2024-05-05 08:47 AM
I'm trying to initialize an LCD module (ST7796U controller) on a STM32F103VET6 development board using SPI1, yet the souce code I got from the seller is using software-simulated SPI instead of hardware SPI (with SPI1_NSS enabled as output):
#define LCD_SCLK_Clr() HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET)
#define LCD_SCLK_Set() HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET)
#define LCD_MOSI_Clr() HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET)
#define LCD_MOSI_Set() HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET)
//the above are located in lcd_init.h, which I cannot attach due to the attachments number limit
void LCD_Write_Bus(uint8_t dat){
uint8_t i;
for(i=0;i<8;i++) {
LCD_SCLK_Clr();
if(dat&0x80) { LCD_MOSI_Set();
}
else { LCD_MOSI_Clr();
}
LCD_SCLK_Set();
dat<<=1; }
}
and the following is my work:
void LCD_Write_Bus(uint8_t dat){
HAL_SPI_Transmit_DMA(&hspi1, &dat, 1);
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY){
__NOP;
}
}
but the LCD module does not show up anything after i initialize the LCD and call the FillColor function in main.c, only the backlight is enabled.
is there any problem with my code?
the edited lcd.c and lcd_init.c is attached, if there is any strange chinese characters, don't worry, they are comments, just ignored them.
thanks!
2024-05-05 09:19 AM - edited 2024-05-05 09:26 AM
>LCD module does not show up anything after i initialize the LCD
So : no working init.
>is there any problem with my code?
A: LCD wrong connected
B: spi timing/signals wrong
C: LCD init sequence wrong (one wrong byte is enough ! )
D : your program .... (with DMA i had not much luck on my TFTs , cpu/dma to fast for the TFT chip.)
You can choose now .... :)
Or begin with A , check it 100% ; then B... (need ds of display, to check timing in specs ); then...
2024-05-10 06:07 AM