STM32 communicating with LCD module HY28B

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

Jude
Posts: 2
Joined: Fri May 12, 2017 7:19 am

STM32 communicating with LCD module HY28B

Postby Jude » Fri May 12, 2017 11:02 am

Hello,
The thread seems a little mussy so if you can read my code with patience I would be much grateful!

I’m currently in trouble with displaying something on the HY28B LCD module . I configured my LCD module in 16bits mode by soldering the right short at the right place and I’m using a STM32 discovery board(http://www.kynix.com/uploadfiles/pdf65976/STM32F100RBT6B.pdf) to drive the LCD module. I ported the source code given by the seller and tried many init sequences found on the internet. I currrently can read the part number register wich is 9325corresponding to the ILI9235 LCD driver but I can’t go further. Here is my code, my only aim is to fill the display with one color to establish the right way to comminicate with it unfortunatly the display remains white. You will find my pin assignation in the source code except for my reset and backlight pin wich are tied to 3V3.

Code: Select all

#include <stm32f10x.h>

#define MAX_X 320
#define MAX_Y 240

#define Set_Cs GPIOC->ODR |= ( 1<<9 );
#define Clr_Cs GPIOC->ODR &= ~( 1<<9 );

#define Set_Rs GPIOC->ODR |= ( 1<<8 );
#define Clr_Rs GPIOC->ODR &= ~( 1<<8 );

#define Set_nWr GPIOC->ODR |= ( 1<<7 );
#define Clr_nWr GPIOC->ODR &= ~( 1<<7 );

#define Set_nRd GPIOC->ODR |= ( 1<<6 );
#define Clr_nRd GPIOC->ODR &= ~( 1<<6 );

void LCD_Configuration(void)
{

GPIO_InitTypeDef GPIO_InitStructure;

/* Enable GPIOA , GPIOB and GPIOC clocks */

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC , ENABLE);

/*
PA.00(D0) PA.01(D1) PA.02(D2) PA.03(D3) PA.04(D4) PA.05(D5) PA.06(D6) PA.07(D7)
*/

/* setting the IO to output mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/*
PB.08(D10) PB.09(D11) PB.10(D12) PB.11(D13) PB.12(D14) PB.13(D15) PB.14(D16) PB.15(D17)
*/

/* setting the IO to output mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

/* PC.09(CS) PC.08(RS), PC.07(WR), PC.06(RD) */

/* setting the IO to output mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);

}

void LCD_WriteIndex(unsigned short index)
{
Clr_Rs; /* RS low */
Set_nRd; /* RD high */

/* write data */
GPIOA->ODR |= index & 0x00FF; //Set D0 -> D7
GPIOB->ODR |= index & 0xFF00; //Set D10 -> D17

Clr_nWr; /* Wr low */
Set_nWr; /* Wr high */
}

void LCD_WriteData(unsigned short data)
{
Set_Rs; /* RS high */

/* write data */
GPIOA->ODR |= data & 0x00FF; //Set D0 -> D7
GPIOB->ODR |= data & 0xFF00; //Set D10 -> D17

Clr_nWr; /* Wr low */
Set_nWr; /* Wr high */
}

unsigned short LCD_ReadData(void)
{
unsigned short value = 0 ;
GPIO_InitTypeDef GPIO_InitStructure;

Set_Rs; /* RS high */
Set_nWr; /* Wr high */
Clr_nRd; /* Rd low */

/*
PA.00(D0) PA.01(D1) PA.02(D2) PA.03(D3) PA.04(D4) PA.05(D5) PA.06(D6) PA.07(D7)
*/

/*
PB.08(D10) PB.09(D11) PB.10(D12) PB.11(D13) PB.12(D14) PB.13(D15) PB.14(D16) PB.15(D17)
*/

/* setting the IO to input mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);

/* read data */
GPIO_ReadInputData(GPIOA);
GPIO_ReadInputData(GPIOB);

value |= 0x00FF & GPIO_ReadInputData(GPIOA);
value |= 0xFF00 & GPIO_ReadInputData(GPIOB);

/* Read twice to ensure correct data */

/* read data OK */

/*
PA.00(D0) PA.01(D1) PA.02(D2) PA.03(D3) PA.04(D4) PA.05(D5) PA.06(D6) PA.07(D7)
*/

/*
PB.08(D10) PB.09(D11) PB.10(D12) PB.11(D13) PB.12(D14) PB.13(D15) PB.14(D16) PB.15(D17)
*/

/* setting the IO to output mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

Set_nRd; /* Rd high */

return value; /* return data */
}

void LCD_WriteReg( unsigned short LCD_Reg, unsigned short LCD_RegValue )
{
/* Write 16-bit Index, then Write Reg */

Clr_Cs; /* Cs low */

/* selected LCD register */
LCD_WriteIndex(LCD_Reg);

/* Write register data */
LCD_WriteData(LCD_RegValue);

Set_Cs; /* Cs high */
}

unsigned short LCD_ReadReg(unsigned short LCD_Reg)
{
unsigned short LCD_RAM;

Clr_Cs; /* Cs low */

/* selected LCD register */
LCD_WriteIndex(LCD_Reg);

/* Write register data */
LCD_RAM = LCD_ReadData();

Set_Cs; /* Cs high */

/* return read data */
return LCD_RAM;
}

void LCD_SetCursor( unsigned short Xpos, unsigned short Ypos )
{
LCD_WriteReg(0x0020, Xpos );
LCD_WriteReg(0x0021, Ypos );
}

static void delay_ms( unsigned short ms )
{
unsigned short i, j;

for( i = 0; i < ms; i++ )
{
for( j = 0; j < 1500; j++ );
}
}

void LCD_Init(void)
{
unsigned short LCD_ID;

LCD_Configuration();

LCD_ID = LCD_ReadReg(0x0000);

if( LCD_ID == 0x9325 )
{
//reading OK

LCD_WriteReg(0x0001,0x0100);
LCD_WriteReg(0x0002,0x0700);
LCD_WriteReg(0x0003,0x1030);
LCD_WriteReg(0x0004,0x0000);
LCD_WriteReg(0x0008,0x0207);
LCD_WriteReg(0x0009,0x0000);
LCD_WriteReg(0x000A,0x0000);
LCD_WriteReg(0x000C,0x0000);
LCD_WriteReg(0x000D,0x0000);
LCD_WriteReg(0x000F,0x0000);
//power on sequence VGHVGL
LCD_WriteReg(0x0010,0x0000);
LCD_WriteReg(0x0011,0x0007);
LCD_WriteReg(0x0012,0x0000);
LCD_WriteReg(0x0013,0x0000);
//vgh
LCD_WriteReg(0x0010,0x1290);
LCD_WriteReg(0x0011,0x0227);
delay_ms(50);
//vregiout
LCD_WriteReg(0x0012,0x001d); //0x001b
delay_ms(50);
//vom amplitude
LCD_WriteReg(0x0013,0x1500);
delay_ms(50);
//vom H
LCD_WriteReg(0x0029,0x0018);
LCD_WriteReg(0x002B,0x000D);
//gamma
LCD_WriteReg(0x0030,0x0004);
LCD_WriteReg(0x0031,0x0307);
LCD_WriteReg(0x0032,0x0002);// 0006
LCD_WriteReg(0x0035,0x0206);
LCD_WriteReg(0x0036,0x0408);
LCD_WriteReg(0x0037,0x0507);
LCD_WriteReg(0x0038,0x0204);//0200
LCD_WriteReg(0x0039,0x0707);
LCD_WriteReg(0x003C,0x0405);// 0504
LCD_WriteReg(0x003D,0x0F02);
//ram
LCD_WriteReg(0x0050,0x0000);
LCD_WriteReg(0x0051,0x00EF);
LCD_WriteReg(0x0052,0x0000);
LCD_WriteReg(0x0053,0x013F);
LCD_WriteReg(0x0060,0xA700);
LCD_WriteReg(0x0061,0x0001);
LCD_WriteReg(0x006A,0x0000);
//
LCD_WriteReg(0x0080,0x0000);
LCD_WriteReg(0x0081,0x0000);
LCD_WriteReg(0x0082,0x0000);
LCD_WriteReg(0x0083,0x0000);
LCD_WriteReg(0x0084,0x0000);
LCD_WriteReg(0x0085,0x0000);
//
LCD_WriteReg(0x0090,0x0010);
LCD_WriteReg(0x0092,0x0600);
LCD_WriteReg(0x0093,0x0003);
LCD_WriteReg(0x0095,0x0110);
LCD_WriteReg(0x0097,0x0000);
LCD_WriteReg(0x0098,0x0000);
LCD_WriteReg(0x0007,0x0133);

}
else
{
/* read LCD ID fail, testing terminated */
/* fatal error */
while(1);
}
delay_ms(50); /* delay 50 ms */
}

void LCD_Clear( unsigned short color )
{
unsigned int index=0;

LCD_SetCursor(0,0);

Clr_Cs; /* Cs low */

/* selected LCD register */
LCD_WriteIndex(0x0022);

for( index = 0; index < MAX_X * MAX_Y; index++ )
{
/* Write data */
LCD_WriteData( color );
}

Set_Cs; /* Cs high */
}

int main (void){

LCD_Init();
LCD_Clear(0x5555);

while(1);

}

void SystemInit (void){}

Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 19 guests