cancel
Showing results for 
Search instead for 
Did you mean: 

SPI for LCD failed to transmit data on STM32F103VET6

OW1TY2
Associate II

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!

2 REPLIES 2
AScha.3
Chief II

>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...

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Evangelist III

@OW1TY2 wrote:

SPI for LCD failed to transmit data on STM32F103VET6


How do you know that it's failed to transmit?

As @AScha.3 said, use an oscilloscope to verify that the SPI lines are actually behaving as required...