Library 08- ILI9341 LCD for STM32F4
On STM32F429 Discovery board there is LCD with ILI9341 controller. It has 240 x 320 pixels resolution and 16bit or 18bit color depth, what gives you 65536 or 262144 different colors.
It has also a possibility of different way of connection, like serial, parallel, with VSYNC and HYSNC.
STM32F429 has also LTDC driver for LCD like that, but this driver we will use later. For now we will use SPI for driving in serial mode and some other pins for controlling.
I choose this way because on ebay there is a lot of this displays configuring for SPI driving.
If you want to use ILI9341 with LTDC on STM32F429-Discovery board, then check this library.
June 06, 2015
After some optimization videos from Jean-François Garcia and electrodacus I thought that adding that optimizations to my library is not bad idea.
So now, DMA is used for SPI and window/page settings is used before sending data to LCD for reducing time for LCD.
Currently, I’ve set these options:
- SPI is changed from 8-bits to 16-bits before sending starts via DMA for correct colors,
- page/window is supported for filling entire LCD, filling rectangle at desired position, drawing vertical or horizontal line
- Adding this feature also to fonts which first draws rectangle is not supported yet
So, for maximal support for this LCD, redownload all libraries because I’ve done some changes in TM SPI, TM DMA, TM SPI DMA and TM ILI9341 libraries.
Library
Features
- Support for 7 x 10 and 11 x 18 pixel font sizes
- Display string
- Draw rectangles, circles, lines
- LCD rotation in all 4 orientations
- Support for \n and \n\r
- \n put string into new line with x coordinate same as start x coordinate
- \n\r put string into new line with x = 0 coordinate
- Support for LCD display ON/OFF
Dependencies
- CMSIS
- STM32F4xx
- STM32F4xx RCC
- STM32F4xx GPIO
- STM32F4xx SPI
- STM32F4xx DMA
- TM
- TM SPI
- TM DMA
- TM SPI DMA
- TM Fonts
- TM GPIO
- defines.h
- TM SPI
On board, LCD is connected to:
LCD BOARD | DISCOVERY BOARD | DESCRIPTION | NOTES |
---|---|---|---|
SDO (MISO) | PF8 | Output from LCD for SPI | Not used, can be left |
LED | 3.3V | Backlight | |
SCK | PF7 | SPI clock | |
SDI (MOSI) | PF9 | SPI master output | |
D/C | PD13 | Data/Command register | |
RESET | PD12 | Reset LCD | Not used on discovery board |
CS | PC2 | Chip select for SPI | |
GND | GND | Ground | |
VCC | 3.3V | Positive power supply |
Remember: This library can also be used, if you are not using STM32F429 Discovery. It can be used in previous STM32F4 Discovery board. All pins can be changed in defines.h file which is included in project.
By default, SPI5 is used, but you can change that also in defines.h file with
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* Change custom SPI for LCD */ #define ILI9341_SPI SPI3 //OR something similar #define ILI9341_SPI_PINS TM_SPI_PinsPack_1 /* Change custom CS, DC and RESET pins */ /* CS pin */ #define ILI9341_CS_PORT GPIOC #define ILI9341_CS_PIN GPIO_PIN_2 /* WRX or DC pin */ #define ILI9341_WRX_PORT GPIOD #define ILI9341_WRX_PIN GPIO_PIN_13 /* RST pin */ #define ILI9341_RST_PORT GPIOD #define ILI9341_RST_PIN GPIO_PIN_12 |
About library
When you included all files to you project, you have to initialize LCD first. Then you are able to work with.
Example describe everything what you need to start with,
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/** * Keil project for ILI9341 LCD example * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 */ #include "stm32f4xx.h" #include "stm32f4xx_spi.h" #include "defines.h" #include "tm_stm32f4_ili9341.h" #include "tm_stm32f4_fonts.h" #include <stdio.h> int main(void) { //Initialize system SystemInit(); //Initialize ILI9341 TM_ILI9341_Init(); //Rotate LCD for 90 degrees TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_2); //FIll lcd with color TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA); //Draw white circle TM_ILI9341_DrawCircle(60, 60, 40, ILI9341_COLOR_GREEN); //Draw red filled circle TM_ILI9341_DrawFilledCircle(60, 60, 35, ILI9341_COLOR_RED); //Draw blue rectangle TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE); //Draw black filled rectangle TM_ILI9341_DrawFilledRectangle(130, 30, 210, 90, ILI9341_COLOR_BLACK); //Draw line with custom color 0x0005 TM_ILI9341_DrawLine(10, 120, 310, 120, 0x0005); //Put string with black foreground color and blue background with 11x18px font TM_ILI9341_Puts(65, 130, "STM32F4 Discovery", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); //Put string with black foreground color and blue background with 11x18px font TM_ILI9341_Puts(60, 150, "ILI9341 LCD Module", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); //Put string with black foreground color and red background with 11x18px font TM_ILI9341_Puts(245, 225, "majerle.eu", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); while (1) { } } |
Project is available on Github, download library below.
ILI9341 LCD controller driver without LTDC support
Recent comments