Initialization TFT Panel NHD-5.0-800480FT-CTXL-T 800x480 with SPI on ESP32 Arduino IDE
Hello,
I am trying to Initialize the EVE FT812 using the Initialization pseudo-code shown in the Programming Guide:
Initialization Pseudo-Code:
host_command(CLKEXT);//send command "CLKEXT" to use the external clock source
host_command(CLKSEL);// Choose the system clock frequency, with an assumed value of 60MHz.
host_command(RST_PULSE);//send host command "RST_PULSE" to reset
host_command(ACTIVE);//send host command "ACTIVE" to wake up
while (0x7C != rd8(REG_ID));
while (0x0 != rd16(REG_CPURESET)); //Check if EVE is in working status.
wr32(REG_FREQUENCY, 0x3938700); //Configure the system clock to 60MHz.
/* Configure display registers - demonstration for WVGA 800x480 resolution */
wr16(REG_HCYCLE, 928);
wr16(REG_HOFFSET, 88);
wr16(REG_HSYNC0, 0);
wr16(REG_HSYNC1, 48);
wr16(REG_VCYCLE, 525);
wr16(REG_VOFFSET, 32);
wr16(REG_VSYNC0, 0);
wr16(REG_VSYNC1, 3);
wr8(REG_SWIZZLE, 0);
wr8(REG_PCLK_POL, 1);
wr8(REG_CSPREAD, 0);
wr16(REG_HSIZE, 800);
wr16(REG_VSIZE, 480);
/* Write first display list to display list memory RAM_DL*/
wr32(RAM_DL+0,CLEAR_COLOR_RGB(0,0,0));
wr32(RAM_DL+4,CLEAR(1,1,1));
int offset = 8;
for (int i=0; i < 16; i++)
{
wr32(RAM_DL+offset,BITMAP_HANDLE(i));
offset += 4;
wr32(RAM_DL+offset,BITMAP_LAYOUT_H(0));
offset += 4;
wr32(RAM_DL+offset,BITMAP_SIZE_H(0));
offset += 4;
}
wr32(RAM_DL+offset,DISPLAY());
wr8(REG_DLSWAP, DLSWAP_FRAME);//display list swap
/* Enable backlight of display panel */
#if defined(FT81X_ENABLE)
wr16(REG_GPIOX_DIR, 0xffff);
wr16(REG_GPIOX, 0xffff);
#else
wr8(REG_GPIO_DIR,0xff);
wr8(REG_GPIO,0xff);
#endif
wr8(REG_PCLK,2); //Configure the PCLK divisor to 2, i.e. PCLK = System CLK/2
Using This Arduino Program:
#include <SPI.h>#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_SCLK 14
#define HSPI_SS 27
int valueread;
static const int spiClk = 5000000; // 5 MHz
//// uninitialised pointers to SPI objects
SPIClass *vspi = NULL;
SPIClass *hspi = NULL;
//// SPIClass *spi = new SPIClass(HSPI); // Or VSPI*/
//// ************************* 2. void setup() - SPI SETUP AND START *************************************************************************
void setup() {
// vspi = new SPIClass(VSPI);
hspi = new SPIClass(HSPI);
/* vspi->begin();
vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS */
/* hspi->begin(); */
//pinMode(vspi->pinSS(), OUTPUT); //VSPI SS
pinMode(HSPI_SS, OUTPUT); //HSPI SS
//pinMode(RST_PIN, OUTPUT);
digitalWrite(HSPI_SS, HIGH);
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI); //SCLK, MISO, MOSI, SS
TFT_5_Init(hspi);
}
//// ************************* 3. void loop() - LOCAL VARIABLES AND EXAMPLES EXECUTION *******************************************************
void loop() {
// Exampledisp();
// delay(10000);
}
//// ************************* 4. void spisnData8(SPIClass *spi, byte data1) - SPI WRITE/SEND COMMANDS 8 BITS ********************************
//// ************************* 5. void spisnData24(SPIClass *spi, byte data2) - SPI WRITE/SEND COMMANDS 24 BITS ******************************
void spisnData24(SPIClass *spi, int data2) { // command 24 bits
//use it as you would the regular arduino SPI API
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(HSPI_SS, LOW); //pull SS slow to prep other end for transfer
spi->transfer((data2 >> 16) & 0xFF);
spi->transfer((data2)&0xFF);
spi->transfer((data2 >> 8) & 0xFF);
spi->transfer((data2 >> 16) & 0xFF);
digitalWrite(HSPI_SS, HIGH); //pull ss high to signify end of data transfer
spi->endTransaction();
}
//// ************************* 6. void spiwriteReg8(int address1, int value1) - SPI WRITE/SEND REGISTERS 8 BITS ******************************
void spiwriteReg8(SPIClass *spi, int address1, int value1) {
digitalWrite(HSPI_SS, LOW); //pull SS slow to prep other end for transfer
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
spi->transfer((address1 >> 16) & 0xFF); // Write command ()
spi->transfer((address1 >> 8) & 0xFF);
spi->transfer((address1)&0xFF);
spi->transfer(value1);
spi->endTransaction();
digitalWrite(HSPI_SS, HIGH); //pull SS slow to prep other end for transfer
}
/// ************************* 7. void spiwriteReg16(int address2, int value2) - SPI WRITE/SEND REGISTERS 16 BITS ****************************
void spiwriteReg16(SPIClass *spi, int address2, int value2) {
digitalWrite(HSPI_SS, LOW); //pull SS slow to prep other end for transfer
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
spi->transfer((address2 >> 16) & 0xFF); // Write command ()
spi->transfer((address2 >> 8) & 0xFF);
spi->transfer((address2)&0xFF);
spi->transfer((value2)&0xFF);
spi->transfer((value2 >> 8) & 0xFF);
spi->endTransaction();
digitalWrite(HSPI_SS, HIGH); //pull SS slow to prep other end for transfer
}
//// ************************* 8. void spiwriteReg32(int address3, int value3) - SPI WRITE/SEND REGISTERS 32 BITS ****************************
void spiwriteReg32(SPIClass *spi, int address3, int value3) {
digitalWrite(HSPI_SS, LOW); //pull SS slow to prep other end for transfer
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
spi->transfer((address3 >> 16) & 0xFF); // Write command ()
spi->transfer((address3 >> 8) & 0xFF);
spi->transfer((address3)&0xFF);
spi->transfer((value3)&0xFF);
spi->transfer((value3 >> 8) & 0xFF);
spi->transfer((value3 >> 16) & 0xFF);
spi->transfer((value3 >> 24) & 0xFF);
spi->endTransaction();
digitalWrite(HSPI_SS, HIGH); //pull SS slow to prep other end for transfer
}
//// ************************* 9. int spireadRegBytes(int address4, int bytestoread) - SPI READ REGISTERS for Desired Number of Bytes ********
int spireadRegBytes(SPIClass *spi, int address4, int bytestoread) {
int inByte;
digitalWrite(HSPI_SS, LOW); // Select the device
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
spi->transfer((address4 >> 16) & 0xFF); // READ ()
spi->transfer((address4 >> 8) & 0xFF);
spi->transfer((address4)&0xFF);
valueread = spi->transfer(0x00); // Send dummy byte to receive data
bytestoread--;
if (bytestoread > 0) {
// shift the first byte left, then get the second byte:
valueread = valueread << 8;
inByte = spi->transfer(0x00);
// combine the byte you just got with the previous one:
valueread = valueread | inByte;
// decrement the number of bytes left to read:
bytestoread--;
}
digitalWrite(HSPI_SS, HIGH);
spi->endTransaction();
return valueread;
}
//// ************************* 10. void TFT_5_Init(void) - Setting TFT 5 inches Screen - Code snippet 1 Initialization sequence **************
void TFT_5_Init(SPIClass *spi) {
spi->setClockDivider(SPI_CLOCK_DIV16);
spisnData24(hspi, 0x440000); // send command to "CLKEXT" to FT800
spisnData24(hspi, 0x610000); // Choose the system clock frequency, with an assumed value of 60MHz
spisnData24(hspi, 0x680000); // send host command "RST_PULSE" to reset
spisnData24(hspi, 0x000000); //send host command "ACTIVE" to wake up
while (0x7C != spireadRegBytes(hspi, 0x302000, 1))
; // CHECK REG_ID
while (0x0 != spireadRegBytes(hspi, 0x302020, 2))
; //Check if EVE is in working status.
spiwriteReg32(hspi, 0x30200C, 0x03938700); ////Configure the system clock to 60MHz.
/* Configure display registers - demonstration for WVGA 800x480 resolution */
spiwriteReg16(hspi, 0x302034, 0x0320); //1 REG_HSIZE wr16(REG_HSIZE, 800);
spiwriteReg16(hspi, 0x30202C, 0x03A0); //2 REG_HCYCLE wr16(REG_HCYCLE, 928);
spiwriteReg16(hspi, 0x302030, 0x0058); //3 REG_HOFFSET wr16(REG_HOFFSET, 88);
spiwriteReg16(hspi, 0x302038, 0x0000); //4 REG_HSYNC0 wr16(REG_HSYNC0, 0);
spiwriteReg16(hspi, 0x30203C, 0x0030); //5 REG_HSYNC1 wr16(REG_HSYNC1, 48);
spiwriteReg16(hspi, 0x302048, 0x01E0); //6 REG_VSIZE wr16(REG_VSIZE, 480);
spiwriteReg16(hspi, 0x302040, 0x020D); //7 REG_VCYCLE wr16(REG_VCYCLE, 525);
spiwriteReg16(hspi, 0x302044, 0x0020); //8 REG_VOFFSET wr16(REG_VOFFSET, 32);
spiwriteReg16(hspi, 0x30204C, 0x0000); //9 REG_VSYNC0 wr16(REG_VSYNC0, 0);
spiwriteReg16(hspi, 0x302050, 0x0003); //10 REG_VSYNC1 wr16(REG_VSYNC1, 3);
// spiwriteReg8(hspi, 0x302070, 0x02); //11 REG_PCLK wr16(REG_PCLK, 2);
spiwriteReg8(hspi, 0x302064, 0x00); //12 REG_SWIZZLE wr16(REG_SWIZZLE, 0);
spiwriteReg8(hspi, 0x30206C, 0x00); //13 REG_PCLK_POL wr16(REG_PCLK_POL, 0);
spiwriteReg8(hspi, 0x302068, 0x00); //14 REG_CSPREAD wr16(REG_CSPREAD, 0);
spiwriteReg16(hspi, 0x302060, 0x0001); //15 REG_DITHER wr16(REG_DITHER, 1);
spiwriteReg16(hspi, 0x302058, 0x0000); //16 REG_ROTATE wr16(REG_ROTATE, 0);
/* Write first display list to display list memory RAM_DL*/
spiwriteReg32(hspi, 0x300000, 0x0200FF00); /// MEMORY CLEAR_COLOR_RGB(GREEN)
spiwriteReg32(hspi, 0x300004, 0x26000007); /// MEMORY CLEAR(1, 1, 1) clear screen
spiwriteReg32(hspi, 0x300008, 0x00000000); /// DISPLAY() display the image
spiwriteReg8(hspi, 0x302054, 0x02); /// wr8(REG_DLSWAP, DLSWAP_FRAME);//display list swap
/* Enable backlight of display panel */
spiwriteReg16(hspi, 0x302098, 0xffff);
spiwriteReg16(hspi, 0x30209C, 0xffff);
spiwriteReg8(hspi, 0x302070, 0x02); //11 REG_PCLK wr16(REG_PCLK, 2);
while (true) {} // This to check Initilization is sending green to Screen First.
}
But only showing a black screen so far.
I would need some sort of help in order to adjust this Program. It could be some details I need to update or correct.
Thanks in advance.
D. Strauss
-
Hi Dhionny,
While we don't perform full code reviews, I can offer some general suggestions regarding the issue based on a brief overview of your code.
It seems that your spisnData24() function is sending 4 bytes total instead of 3. spi->transfer((data2 >> 16) & 0xFF) appears to called twice in this function. Please try correcting this function to see if it fixes the issue.
0 -
Hello, and thank you so much. Yes, I saw it. I will proceed to take this into account as soon as possible. Thank you. I will try it again for Early Next week. Thank you so much. Appreciate it. Very best regards. Dhionny Strauss
0 -
0
Please sign in to leave a comment.
Comments
3 comments