0
\$\begingroup\$

Connecting STM32F407VGT6 to ILI9341 display.

I need to perform a simple task: fill the display with some color.

Current display status: The display backlight lights up. The display is not filled with the color. In the code I wrote the color that should be filled in the TFT display. TFT_SendData(0xbb); 2 times is 0хbbbb color Purple enter image description here

I have written the code and connection below in the text. Maybe I have an error somewhere in the initialization of TFT_Init()?

SPI1 settings from CubeMX.

enter image description here

Connection diagram for ILI9341 to STM32F407VGT6.

enter image description here

(STM32)PA3 -------- (ILI9341)DC, Data / Command 
(STM32)PA4 --------  (ILI9341)CS, Chip Select 
(STM32)PA5 -------- (ILI9341)SCK, serial clock (SP1) 
(STM32)PA6 -------- (ILI9341)SDO, MISO (SP1) 
(STM32)PA7 -------- (ILI9341)SDI, MOSI (SP1)

(STM32)3 Volt -------- (ILI9341)LED
(STM32)5 Volt -------- (ILI9341)VCC
(STM32)GND   -------- (ILI9341)GND

I am using the driver with standard settings for ILI9341.

#define Software_Reset 0x01
#define Power_Control_A 0xCB
#define Power_Control_B 0xCF
#define Driver_Timing_Control_A 0xE8
#define Driver_Timing_Control_B 0xEA
#define Power_On_Sequence_Control 0xED
#define Pump_Ratio_Control 0xF7
#define Power_Control_1 0xC0
#define Power_Control_2 0xC1
#define VCOM_Control_1 0xC5
#define VCOM_Control_2 0xC7
#define Memory_Access_Control 0x36
#define Pixel_Format_Set 0x3A
#define Frame_Rate_Control 0xB1
#define Display_Function_Control 0xB6
#define Enable_3G 0xF2
#define Column_Address_Set 0x2A
#define Page_Address_Set 0x2B
#define Gamma_Set 0x26
#define Positive_Gamma_Correction 0xE0
#define Negative_Gamma_Correction 0xE1
#define Sleep_Out 0x11
#define Display_ON 0x29
#define Memory_Write 0x2C


#define TFT_DC_SET()        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);
#define TFT_DC_RESET()    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
#define TFT_RST_SET()      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET);
#define TFT_RST_RESET()  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_RESET);
#define TFT_CS_SET()        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
#define TFT_CS_RESET()    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);



void TFT_SendCommand(uint8_t command) 
{
  TFT_DC_RESET();
  TFT_CS_RESET();
  HAL_SPI_Transmit(&hspi1, &command,1,1000);
  TFT_CS_SET();
}

void TFT_SendData(uint8_t data) 
{
  TFT_DC_SET();
  TFT_CS_RESET();
  HAL_SPI_Transmit(&hspi1, &data,1,1000);
  TFT_CS_SET();
}


void TFT_SetCursorPosition(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) 
    {
        TFT_SendCommand(Column_Address_Set);
        TFT_SendData(x1 >> 8);
        TFT_SendData(x1 & 0xFF);
        TFT_SendData(x2 >> 8);
        TFT_SendData(x2 & 0xFF);

        TFT_SendCommand(Page_Address_Set);
        TFT_SendData(y1 >> 8);
        TFT_SendData(y1 & 0xFF);
        TFT_SendData(y2 >> 8);
        TFT_SendData(y2 & 0xFF);
}


void TFT_Init()
{
  TFT_CS_SET();
  TFT_RST_SET();
  TFT_SendCommand(Software_Reset);
  HAL_Delay(100);
  
  TFT_SendCommand(Power_Control_A);
  TFT_SendData(0x39);
  TFT_SendData(0x2C);
  TFT_SendData(0x00);
  TFT_SendData(0x34);
  TFT_SendData(0x02);
  TFT_SendCommand(Power_Control_B);
  TFT_SendData(0x00);
  TFT_SendData(0xC1);
  TFT_SendData(0x30);
  TFT_SendCommand(Driver_Timing_Control_A);
  TFT_SendData(0x85);
  TFT_SendData(0x00);
  TFT_SendData(0x78);
  TFT_SendCommand(Driver_Timing_Control_B);
  TFT_SendData(0x00);
  TFT_SendData(0x00);
  TFT_SendCommand(Power_On_Sequence_Control);
  TFT_SendData(0x64);
  TFT_SendData(0x03);
  TFT_SendData(0x12);
  TFT_SendData(0x81);
  TFT_SendCommand(Pump_Ratio_Control);
  TFT_SendData(0x20);
  TFT_SendCommand(Power_Control_1);
  TFT_SendData(0x23);
  TFT_SendCommand(Power_Control_2);
  TFT_SendData(0x10);
  TFT_SendCommand(VCOM_Control_1);
  TFT_SendData(0x3E);
  TFT_SendData(0x28);
  TFT_SendCommand(VCOM_Control_2);
  TFT_SendData(0x86);
  TFT_SendCommand(Memory_Access_Control);
  TFT_SendData(0x48);
  TFT_SendCommand(Pixel_Format_Set);
  TFT_SendData(0x55);
  TFT_SendCommand(Frame_Rate_Control);
  TFT_SendData(0x00);
  TFT_SendData(0x18);
  TFT_SendCommand(Display_Function_Control);
  TFT_SendData(0x08);
  TFT_SendData(0x82);
  TFT_SendData(0x27);
  TFT_SendCommand(Enable_3G);
  TFT_SendData(0x00);
  TFT_SendCommand(Gamma_Set);
  TFT_SendData(0x01);
  TFT_SendCommand(Positive_Gamma_Correction);
  TFT_SendData(0x0F);
  TFT_SendData(0x31);
  TFT_SendData(0x2B);
  TFT_SendData(0x0C);
  TFT_SendData(0x0E);
  TFT_SendData(0x08);
  TFT_SendData(0x4E);
  TFT_SendData(0xF1);
  TFT_SendData(0x37);
  TFT_SendData(0x07);
  TFT_SendData(0x10);
  TFT_SendData(0x03);
  TFT_SendData(0x0E);
  TFT_SendData(0x09);
  TFT_SendData(0x00);
  TFT_SendCommand(Negative_Gamma_Correction);
  TFT_SendData(0x00);
  TFT_SendData(0x0E);
  TFT_SendData(0x14);
  TFT_SendData(0x03);
  TFT_SendData(0x11);
  TFT_SendData(0x07);
  TFT_SendData(0x31);
  TFT_SendData(0xC1);
  TFT_SendData(0x48);
  TFT_SendData(0x08);
  TFT_SendData(0x0F);
  TFT_SendData(0x0C);
  TFT_SendData(0x31);
  TFT_SendData(0x36);
  TFT_SendData(0x0F);
  TFT_SendCommand(Sleep_Out);
  HAL_Delay(100);
  TFT_SendCommand(Display_ON);
}

int main(void)
{
  TFT_Init();
  TFT_SetCursorPosition(0,0,239,319);

  TFT_SendData(0xbb);
  TFT_SendData(0xbb);
  TFT_SendData(0xbb);
  //...
  //...
  //...
  //Here I write 200 times TFT_SendData(0xbb); to make the code easier to understand.
  TFT_SendData(0xbb);
}

Repeating function TFT_SendData(0xbb); can be replaced with this code:

  for(int i=0; i<239*319; i++)
    {
    TFT_SendData(0xbb);
    }

But the result will not change.

Of course, the code contains initialization of GPIO, SPI and everything else that is needed. This is not in the code to shorten the code and have a better understanding of the code.

\$\endgroup\$
9
  • \$\begingroup\$ the title of your post does not match the posted problem ... one says can't display color the other says display does not respond ... please edit the title to match \$\endgroup\$
    – jsotola
    Commented Oct 11, 2023 at 15:51
  • \$\begingroup\$ I have removed this sentence from the text. I don't know for sure if my code is correct. It may contain an error. So my code doesn't work for the display. I meant it. The subject of the message is correct. \$\endgroup\$
    – stm
    Commented Oct 11, 2023 at 16:12
  • \$\begingroup\$ what is the actual problem that you see? ... what is shown on the display? ... But the result will not change. is meaningless if you do not say what the result actually is \$\endgroup\$
    – jsotola
    Commented Oct 11, 2023 at 16:32
  • \$\begingroup\$ I have changed the text in the message. I think there is something wrong with the TFT_Init function for initializing the display. \$\endgroup\$
    – stm
    Commented Oct 11, 2023 at 17:10
  • \$\begingroup\$ display not filled with color is very vague ... it's like going to a doctor with a sore arm and saying I don't have a broken leg ... what is actually displayed? \$\endgroup\$
    – jsotola
    Commented Oct 11, 2023 at 18:32

1 Answer 1

1
\$\begingroup\$

I found a bug. The error is only in the main function. I forgot to send the Memory_Write command before sending the data to the display.

int main()
{
    TFT_Init();
    TFT_SetCursorPosition(0,0,239,319);

    TFT_SendCommand(Memory_Write); //Memory_Write

  for(int i=0; i<(239*319); i++)
    {
    TFT_SendData(0xbb);
    TFT_SendData(0xbb);
    }
}

enter image description here

Thanks, problem solved.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.