cancel
Showing results for 
Search instead for 
Did you mean: 

ILI9488 -TFT (without touch) not working on STM32H563ZIT6

Berlin-raj123
Associate III

Hi, I am trying to interface with a 3.5-inch ILI9488 TFT display (without touch) on an STM32H563ZIT6 microcontroller. I'm attempting to write a test function to fill the entire screen with a solid red color, but it's not working. Could anyone please help me? I will attach my code. How can I verify that SPI is properly working with the TFT?

#include "main.h"

SPI_HandleTypeDef hspi2;

UART_HandleTypeDef huart7;

#define ILI9488_CMD_MEMORY_WRITE        0x2C
#define ILI9488_CMD_MEMORY_ACCESS_CTRL  0x36

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ICACHE_Init(void);
static void MX_SPI2_Init(void);
static void MX_UART7_Init(void);
void ILI9488_FillScreen(uint16_t color);
void ILI9488_SendData(uint8_t data);
void ILI9488_SendCommand(uint8_t cmd);
void ILI9488_Init(void);
void testFillScreen(uint16_t color);

#define WIDTH  320
#define HEIGHT 480
#define CS_PORT GPIOB
#define CS_PIN    GPIO_PIN_12

#define DC_PORT GPIOE
#define DC_PIN    GPIO_PIN_4

#define RESET_PORT GPIOE
#define RESET_PIN GPIO_PIN_2
uint8_t tx_buffer[50];
int uart_buffer_len;
char spi_buffer[20];
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
/* Configure the system clock */
  SystemClock_Config();
/* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ICACHE_Init();
  MX_SPI2_Init();
  MX_UART7_Init();
  ILI9488_Init();
  // Test filling screen with red color
  ILI9488_FillScreen(0xF800); // Red color in 16-bit RGB
  while (1)
  {

  }
}
void ILI9488_Init(void)
{
	 // Reset display
    ILI9488_SendCommand(0x01); // Software Reset
    HAL_Delay(150);
    ILI9488_SendCommand(0x11); // Sleep Out
    HAL_Delay(150);
    ILI9488_SendCommand(0x29); // Display On
}
void ILI9488_SendCommand(uint8_t cmd)
{
    HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET); // DC low for command
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); // CS low
    HAL_SPI_Transmit(&hspi2, &cmd, 1, HAL_MAX_DELAY);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);   // CS high
}
void ILI9488_FillScreen(uint16_t color)
{
    uint8_t highByte = color >> 8;
    uint8_t lowByte = color & 0xFF;

    ILI9488_SendCommand(0x2C); // Memory Write

    for (int i = 0; i < WIDTH * HEIGHT; i++)
    {
        ILI9488_SendData(highByte);
        ILI9488_SendData(lowByte);
    }
}
void ILI9488_SendData(uint8_t data)
{
    HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET);   // DC high for data
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); // CS low
    HAL_SPI_Transmit(&hspi2, &data, 1, HAL_MAX_DELAY);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);   // CS high
}
22 REPLIES 22

Hi, @AScha.3. Actually, I want 65K colors (16-bit data, R: 5-bit, G: 6-bit, B: 5-bit), so I set the value of EPF [1:0] to 00. Is this the correct value for 16-bit color? i am little stuck..Screenshot 2024-07-29 144437.pngScreenshot 2024-07-29 144159.png

Hi,

you should not "play around" with settings - until you have it working, just using one of the libs (i showed you..).

+

565 is the "usual" format (on all libs, i have seen). -> 65K colors

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

OK...