Wednesday 17 May 2017

ILI9341 initialization code for 16-bit interface

ILI9341 is a common LCD driver for 320x240 LCD displays. The graphic controller is pretty flexible, it can have serial or parallel interface, and the parallel interface can be 8, 9, or 16 bits wide. You can find handful of initialization codes for ILI9341 on the internet, some of them can be long and complicated. Here I provide a very simple one, it's for the 16-bit interface, and only has less than 10 lines of code.
It was tested on STM32F103 with external bus (SFMC)

#define LCD_ILI9341_CMD(index)       ((*(volatile u16 *) ((u32)0x6C000000)) = ((u16)index))
#define LCD_ILI9341_Parameter(val)   ((*(volatile u16 *) ((u32)0x6D000000)) = ((u16)(val)))


volatile u32 i;

GPIOG->BRR = LCD_RESET;          //reset lcd
for (i=0; i< (0xAFFf<<2); i++);  // delay
GPIOG->BSRR = LCD_RESET;
for (i=0; i< (0xAFFf<<2); i++); 
        
/*  Pixel Format Set (3Ah)  */
LCD_ILI9341_CMD(0x3a); 
LCD_ILI9341_Parameter(0x55);    // set to 16bit per pixel
        
/* Sleep Out (11h)  */
LCD_ILI9341_CMD(0x11);
for (i=0; i< (0xAFFf<<2); i++);

/* Display ON (29h) */
LCD_ILI9341_CMD(0x29);

No comments:

Post a Comment