interfacing MBED to LCD ILI9325

24 Jun 2012

Hy. I am trying to program the following LCD (http://www.ghielectronics.com/catalog/product/262) which use the ILI9325 controller. I modified the code given for HX8347 (http://mbed.org/users/Suky/programs/LCDTFT_Library/llv383) to ca work with the ILI9325, i changed all the register. i used 16bit data in 8bit parallel interface. But it's not work and i dont know were is the problem.

here the code :

enum
{
  ILI9325_COMMANDS_DRIVERCODEREAD                 = 0x0000,
  ILI9325_COMMANDS_DRIVEROUTPUTCONTROL1           = 0x0001,
  ILI9325_COMMANDS_LCDDRIVINGCONTROL              = 0x0002,
  ILI9325_COMMANDS_ENTRYMODE                      = 0x0003,
  ILI9325_COMMANDS_RESIZECONTROL                  = 0x0004,
  ILI9325_COMMANDS_DISPLAYCONTROL1                = 0x0007,
  ILI9325_COMMANDS_DISPLAYCONTROL2                = 0x0008,
  ILI9325_COMMANDS_DISPLAYCONTROL3                = 0x0009,
  ILI9325_COMMANDS_DISPLAYCONTROL4                = 0x000A,
  ILI9325_COMMANDS_RGBDISPLAYINTERFACECONTROL1    = 0x000C,
  ILI9325_COMMANDS_FRAMEMAKERPOSITION             = 0x000D,
  ILI9325_COMMANDS_RGBDISPLAYINTERFACECONTROL2    = 0x000F,
  ILI9325_COMMANDS_POWERCONTROL1                  = 0x0010,
  ILI9325_COMMANDS_POWERCONTROL2                  = 0x0011,
  ILI9325_COMMANDS_POWERCONTROL3                  = 0x0012,
  ILI9325_COMMANDS_POWERCONTROL4                  = 0x0013,
  ILI9325_COMMANDS_HORIZONTALGRAMADDRESSSET       = 0x0020,
  ILI9325_COMMANDS_VERTICALGRAMADDRESSSET         = 0x0021,
  ILI9325_COMMANDS_WRITEDATATOGRAM                = 0x0022,
  ILI9325_COMMANDS_POWERCONTROL7                  = 0x0029,
  ILI9325_COMMANDS_FRAMERATEANDCOLORCONTROL       = 0x002B,
  ILI9325_COMMANDS_GAMMACONTROL1                  = 0x0030,
  ILI9325_COMMANDS_GAMMACONTROL2                  = 0x0031,
  ILI9325_COMMANDS_GAMMACONTROL3                  = 0x0032,
  ILI9325_COMMANDS_GAMMACONTROL4                  = 0x0035,
  ILI9325_COMMANDS_GAMMACONTROL5                  = 0x0036,
  ILI9325_COMMANDS_GAMMACONTROL6                  = 0x0037,
  ILI9325_COMMANDS_GAMMACONTROL7                  = 0x0038,
  ILI9325_COMMANDS_GAMMACONTROL8                  = 0x0039,
  ILI9325_COMMANDS_GAMMACONTROL9                  = 0x003C,
  ILI9325_COMMANDS_GAMMACONTROL10                 = 0x003D,
  ILI9325_COMMANDS_HORIZONTALADDRESSSTARTPOSITION = 0x0050,
  ILI9325_COMMANDS_HORIZONTALADDRESSENDPOSITION   = 0x0051,
  ILI9325_COMMANDS_VERTICALADDRESSSTARTPOSITION   = 0x0052,
  ILI9325_COMMANDS_VERTICALADDRESSENDPOSITION     = 0x0053,
  ILI9325_COMMANDS_DRIVEROUTPUTCONTROL2           = 0x0060,
  ILI9325_COMMANDS_BASEIMAGEDISPLAYCONTROL        = 0x0061,
  ILI9325_COMMANDS_VERTICALSCROLLCONTROL          = 0x006A,
  ILI9325_COMMANDS_PARTIALIMAGE1DISPLAYPOSITION   = 0x0080,
  ILI9325_COMMANDS_PARTIALIMAGE1AREASTARTLINE     = 0x0081,
  ILI9325_COMMANDS_PARTIALIMAGE1AREAENDLINE       = 0x0082,
  ILI9325_COMMANDS_PARTIALIMAGE2DISPLAYPOSITION   = 0x0083,
  ILI9325_COMMANDS_PARTIALIMAGE2AREASTARTLINE     = 0x0084,
  ILI9325_COMMANDS_PARTIALIMAGE2AREAENDLINE       = 0x0085,
  ILI9325_COMMANDS_PANELINTERFACECONTROL1         = 0x0090,
  ILI9325_COMMANDS_PANELINTERFACECONTROL2         = 0x0092,
  ILI9325_COMMANDS_PANELINTERFACECONTROL3         = 0x0093,
  ILI9325_COMMANDS_PANELINTERFACECONTROL4         = 0x0095,
  ILI9325_COMMANDS_PANELINTERFACECONTROL5         = 0x0097,
  ILI9325_COMMANDS_PANELINTERFACECONTROL6         = 0x0098,
  ILI9325_COMMANDS_OTPVCMPROGRAMMINGCONTROL       = 0x00A1,
  ILI9325_COMMANDS_OTPVCMSTATUSANDENABLE          = 0x00A2,
  ILI9325_COMMANDS_OTPPROGRAMMINGIDKEY            = 0x00A5
};

#include "LCDTFT_16bitto8bit.h"

LCDTFT::LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, BusInOut *BUSLCD)
    : LCD_PIN_RD(PIN_RD),LCD_PIN_WR(PIN_WR),LCD_PIN_RS(PIN_RS),LCD_PIN_CS(PIN_CS),LCD_PIN_RESET(PIN_RESET){
    LCD_PORT=BUSLCD;
    X=0;
    Y=0;
    X_min=0;
    X_max=LCD_X_MAX;
    _Alto=1;
    _Color=0x0000;
} 

void LCDTFT::vLCDTFTSetParametersPrintf(uint16_t Xo,uint16_t Yo,uint16_t Xmin,uint16_t Xmax,unsigned char Alto, uint16_t Color){

    X=Xo;
    Y=Yo;
    X_min=Xmin;
    X_max=Xmax;
    _Alto=Alto;
    _Color=Color;
} 

int LCDTFT::_putc(int value){
    char Fmt[2]={value,0};

    if(value=='\n'){
        X=X_min;
        Y+=7*_Alto + 1;
    }else{
        vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color);
        X+=5*_Alto+1;
        if(X >= X_max){
            X = X_min;                           
            Y += 7*_Alto + 1;                
        }
    }
    return(value);
} 

int LCDTFT::_getc(){
    return(-1);
} 

/**************************************************************************/
/*!
    @brief  Writes the supplied 16-bit command using an 8-bit interface
*/
/**************************************************************************/
void LCDTFT::vLCDTFTWriteCommand(uint16_t Command){   
    
    LCD_PIN_CS=0;
    LCD_PIN_RS=0;
    LCD_PIN_WR=1;
    LCD_PIN_RD=1;
    LCD_PORT->write(Command >> 8);   
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;
    LCD_PORT->write(Command);
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;
    LCD_PIN_CS=1;  
}

/**************************************************************************/
/*!
    @brief  Writes the supplied 16-bit data using an 8-bit interface
*/
/**************************************************************************/
void LCDTFT::vLCDTFTWriteData(uint16_t Data){
    
    LCD_PIN_CS=0;
    LCD_PIN_WR=1;
    LCD_PIN_RS=1; 
    LCD_PIN_RD=1;
    LCD_PORT->write(Data >> 8);   
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;
    LCD_PORT->write(Data);
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;
    LCD_PIN_CS =1; 
}
/**************************************************************************/
/*!
    @brief  Sends a 16-bit command + 16-bit data
*/
/**************************************************************************/
void LCDTFT::vLCDTFTWriteCommandData(uint16_t Command,uint16_t Data){
    vLCDTFTWriteCommand(Command);
    vLCDTFTWriteData(Data);
}
/**************************************************************************/
/*!
    @brief  Sets the cursor to the specified X/Y position
*/
/**************************************************************************/
void LCDTFT::vLCDTFTAddressSetPoint(uint16_t x,uint16_t y){

    vLCDTFTWriteCommandData(ILI9325_COMMANDS_HORIZONTALGRAMADDRESSSET,x); 
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALGRAMADDRESSSET,y); 
    vLCDTFTWriteCommand(0x0022);
}
/**************************************************************************/
/*!
    @brief  Sets the window confines
*/
/**************************************************************************/
void LCDTFT::vLCDTFTAddressSet(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2){ 
//  vLCDTFTAddressSet(PosXImagen, y, PosXImagen+WidthPixel-1, y);
   
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_HORIZONTALADDRESSSTARTPOSITION, x1);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_HORIZONTALADDRESSENDPOSITION, x2);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALADDRESSSTARTPOSITION, y1);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALADDRESSENDPOSITION, y2);
    vLCDTFTAddressSetPoint(x1, y1);
}  
/**************************************************************************/
/*!
    @brief  Sends the initialisation sequence to the display controller
*/
/**************************************************************************/
void LCDTFT::vLCDTFTInit(void){ // Initialize the ILI9225 lcd driver. return 0 if initial succeded

    LCD_PIN_RD=1;
    LCD_PIN_WR=1;
    LCD_PIN_CS=1;
    LCD_PIN_RS=1;
    
    LCD_PIN_RESET=1;
    wait_ms(100);   
    LCD_PIN_RESET=0;
    wait_ms(100);
    LCD_PIN_RESET=1;
    wait_ms(100);
        
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DRIVERCODEREAD, 0x0001);  // Star oscillator
    wait_ms(50);
    
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DRIVEROUTPUTCONTROL1, 0x0100);  // Driver Output Control Register (R01h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_LCDDRIVINGCONTROL, 0x0700);     // LCD Driving Waveform Control (R02h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_ENTRYMODE, 0x1030);             // Entry Mode (R03h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_RESIZECONTROL, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DISPLAYCONTROL2, 0x0202);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DISPLAYCONTROL3, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DISPLAYCONTROL4, 0x0000);       // Fmark On
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_RGBDISPLAYINTERFACECONTROL1, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_FRAMEMAKERPOSITION, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_RGBDISPLAYINTERFACECONTROL2, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL1, 0x0000);         // Power Control 1 (R10h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL2, 0x0007);         // Power Control 2 (R11h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL3, 0x0000);         // Power Control 3 (R12h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL4, 0x0000);         // Power Control 4 (R13h)
    wait_ms(200);
    
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL1, 0x1690);         // Power Control 1 (R10h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL2, 0x0227);         // Power Control 2 (R11h)
    wait_ms(50);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL3, 0x001A);         // Power Control 3 (R12h)
    wait_ms(50);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL4, 0x1800);         // Power Control 4 (R13h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_POWERCONTROL7, 0x002A);         // NVM read data 2 (R29h)
    wait_ms(50);
    
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL1, 0x0000);         // Gamma Control 1
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL2, 0x0000);         // Gamma Control 2
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL3, 0x0000);         // Gamma Control 3
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL4, 0x0206);         // Gamma Control 4
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL5, 0x0808);         // Gamma Control 5
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL6, 0x0007);         // Gamma Control 6
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL7, 0x0201);         // Gamma Control 7
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL8, 0x0000);         // Gamma Control 8
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL9, 0x0000);         // Gamma Control 9
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_GAMMACONTROL10, 0x0000);        // Gamma Control 10
    
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_HORIZONTALGRAMADDRESSSET, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALGRAMADDRESSSET, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_HORIZONTALADDRESSSTARTPOSITION, 0x0000);                      // Window Horizontal RAM Address Start (R50h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_HORIZONTALADDRESSENDPOSITION, 0x00EF); // ili9325Properties.width - 1);   // Window Horizontal RAM Address End (R51h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALADDRESSSTARTPOSITION, 0x0000);                        // Window Vertical RAM Address Start (R52h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALADDRESSENDPOSITION, 0x013F); // ili9325Properties.height - 1);    // Window Vertical RAM Address End (R53h)
    
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DRIVEROUTPUTCONTROL2, 0xA700);    // Driver Output Control (R60h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_VERTICALSCROLLCONTROL, 0x0000);
    
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_PANELINTERFACECONTROL1, 0x0010);  // Panel Interface Control 1 (R90h)
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_PANELINTERFACECONTROL2, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_PANELINTERFACECONTROL3, 0x0003);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_PANELINTERFACECONTROL4, 0x1100);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_PANELINTERFACECONTROL5, 0x0000);
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_PANELINTERFACECONTROL6, 0x0000);

    // Display On
    vLCDTFTWriteCommandData(ILI9325_COMMANDS_DISPLAYCONTROL1, 0x0133);     // Display Control (R07h)
    wait_ms(100);
    vLCDTFTWriteCommand(ILI9325_COMMANDS_WRITEDATATOGRAM);
}
/**************************************************************************/
/*!
    @brief  Assign background color
*/
/**************************************************************************/
void LCDTFT::vLCDTFTFillScreen(uint16_t Color){
    uint16_t i,j;
 
    vLCDTFTAddressSet(0,0,239,319);
    vLCDTFTWriteCommand(ILI9325_COMMANDS_WRITEDATATOGRAM);
    
    //LCD_PIN_CS=0;
    //LCD_PIN_RS=1; 
    //LCD_PIN_RD=1;
    //LCD_PIN_WR=1;

    for(i=0;i<320;i++){
        for (j=0;j<240;j++){
            vLCDTFTWriteData(Color);
        }
    } 
    //LCD_PIN_CS=1;     
} 
/**************************************************************************/
/*!
    @brief  Draws a single pixel at the specified X/Y location
*/
/**************************************************************************/
void LCDTFT::vLCDTFTPoint(uint16_t x,uint16_t y,uint16_t Color){

    vLCDTFTAddressSetPoint(x,y);
    vLCDTFTWriteCommand(ILI9325_COMMANDS_WRITEDATATOGRAM);  // Write Data to GRAM (R22h) 
    vLCDTFTWriteData(Color);
}

#include "mbed.h"
#include "LCDTFT_16bitto8bit.h"
// LCDTFT(PIN_RD , PIN_WR , PIN_RS , PIN_CS , PIN_RESET , BusOut *BUSLCD); 

BusInOut     MyBus(p29,p22,p23,p24,p25,p26,p27,p28);
PwmOut      BL(p21);
LCDTFT     MyLCD(p19,p18,p17,p16,p20,&MyBus);

int main(){
 
    MyLCD.vLCDTFTInit();
    MyLCD.vLCDTFTFillScreen(ColorRed);
    MyLCD.vLCDTFTSetParametersPrintf(10,20,10,229,2,0x0000);
    MyLCD.printf("Hola mbed!!!");
    wait_ms(2000);
    MyLCD.vLCDTFTRectangle(0,0,239,319,1,0x0000);
    MyLCD.vLCDTFTCircle(120,160,110,0,0xFFFF);
}

thanks

23 Jun 2012

Assuming that all your wiring and voltages are OK, there may be a problem with the way you write commands and data. You first write the commandregister (index) in two parts (upper and lower byte), then you write the data that should be written to that register (also in upper and lower byte parts). You use two separate instructions and each activates and deactivates the nCS line. The ILI9325 datasheet (fig 24, pg 50, 8/9bit interface timing) shows that this should be one single operation without deactivating the nCS between the command and datapart.

Try:

/**************************************************************************/
/*!
    @brief  Sends a 16-bit command + 16-bit data using an 8-bit interface
*/
/**************************************************************************/
void LCDTFT::vLCDTFTWriteCommandData(uint16_t Command,uint16_t Data){

   
//Write command part

//now activate nCS
    LCD_PIN_CS=0;

    LCD_PIN_RS=0;

    LCD_PORT->write(Command >> 8);   
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;
    LCD_PORT->write(Command);
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;

//Now write data    
    LCD_PIN_RS=1; 

    LCD_PORT->write(Data >> 8);   
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;
    LCD_PORT->write(Data);
    LCD_PIN_WR=0;
    wait_ms(100);
    LCD_PIN_WR=1;

//now deactivate nCS
    LCD_PIN_CS =1;
 
}
24 Jun 2012

Thanks for your reply. i just try this idea but the result stay the same, and i try this LCD with arduino with code who use the same method (activates and deactivates the nCS line in separate instructions) and that work correctly.

24 Jun 2012

I havent usd BusInOut yet, but in the examples the mode is set first before using it:

BusInOut pins(p5, p10, p7);

int main() {
    pins.output();
    pin = 0x3;     
    wait(1);
    pins.input();
    wait(1);
    if(pins == 0x6) {
        printf("Hello!\n");
    }
}

Call LCD_PORT->output() at least once before using it. May not be needed if it is a part of the LCD_PORT->write() though.

When this new commandcode is still not working you should check the wiring, voltages and GND again. Maybe write some testcode to set/reset each control and databit individually and measure on the displays 40 pinconnector.

20 Sep 2016

Hello!

I'm using STM32F446RE and 2.8" TFT LCD with built in ILI9325 controller configured in 8bit mode, but I'm having a hard finding a library that can get the job done, for instance I don't know how to configure the control pins to individual bits in a GPIO, I'm using GCC based IDE "CoIDE", can I get help? :)