ILI9341 Command Delay
In the example code, unlike the datasheet, there is a TFT_Delay(10) after the command. I've found that my display does not operate correctly unless I have a delay. However, a response in this forum from another user seems to indicate that the command delay is not necessary. If the a delay after a command is not necessary, what might be causing this issue? To be specific, when I omit the delay, the LCD skips some of the pixels that are subsequently sent and the pixels that are omitted are random. I'm running the application on a 48 MHz Coretex-M0.
My application requires displaying a grid, so I'm constantly changing the window with the page and row set commands. The delay required to send those commands is large enough that I'm only getting 1-2 FPS. I get about 10 FPS drawing to the whole screen without sending window size commands.
Thanks
-
Sounds like you will need to implement a small delay if it is not working without it. I didn't have any delays in my Arduino example code below because it operates at 16MHz:
//---------------------------------------------------------
/*
NHD_2_4_240320SF_CTXI_mega.ino
Program for writing to Newhaven Display 2.4” TFT with ILI9341 controller
(c)2013 Mike LaVine - Newhaven Display International, LLC.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------
// The 8 bit data bus is connected to PORTA of the Arduino Mega2560
// 5V voltage regulator on Arduino Mega has been replaced with a 3.3V regulator to provide 3.3V logic
int RS = 30; // RS signal connected to Arduino digital pin 30
int WR = 31; // /WR signal connected to Arduino digital pin 31
int RD = 32; // /RD signal connected to Arduino digital pin 32
int RES = 33; // /RES signal connected to Arduino digital pin 33
// /CS signal tied to GND
// IM0 signal tied to VDD
void comm_out(unsigned char c)
{
digitalWrite(RS, LOW);
PORTA = c;
digitalWrite(WR, LOW);
digitalWrite(WR, HIGH);
}
void data_out(unsigned char d)
{
digitalWrite(RS, HIGH);
PORTA = d;
digitalWrite(WR, LOW);
digitalWrite(WR, HIGH);
}
void disp()
{
unsigned int i;
comm_out(0x2C); //command to begin writing to frame memory
for(i=0;i<38400;i++) //fill screen with blue pixels
{
data_out(0x00);
data_out(0x1F);
data_out(0x00);
data_out(0x1F);
}
for(i=0;i<38400;i++) //fill screen with green pixels
{
data_out(0x07);
data_out(0xE0);
data_out(0x07);
data_out(0xE0);
}
}
void setup()
{
DDRC = 0xFF;
PORTC = 0x00;
DDRA = 0xFF;
PORTA = 0x00;
digitalWrite(RD, HIGH);
digitalWrite(WR, LOW);
digitalWrite(RES, LOW);
delay(250);
digitalWrite(RES, HIGH);
delay(250);
comm_out(0x28); //display off
comm_out(0x11); //exit SLEEP mode
comm_out(0xCB); //power control A
data_out(0x39);
data_out(0x2C);
data_out(0x00);
data_out(0x34);
data_out(0x02);
comm_out(0xCF); //power control B
data_out(0x00);
data_out(0x81);
data_out(0x30);
comm_out(0xC0);
data_out(0x26); //power control 1
data_out(0x04); //second parameter for ILI9340 (ignored by ILI9341)
comm_out(0xC1);
data_out(0x11); //power control 2
comm_out(0xC5);
data_out(0x35);
data_out(0x3E); //VCOM control 1
comm_out(0x36);
data_out(0x88); //memory access control = BGR
comm_out(0xB1);
data_out(0x00);
data_out(0x18); //frame rate control
comm_out(0xB6);
data_out(0x0A);
data_out(0xA2); //display function control
comm_out(0xC7);
data_out(0xBE); //VCOM control 2
comm_out(0x3A);
data_out(0x55); //pixel format = 16 bit per pixel
/*comm_out(0xE0);
data_out(0x1F); //positive gamma correction
data_out(0x1B);
data_out(0x18);
data_out(0x0B);
data_out(0x0F);
data_out(0x09);
data_out(0x46);
data_out(0xB5);
data_out(0x37);
data_out(0x0A);
data_out(0x0C);
data_out(0x07);
data_out(0x07);
data_out(0x05);
data_out(0x00);
comm_out(0xE1);
data_out(0x00); //negative gamma correction
data_out(0x24);
data_out(0x27);
data_out(0x04);
data_out(0x10);
data_out(0x06);
data_out(0x39);
data_out(0x74);
data_out(0x48);
data_out(0x05);
data_out(0x13);
data_out(0x38);
data_out(0x38);
data_out(0x3A);
data_out(0x1F);*/
comm_out(0xF2); //3g damma control
data_out(0x02); //off
comm_out(0x26); //gamma curve 3
data_out(0x01);
comm_out(0x2A);
data_out(0x00); //column address set
data_out(0x00); //start 0x0000
data_out(0x00);
data_out(0xEF); //end 0x00EF
comm_out(0x2B);
data_out(0x00); //page address set
data_out(0x00); //start 0x0000
data_out(0x01);
data_out(0x3F); //end 0x003F
comm_out(0x29); //display ON
delay(10);
}
void loop()
{
disp();
delay(1000);
}However, with faster micros, you will probably need to control some of the timing by use of delay(s).
All relevant timing information can be viewed on pages 238 - 241 in the ILI9341 datasheet, here: https://newhavendisplay.com/content/app_notes/ILI9341.pdf0 -
It sounds like it might be a write cycle timing violation to me. If you are bit-banging and toggling the ~WR signal without a delay, the "Write Cycle" minimum timing of 66 ns would likely be violated. Perhaps a command requires the full Write Cycle time and so the delay after the command just lets the controller catch up before you start throwing the data at it. Otherwise, it is running behind and so it periodically overflows the buffer while sending the data.
0
Please sign in to leave a comment.
Comments
2 comments