Thursday, 10 September 2015

c - My 2.2" TFT LCD doesn't work (ILI9225 driver)(STM32F1)


Today I was working on this TFT LCD and I don't know why it doesn't work.


figure1


figure2


This LCD is a 2.2" TFT with ILI9225 LCD driver and is connected to my STM32F1. Here is the datasheet of LCD driver:


http://www.hpinfotech.ro/ILI9225B.pdf


And sample code:


http://www.displayfuture.com/Display/datasheet/controller/ILI9225.pdf



And here is other sources that I've read:


https://github.com/prenticedavid/TFT_SPI_kbv/blob/master/ILI9225_kbv.cpp https://github.com/prenticedavid/TFT_SPI_kbv/blob/master/ILI9225_kbv.h


https://github.com/Nkawu/TFT_22_ILI9225/blob/master/src/TFT_22_ILI9225.h https://github.com/Nkawu/TFT_22_ILI9225/blob/master/src/TFT_22_ILI9225.cpp


https://www.mikrocontroller.net/topic/373581


Software


For sofware, here is the code I've used to initiate the LCD:


void TM_ILI9225_Init(void) 
{



ILI9225_RST_RESET;
TM_ILI9225_Delay(20000);
ILI9225_RST_SET;
TM_ILI9225_Delay(200000);
ILI9225_RST_RESET;
TM_ILI9225_Delay(400000);

TM_ILI9225_SendCommand(0x28);
TM_ILI9225_SendData(0x00CE);



TM_ILI9225_SendCommand(0x10);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x11);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x12);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x13);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x14);

TM_ILI9225_SendData(0x0000);

TM_ILI9225_Delay(400000);

TM_ILI9225_SendCommand(0x11);
TM_ILI9225_SendData(0x103B);//0x0018
TM_ILI9225_SendCommand(0x12);
TM_ILI9225_SendData(0x6121);
TM_ILI9225_SendCommand(0x13);
TM_ILI9225_SendData(0x006F);

TM_ILI9225_SendCommand(0x14);
TM_ILI9225_SendData(0x495F);
TM_ILI9225_SendCommand(0x10);
TM_ILI9225_SendData(0x0A00);

TM_ILI9225_Delay(400000);

TM_ILI9225_SendCommand(0x11);
TM_ILI9225_SendData(0x1000);


TM_ILI9225_Delay(400000);

TM_ILI9225_SendCommand(0x01);
TM_ILI9225_SendData(0x011C);
TM_ILI9225_SendCommand(0x02);
TM_ILI9225_SendData(0x0100);//0x0100
TM_ILI9225_SendCommand(0x03);
TM_ILI9225_SendData(0x1030);
TM_ILI9225_SendCommand(0x07);
TM_ILI9225_SendData(0x0000);

TM_ILI9225_SendCommand(0x08);
TM_ILI9225_SendData(0x0808);
TM_ILI9225_SendCommand(0x0B);
TM_ILI9225_SendData(0x1100);
TM_ILI9225_SendCommand(0x0C);
TM_ILI9225_SendData(0x0111);//0x0000
TM_ILI9225_SendCommand(0x0F);
TM_ILI9225_SendData(0x0F01);//
TM_ILI9225_SendCommand(0x20);
TM_ILI9225_SendData(0x0000);

TM_ILI9225_SendCommand(0x21);
TM_ILI9225_SendData(0x0000);

TM_ILI9225_SendCommand(0x30);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x31);
TM_ILI9225_SendData(0x00DB);
TM_ILI9225_SendCommand(0x32);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x33);

TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x34);
TM_ILI9225_SendData(0x00DB);
TM_ILI9225_SendCommand(0x35);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x36);
TM_ILI9225_SendData(0x00AF);
TM_ILI9225_SendCommand(0x37);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x38);

TM_ILI9225_SendData(0x00DB);
TM_ILI9225_SendCommand(0x39);
TM_ILI9225_SendData(0x0000);


TM_ILI9225_SendCommand(0x50);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x51);
TM_ILI9225_SendData(0x0808);
TM_ILI9225_SendCommand(0x52);

TM_ILI9225_SendData(0x080A);
TM_ILI9225_SendCommand(0x53);
TM_ILI9225_SendData(0x000A);
TM_ILI9225_SendCommand(0x54);
TM_ILI9225_SendData(0x0A08);
TM_ILI9225_SendCommand(0x55);
TM_ILI9225_SendData(0x0808);
TM_ILI9225_SendCommand(0x56);
TM_ILI9225_SendData(0x0000);
TM_ILI9225_SendCommand(0x57);

TM_ILI9225_SendData(0x0A00);
TM_ILI9225_SendCommand(0x58);
TM_ILI9225_SendData(0x0710);
TM_ILI9225_SendCommand(0x59);
TM_ILI9225_SendData(0x0710);

TM_ILI9225_SendCommand(0x07);
TM_ILI9225_SendData(0x0012);

TM_ILI9225_Delay(400000);


TM_ILI9225_SendCommand(0x07);
TM_ILI9225_SendData(0x1017);


}

And here is functions:


void TM_ILI9225_Delay(volatile unsigned int delay) {
for (; delay != 0; delay--);

}

void TM_ILI9225_SendCommand(uint16_t data) {

ILI9225_WRX_RESET;
a = 3;
while(a){
a--;
}
GPIOA->BRR = GPIO_Pin_4;

a = 3;
while(a){
a--;
}
SPI1->DR = data;
a = 3;
while(a){
a--;
}
GPIOA->BSRR = GPIO_Pin_4; //setbit


}

void TM_ILI9225_SendData(uint16_t data) {

ILI9225_WRX_SET;
a = 3;
while(a){
a--;
}

GPIOA->BRR = GPIO_Pin_4;
a = 3;
while(a){
a--;
}
SPI1->DR = data;
a = 3;
while(a){
a--;
}

GPIOA->BSRR = GPIO_Pin_4;

}

void TM_ILI9225_SetCursorPosition(uint16_t x1, uint16_t y1) {
TM_ILI9225_SendCommand(0x20);
TM_ILI9225_SendData(x1);

TM_ILI9225_SendCommand(0x21);
TM_ILI9225_SendData(y1);


}

void TM_ILI9225_Fill(uint16_t color) {
unsigned int n, i, j;
i = color >> 8;
j = color & 0xFF;
TM_ILI9225_SetCursorPosition(0, 0);

TM_ILI9225_SendCommand(0x22);


for (n = 0; n < ILI9225_PIXEL; n++) {
TM_ILI9225_SendData(i);
TM_ILI9225_SendData(j);
}

And Macros:


#define ILI9225_RST_SET             GPIO_SetBits( GPIOA , GPIO_Pin_3)
#define ILI9225_RST_RESET GPIO_ResetBits(GPIOA, GPIO_Pin_3)
#define ILI9225_WRX_SET GPIO_SetBits(GPIOA, GPIO_Pin_2)

#define ILI9225_WRX_RESET GPIO_ResetBits(GPIOA, GPIO_Pin_2)

#define ILI9225_WIDTH 220
#define ILI9225_HEIGHT 176
#define ILI9225_PIXEL 38720

And this is the code that I use to change color of the LCD.


TM_ILI9225_Init();
TM_ILI9225_Fill(0xfb20);


I'm not going to put other parts of the code (such as SPI initialization and etc) because the rest of the code is tested and works very well.


Hardware


Here is the connection of the pins:


MCU -------- LCD


PIN-3A ----> RST


PIN-2A ----> RS


NSS -------> CS


MOSI ------> SDI


CLK -------> CLK


3v3 -------> LED



Vcc -------> Vcc


GND -------> GND


I've checked the wiring by my logic analyzer and they works very well.


What have I done so far?


This LCD module has a 74HC245 IC and I thought it might be possible that this IC cannot handle high speed SPI then I reduced and increased the speed of the interface and checked it by my logic analyzer and nothing changed. I manupulated the initialization code and especialy this part:


TM_ILI9225_SendCommand(0x0C);
TM_ILI9225_SendData(0x0000);

To this:


TM_ILI9225_SendCommand(0x0C);

TM_ILI9225_SendData(0x0111);

But nothing happend. I think many codes on the net incorrectly used value 0x0000 for register 0x0c.


Any idea would be appreciated




No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...