STemWin with ILI9488 LCD-Controller on a STM32F103 Microcontroller

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • STemWin with ILI9488 LCD-Controller on a STM32F103 Microcontroller

    I need help to integrate a ILI9488 LCD-Controller on the FSMC-BUS with STemWin Library.

    The display works but only without STemWin Library ("#define ILI9488DEBUG" in the attached main.c).
    When I want use the STemWin Library (Comment "#define ILI9488DEBUG" in the attached main.c) the display doesn't work.

    I think I have some misstake in the attached LCDConf.c. Can you help me where?
    I read the ILI9488 Controller is supported by the library but what's wrong?

    LCDConf.c

    C Source Code

    1. #include "GUI.h"
    2. #include "GUIDRV_FlexColor.h"
    3. #include "stm32f1xx_hal.h"
    4. #include "ILI9488.h"
    5. #define XSIZE_PHYS 320 // To be adapted to x-screen size
    6. #define YSIZE_PHYS 480 // To be adapted to y-screen size
    7. #ifndef VXSIZE_PHYS
    8. #define VXSIZE_PHYS XSIZE_PHYS
    9. #endif
    10. #ifndef VYSIZE_PHYS
    11. #define VYSIZE_PHYS YSIZE_PHYS
    12. #endif
    13. #ifndef XSIZE_PHYS
    14. #error Physical X size of display is not defined!
    15. #endif
    16. #ifndef YSIZE_PHYS
    17. #error Physical Y size of display is not defined!
    18. #endif
    19. #ifndef GUICC_565
    20. #error Color conversion not defined!
    21. #endif
    22. #ifndef GUIDRV_FLEXCOLOR
    23. #error No display driver defined!
    24. #endif
    25. static void LcdWriteReg(U16 Data) {
    26. // ... TBD by user
    27. ILI9488WriteReg(Data);
    28. }
    29. static void LcdWriteData(U16 Data) {
    30. // ... TBD by user
    31. ILI9488WriteData(Data);
    32. }
    33. static void LcdWriteDataMultiple(U16 * pData, int NumItems) {
    34. while (NumItems--) {
    35. // ... TBD by user
    36. ILI9488WriteData(pData++);
    37. }
    38. }
    39. static void LcdReadDataMultiple(U16 * pData, int NumItems) {
    40. while (NumItems--) {
    41. // ... TBD by user
    42. *pData++=LCD_DATA_ADDRESS;
    43. }
    44. }
    45. void LCD_X_Config(void) {
    46. GUI_DEVICE * pDevice;
    47. CONFIG_FLEXCOLOR Config = {0};
    48. GUI_PORT_API PortAPI = {0};
    49. //
    50. // Set display driver and color conversion
    51. //
    52. pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_565, 0, 0);
    53. //
    54. // Display driver configuration, required for Lin-driver
    55. //
    56. LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
    57. LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
    58. //
    59. // Orientation
    60. //
    61. Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
    62. GUIDRV_FlexColor_Config(pDevice, &Config);
    63. //
    64. // Set controller and operation mode
    65. //
    66. PortAPI.pfWrite16_A0 = LcdWriteReg;
    67. PortAPI.pfWrite16_A1 = LcdWriteData;
    68. PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
    69. PortAPI.pfReadM16_A1 = LcdReadDataMultiple;
    70. GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B16);
    71. }
    72. int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
    73. int r;
    74. (void) LayerIndex;
    75. (void) pData;
    76. switch (Cmd) {
    77. case LCD_X_INITCONTROLLER: {
    78. //ILI9488_35_Initial_Code();
    79. return 0;
    80. }
    81. default:
    82. r = -1;
    83. }
    84. return r;
    85. }
    Display All


    ILI9488.c

    C Source Code

    1. #include "ILI9488.h"
    2. #include "stm32f1xx_hal.h" /* include for HAL_Delay */
    3. void ILI9488_35_Initial_Code(void)
    4. {
    5. /* PGAMCTRL (Positive Gamma Control) (E0h) */
    6. ILI9488WriteReg(0xE0);
    7. ILI9488WriteData(0x00);
    8. ILI9488WriteData(0x07);
    9. ILI9488WriteData(0x0f);
    10. ILI9488WriteData(0x0D);
    11. ILI9488WriteData(0x1B);
    12. ILI9488WriteData(0x0A);
    13. ILI9488WriteData(0x3c);
    14. ILI9488WriteData(0x78);
    15. ILI9488WriteData(0x4A);
    16. ILI9488WriteData(0x07);
    17. ILI9488WriteData(0x0E);
    18. ILI9488WriteData(0x09);
    19. ILI9488WriteData(0x1B);
    20. ILI9488WriteData(0x1e);
    21. ILI9488WriteData(0x0f);
    22. /* NGAMCTRL (Negative Gamma Control) (E1h) */
    23. ILI9488WriteReg(0xE1);
    24. ILI9488WriteData(0x00);
    25. ILI9488WriteData(0x22);
    26. ILI9488WriteData(0x24);
    27. ILI9488WriteData(0x06);
    28. ILI9488WriteData(0x12);
    29. ILI9488WriteData(0x07);
    30. ILI9488WriteData(0x36);
    31. ILI9488WriteData(0x47);
    32. ILI9488WriteData(0x47);
    33. ILI9488WriteData(0x06);
    34. ILI9488WriteData(0x0a);
    35. ILI9488WriteData(0x07);
    36. ILI9488WriteData(0x30);
    37. ILI9488WriteData(0x37);
    38. ILI9488WriteData(0x0f);
    39. /* Power Control 1 (C0h) */
    40. ILI9488WriteReg(0xC0);
    41. ILI9488WriteData(0x10);
    42. ILI9488WriteData(0x10);
    43. /* Power Control 2 (C1h) */
    44. ILI9488WriteReg(0xC1);
    45. ILI9488WriteData(0x41);
    46. /* VCOM Control (C5h) */
    47. ILI9488WriteReg(0xC5);
    48. ILI9488WriteData(0x00);
    49. ILI9488WriteData(0x2c); // VCOM
    50. ILI9488WriteData(0x80);
    51. /* Memory Access Control (36h) */
    52. ILI9488WriteReg(0x36);
    53. ILI9488WriteData(0x08);
    54. /* Interface Pixel Format (3Ah) */
    55. ILI9488WriteReg(0x3A); //Interface Mode Control
    56. ILI9488WriteData(0x55);
    57. ILI9488WriteReg(0xB0); //Interface Mode Control
    58. ILI9488WriteData(0x00);
    59. ILI9488WriteReg(0xB1); //Frame rate 70HZ
    60. ILI9488WriteData(0xB0);
    61. /* Display Inversion Control (B4h) */
    62. ILI9488WriteReg(0xB4);
    63. ILI9488WriteData(0x02);
    64. /* Display Function Control (B6h) */
    65. ILI9488WriteReg(0xB6); //RGB/MCU Interface Control
    66. ILI9488WriteData(0x02);
    67. ILI9488WriteData(0x22);
    68. /* Set Image Function (E9h) */
    69. ILI9488WriteReg(0xE9);
    70. ILI9488WriteData(0x00);
    71. /* Adjust Control 3 (F7h) */
    72. ILI9488WriteReg(0XF7);
    73. ILI9488WriteData(0xA9);
    74. ILI9488WriteData(0x51);
    75. ILI9488WriteData(0x2C);
    76. ILI9488WriteData(0x82);
    77. /* Sleep Out (11h) */
    78. ILI9488WriteReg(0x11);
    79. HAL_Delay(150);
    80. /* Display ON (29h) */
    81. ILI9488WriteReg(0x29);
    82. }
    83. unsigned long ILI9488_ReadID(void) {
    84. unsigned char buf[4];
    85. ILI9488WriteReg(0x04);
    86. buf[0] = LCD_REG_ADDRESS;
    87. buf[1] = LCD_REG_ADDRESS;
    88. buf[2] = LCD_REG_ADDRESS;
    89. buf[3] = LCD_REG_ADDRESS;
    90. return (buf[1]<<16)+(buf[2]<<8)+(buf[3]);
    91. }
    92. void ILI9488DisplayOn()
    93. {
    94. ILI9488WriteReg(0x29);
    95. }
    96. void ILI9488DisplayOff()
    97. {
    98. ILI9488WriteReg(0x28);
    99. }
    100. void ILI9488MemoryWrite(unsigned short * pData, unsigned long size)
    101. {
    102. unsigned long i;
    103. ILI9488WriteReg(0x2C);
    104. for(i=0;i<size;i++)
    105. {
    106. ILI9488WriteData(*pData++);
    107. }
    108. }
    109. void ILI9488MemoryRead(unsigned short * pData, unsigned short size)
    110. {
    111. unsigned short i;
    112. ILI9488WriteReg(0x2E);
    113. for(i=0;i<size;i++)
    114. {
    115. *pData++ = LCD_REG_ADDRESS;
    116. }
    117. }
    118. unsigned long ILI9488ReadDisplayStatus()
    119. {
    120. volatile unsigned long tmp;
    121. ILI9488WriteReg(0x09);
    122. tmp = LCD_REG_ADDRESS;
    123. tmp = (LCD_REG_ADDRESS & 0x00FF) << 24;
    124. tmp |= (LCD_REG_ADDRESS & 0x00FF) << 16;
    125. tmp |= (LCD_REG_ADDRESS & 0x00FF) << 8;
    126. tmp |= (LCD_REG_ADDRESS & 0x00FF);
    127. return tmp;
    128. }
    129. void ILI9488RamAddress(void)
    130. {
    131. // set column address
    132. ILI9488WriteReg(0x2a);
    133. ILI9488WriteData(0x00);
    134. ILI9488WriteData(0x00);
    135. ILI9488WriteData(0x01);
    136. ILI9488WriteData(0x3f);
    137. // set page address
    138. ILI9488WriteReg(0x2b);
    139. ILI9488WriteData(0x00);
    140. ILI9488WriteData(0x00);
    141. ILI9488WriteData(0x01);
    142. ILI9488WriteData(0xdf);
    143. // send command memory write
    144. ILI9488WriteReg(0x2c);
    145. }
    146. void ILI9844NormalDisplayModeOn()
    147. {
    148. ILI9488WriteReg(0x13);
    149. }
    150. void ILI9844AllPixelOn()
    151. {
    152. ILI9488WriteReg(0x23);
    153. }
    154. void ILI9844AllPixelOff()
    155. {
    156. ILI9488WriteReg(0x22);
    157. }
    158. void ILI9844ColumnAddressSet(unsigned short SC, unsigned short EC)
    159. {
    160. ILI9488WriteReg(0x2A);
    161. ILI9488WriteData( (SC & 0xFF00) >> 8);
    162. ILI9488WriteData(SC & 0xFF);
    163. ILI9488WriteData( (EC & 0xFF00) >> 8);
    164. ILI9488WriteData(EC & 0xFF);
    165. }
    166. void Ili9844PageAddressSet(unsigned short SP, unsigned short EP)
    167. {
    168. ILI9488WriteReg(0x2B);
    169. ILI9488WriteData( (SP & 0xFF00) >> 8);
    170. ILI9488WriteData(SP & 0xFF);
    171. ILI9488WriteData( (EP & 0xFF00) >> 8);
    172. ILI9488WriteData(EP & 0xFF);
    173. }
    174. unsigned short ILI9844ReadNumberOfTheErrorsOnDsi()
    175. {
    176. volatile unsigned short tmp;
    177. ILI9488WriteReg(0x05);
    178. tmp = LCD_REG_ADDRESS;
    179. tmp = LCD_REG_ADDRESS;
    180. return tmp;
    181. }
    Display All


    main.c

    C Source Code

    1. /* Includes ------------------------------------------------------------------*/
    2. #include "stm32f1xx_hal.h"
    3. /* USER CODE BEGIN Includes */
    4. #include "GUI.h"
    5. #include "ILI9488.h"
    6. #include "LCDConf.h"
    7. #include "testtable.h"
    8. #define ILI9488DEBUG 1
    9. CRC_HandleTypeDef hcrc;
    10. SRAM_HandleTypeDef hsram1;
    11. void SystemClock_Config(void);
    12. static void MX_GPIO_Init(void);
    13. static void MX_CRC_Init(void);
    14. static void MX_FSMC_Init(void);
    15. int main(void)
    16. {
    17. uint32_t LcdStatus=0;
    18. HAL_Init();
    19. SystemClock_Config();
    20. MX_GPIO_Init();
    21. MX_CRC_Init();
    22. MX_FSMC_Init();
    23. // Reset LCD Display
    24. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_RESET);
    25. HAL_Delay(100);
    26. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_SET);
    27. HAL_Delay(10);
    28. // initialize display driver
    29. ILI9488_35_Initial_Code();
    30. LcdStatus = ILI9488ReadDisplayStatus();
    31. #ifndef ILI9488DEBUG
    32. GUI_Init();
    33. LcdStatus = ILI9488ReadDisplayStatus();
    34. #endif
    35. #ifdef ILI9488DEBUG
    36. // Fill Screen with testtable
    37. ILI9488MemoryWrite(testtable, 320*480);
    38. LcdStatus = ILI9488ReadDisplayStatus();
    39. #else
    40. GUI_SetBkColor(GUI_BLACK);
    41. LcdStatus = ILI9488ReadDisplayStatus();
    42. GUI_SetColor(GUI_WHITE);
    43. LcdStatus = ILI9488ReadDisplayStatus();
    44. GUI_DrawRect(10,10,200,200);
    45. LcdStatus = ILI9488ReadDisplayStatus();
    46. #endif
    47. while (1)
    48. {
    49. // Toggle Power LED
    50. HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_9);
    51. HAL_Delay(1000);
    52. }
    53. }
    Display All
  • Hello,

    Please understand that I am not able to help you find the problem. I would suggest you to follow the description of the emWin display driver GUIDRV_FlexColor in the emWin user manual.

    I would also recommend you not to access the display controller directly after GUI_Init() was called. emWin might expect the controller to be in a certain state.

    Best regards,
    Adrian
  • Some strange news:
    When I replace in the main.c the function

    C Source Code

    1. GUI_DrawRect(10,10,200,200);

    with

    C Source Code

    1. GUI_DispStringAt("Hallo world", 160,160);

    then I see "Hello world" on the Display. This works.

    The background color of the display is some kinde of green. But the text color and the text background color is correct.
    The function GUI_DrawLine works also.

    I try also the function GUI_DrawRectFill, this function do something but with wrong colors like the background color.
    I try also the function GUI_BMP_Draw but this doesn't work. This function I think do nothing.

    Do you have any ideas?
  • Hello,

    Please refer to the according function descriptions in the emWin user manual for detailed information on how to use them.

    After GUI_Init() was processed, the screen should be filled with solid black color. If this is not the case, I would recommend you to verify the display initialization sequence and the emWin display configuration (LCDConf.c).

    Best regards,
    Adrian
  • Now It works :)

    The main error was a wrong pointer operation.
    Because this only the functions GUI_DrawLine() and GUI_DispStringAt() works correct.

    LCDConf.c

    C Source Code

    1. static void LcdWriteDataMultiple(U16 * pData, int NumItems) {
    2. while (NumItems--) {
    3. // ... TBD by user
    4. ILI9488WriteData(*pData++); // lack *
    5. }
    6. }


    And in the ILI9488.c was some wrong debug function (Wrong address):
    ILI9488.c

    C Source Code

    1. unsigned long ILI9488_ReadID(void) {
    2. unsigned char buf[4];
    3. ILI9488WriteReg(0x04);
    4. buf[0] = LCD_DATA_ADDRESS; // was wrong address
    5. buf[1] = LCD_DATA_ADDRESS;
    6. buf[2] = LCD_DATA_ADDRESS;
    7. buf[3] = LCD_DATA_ADDRESS;
    8. return (buf[1]<<16)+(buf[2]<<8)+(buf[3]);
    9. }
    10. ...
    11. unsigned long ILI9488ReadDisplayStatus()
    12. {
    13. volatile unsigned long tmp;
    14. ILI9488WriteReg(0x09);
    15. tmp = LCD_DATA_ADDRESS; // was wrong address
    16. tmp = (LCD_DATA_ADDRESS & 0x00FF) << 24;
    17. tmp |= (LCD_DATA_ADDRESS & 0x00FF) << 16;
    18. tmp |= (LCD_DATA_ADDRESS & 0x00FF) << 8;
    19. tmp |= (LCD_DATA_ADDRESS & 0x00FF);
    20. return tmp;
    21. }
    Display All