Adapting SPI_TFT_ILI9320 library to work with the ILI9325 Controller

Overview

I'd been happily using Frank Vannieuwkerke's SPI_TFT_ILI9320 library quite happily for awhile with my Mini-DK2 board (thanks Frank!) and the HY28A SPI TFT display that came with it, and it worked beautifully. Until that is, I bought another one and was told that the 'A' display variant was now obsolete and that it has been replaced with the HY28B display, which has a different pin-out in order to accommodate a new controller (ILI9325) and dual parallel and SPI interfaces. Luckily, the changes required to Frank's library are not great. You just need some new code to reset the display.

New SPI tft_reset() function

void SPI_TFT::tft_reset()
{
    DigitalOut lcd_reset(P3_26);        // Hard coded to reset the display properly on my board
    lcd_reset = 1;  // Reset is active low.
    wait_ms(100);
    lcd_reset = 0;  // Reset
    wait_ms(2);     // wait at least 1ms
    lcd_reset = 1;
    wait_ms(50);    // Now wait at least 50ms before doing anything else
    
    _spi.format(8,3);                                   // 8 bit spi mode 3
    _spi.frequency(SPI_F_HI);                           // 24 Mhz SPI clock on my board, but Frank's code sets it to 48MHz

// Begin 9325C setup
    // LCD reset for the ILI9325C
    wr_reg(0x00e7,0x0010);
    wr_reg(0x0000,0x0001);                              // Start internal oscillator
    wr_reg(0x0001,0x0100);
    wr_reg(0x0002,0x0700);                              // Power on sequence
    wr_reg(0x0003,(1<<12)|(1<<5)|(1<<4)|(1<<3));        // Important!
    wr_reg(0x0004,0x0000);
    wr_reg(0x0008,0x0207);                              // Display Control 2
    wr_reg(0x0009,0x0000);                              // Display Control 3
    wr_reg(0x000a,0x0000);                              // Display Control 4
    wr_reg(0x000c,0x0001);                              // RGB Display Interface Control 1
    wr_reg(0x000d,0x0000);                              // Frame Marker Position
    wr_reg(0x000f,0x0000);                              // RGB Display Interface Control 2
    // Power on sequence
    wr_reg(0x0010,0x0000);                              // Power Control 1
    wr_reg(0x0011,0x0007);                              // Power Control 2
    wr_reg(0x0012,0x0000);                              // Power Control 3
    wr_reg(0x0013,0x0000);                              // Power Control 4
    wait_ms(50);
    wr_reg(0x0010,0x1590);                              // Power Control 1
    wr_reg(0x0011,0x0227);                              // Power Control 2
    wait_ms(50);
    wr_reg(0x0012,0x009c);                              // Power Control 3
    wait_ms(50);
    wr_reg(0x0013,0x1900);                              // Power Control 4
    wr_reg(0x0029,0x0023);                              // Power Control 7
    wr_reg(0x002b,0x000e);                              // Frame Rate and Color Control
    wait_ms(50);
    wr_reg(0x0020,0x0000);                              // Set GRAM Horizontal Address
    wr_reg(0x0021,0x0000);                              // Set GRAM Vertical Address
    wait_ms(50);
    wr_reg(0x0030,0x0007);                              // Gamma control
    wr_reg(0x0031,0x0707);                              // Gamma control
    wr_reg(0x0032,0x0006);                              // Gamma control
    wr_reg(0x0035,0x0704);                              // Gamma control
    wr_reg(0x0036,0x1f04);                              // Gamma control
    wr_reg(0x0037,0x0004);                              // Gamma control
    wr_reg(0x0038,0x0000);                              // Gamma control
    wr_reg(0x0039,0x0706);                              // Gamma control
    wr_reg(0x003c,0x0701);                              // Gamma control
    wr_reg(0x003d,0x000f);                              // Gamma control
    wait_ms(50);
    wr_reg(0x0050,0x0000);                              // Horizontal and Vertical RAM Address Position
    wr_reg(0x0051,0x00ef);                              // Horizontal and Vertical RAM Address Position
    wr_reg(0x0052,0x0000);                              // Horizontal and Vertical RAM Address Position
    wr_reg(0x0053,0x013f);                              // Horizontal and Vertical RAM Address Position
    wr_reg(0x0060,0xa700);                              // Gate Scan Control
    wr_reg(0x0061,0x0001);                              // Gate Scan Control
    wr_reg(0x006a,0x0000);                              // Gate Scan Control
    wr_reg(0x0080,0x0000);                              // Partial Image 1 Display Position
    wr_reg(0x0081,0x0000);                              // Partial Image 1 RAM Start/End Address
    wr_reg(0x0082,0x0000);                              // Partial Image 1 RAM Start/End Address
    wr_reg(0x0083,0x0000);                              // Partial Image 2 Display Position
    wr_reg(0x0084,0x0000);                              // Partial Image 2 RAM Start/End Address
    wr_reg(0x0085,0x0000);                              // Partial Image 2 RAM Start/End Address
    
    wr_reg(0x0090,0x0010);                              // Panel Interface Control 1
    wr_reg(0x0092,0x0000);                              // Panel Interface Control 2
    wr_reg(0x0093,0x0003);
    wr_reg(0x0095,0x0110);                              // Panel Interface Control 4
    wr_reg(0x0097,0x0000);                              // Panel Interface Control 5
    wr_reg(0x0098,0x0000);
    
    wr_reg(0x0007,0x0133);                              // Sequence to turn Display On
// End 9325 setup

    wr_reg(0x0020,0x0000);                              // Set X position to 0
    wr_reg(0x0021,0x0000);                              // Set Y position to 0

    wait_ms(100);
    WindowMax();
}

I publish my initialisation code for the ILI9325 controller for whoever might find it useful. Simply replace the tft_reset() function in Frank's original library with this one.


3 comments on Adapting SPI_TFT_ILI9320 library to work with the ILI9325 Controller:

24 May 2014

Hi Jason

I'm trying to get HY28B dispay to work with KL25Z without any luck using the updated tft_reset function above. When the board is powered up, the display stays grayish color. Is there anything else I need to modify?

Thanks a lot.

24 May 2014

I found out what why the display didn't work for me. I had the "MISO" and "MOSI" pin reversed on KL25Z board. Please disregard my above comment. Cheers.

12 Jun 2014

Apologies for missing out on this message.
Another user posted a similar question at https://mbed.org/questions/3616/Is-this-compatible-with-the-HY28B-The-HY/.
I reworked the library to auto-detect the ILI9320, ILI9325 and ILI9328
As i currently don't have an ILI9325 or ILI9328 available, this is untested (i ordered an ILI9325 board - should receive it in 3 weeks). Meanwhile, if someone has time to test the changes, use the issues tab on the library page to report any problems.

Please log in to post comments.