STM32F0 + ILI9163 LCD!

Well after popular demand (lol two people…)! I’ve revisited some EXTREMELY old code and got it working for my ILI9163 LCD, its not pretty, its code I’ve not used in a LONG time and probably won’t use for a long while more but as far as I know, the driver is pretty sound. Its uncommented and is in pretty poor condition but I’ve not got as much time to invest as I would’ve liked to have had. If I get the chance in the future, I’ll improve on this!

The graphics library used for this example is a little weird as it uses structs to pass to the graphics functions, this makes printing lots of the same thing less typing and easier to change as a whole white other things are a bit less easy to change. Regardless, it was just a test to see how much better a structure based library would be for this kind of application.

The code is on my Github!

A better perspective…

8 thoughts on “STM32F0 + ILI9163 LCD!

  1. Nice , thank you ! though I managed to build my own based on the one you had previously two weeks ago 🙂 I’m more into making some animation , like transitions and so.. also maybe trying to make the font rendering better , simple anti-aliasing, but seems like lots of work.

    1. Nice job man! I’d live to invest more time into my libraries but I’m so strapped, its unreal! I’ve got loads of little code nuggets to integrate into my libraries but getting round to it is always a problem!

  2. Hi man, I’m Jonathan, from Brazil.

    So, I’m trying change your library, adding a DMA controller on SB and SX functions like this:

    void SB(uint8_t Data, uint8_t DR)

    DataSPI = Data; // Buffer set on DMA_Config()

    if (DR == Dat)

    GPIO_SetBits(GPIOB, AOPin);

    GPIO_ResetBits(GPIOB, AOPin);

    //SPI_I2S_SendData(SPI2, DataSPI); >> Only works with this line

    //Enable channels
    DMA_Cmd(DMA1_Channel5, ENABLE);

    //Wait complete
    while ( DMA_GetFlagStatus ( DMA1_FLAG_TC5) == RESET);

    //Disable Channles
    DMA_Cmd(DMA1_Channel5, DISABLE);


    But the communication doesn’t work. Polling or interrupt DMA doesn’t work. The SPI’s DR register doesn’t receive the data. Can you help me, please?

    This is my DMA routine:

    extern uint16_t DataSPI; // Global buffer to SPI
    void DMA_Configuration(void)

    DMA_InitTypeDef DMA_InitStructure;

    DMA_InitStructure . DMA_PeripheralBaseAddr = (uint32_t) & (SPI2 -> DR); // (uint32_t) & (SPI2 -> DR);
    DMA_InitStructure . DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
    DMA_InitStructure . DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
    DMA_InitStructure . DMA_PeripheralInc = DMA_PeripheralInc_Disable ;
    DMA_InitStructure . DMA_BufferSize = 100;
    DMA_InitStructure . DMA_Mode = DMA_Mode_Normal;
    DMA_InitStructure . DMA_Priority = DMA_Priority_VeryHigh ;
    DMA_InitStructure . DMA_M2M = DMA_M2M_Disable ;

    DMA_InitStructure . DMA_MemoryBaseAddr = (uint32_t) &DataSPI; //(uint32_t) &DataSPI;
    DMA_InitStructure . DMA_MemoryInc = DMA_MemoryInc_Disable ;
    DMA_InitStructure . DMA_DIR = DMA_DIR_PeripheralDST ; //Destiny DST or Source SRC
    DMA_Init (DMA1_Channel5 , & DMA_InitStructure);

    // Enable DMA1 transfer complete interrupt
    DMA_ITConfig(DMA1_Channel5, DMA1_IT_TC5 , ENABLE);

    DMA_Cmd(DMA1_Channel5, ENABLE);


    Sorry about my bad English :-/

    1. Hi Jonathan,

      The SB function is required to send a single byte through SPI. In your DMA config, you’ve set the buffer size to 100. For the function SB, its probably best to disable the DMA and blocking send the single byte. This is required for setting up the amount of pixels that you’re going to be sending to the LCD.

      The DMA with the STM32 is a little confusing at times as you generally need to reinitialize it before every transaction. What type of transfer would you like to do? If you have a framebuffer in RAM, you can modify that with the processor then use DMA to stream the data while you’re doing something else with the microcontroller. Otherwise, you need to devise a method for when you want to use DMA, for example you could have small framebuffers for every character and use DMA to stream that. Hopefully that helps a bit!

      1. Hi Harry,
        Thanks for your fast reply.
        So, I just want transfer a bitmap for example, more fast than standard method with CPU. Do you think is better use frame buffer? Like a buffer of pixel until complete a image and tranfer to SPI from DMA? Ah, I’m using STM32F103 and AC6 System Work Bench IDE on Linux.

  3. Transferring a bitmap through DMA is definitely worth doing! I’ve not actually used many of the STM32F1 series so I don’t know if it would be different to the STM32F0 series. If you have enough RAM, using a framebuffer makes it a little easier as you can do all changes to the LCD in RAM then just stream the whole buffer without having to worry about tracking changes etc. Have you looked at the STM32F1 peripheral library examples?

    1. Yes, but I can’t find any example with DMA, SPI TX and interrupt. The ILI 9163 is not much used, the people prefer ILI9341 (bigger and with touch screen). My chip has 64kb flash and 20k RAM(STM32F103C8T6, chinese board like Maple Mini). I’m just using a ADC, USART_RX (Bluetooth), LCD I2C and now SPI. I’ll try every methods you told me and if I have succes, I return to tell you. Again, sorry about my English and thanks man.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s