I'm stuck in an extremely painful situation where sometimes everything displays correctly when my device powers up and other times, actually most of the time, only the backlight seems to work. I'm using Rudolph's library as well as the EVE library as a reference and can't seem to figure out what I'm missing. I'm using qspi which I don't think is an issue because sometimes it works fine.
I have attached my init method, can anyone possibly see what could cause it to display intermittently?
Kindest regards.
void TFT_qspi_init()
{
HAL_GPIO_WritePin(MCU_DISP_RST_GPIO_Port, MCU_DISP_RST_Pin, GPIO_PIN_RESET);
HAL_Delay(21); /* minimum time for power-down is 5ms */
HAL_GPIO_WritePin(MCU_DISP_RST_GPIO_Port, MCU_DISP_RST_Pin, GPIO_PIN_SET);
HAL_Delay(21); /* minimum time to allow from rising PD_N to first access is 20ms */
//Reset the device
TFT_sendCmd(EVE_RST_PULSE, 0x00);
HAL_Delay(21);
//External Crystal
TFT_sendCmd(CMD_CLKEXT, 0x00);
HAL_Delay(100);
/* set clock to 72 MHz */
TFT_sendCmd(CMD_CLKSEL, 0x46);
/* start EVE */
TFT_sendCmd(CMD_ACTIVE, 0x00);
/* give EVE time to power up */
HAL_Delay(40);
/* read the ID */
uint8_t regId = TFT_readId(REG_ID);
while(regId != 0x7c)
regId = TFT_readId(REG_ID);
/* ensure CPUreset register reads 0 signaling it's ready */
uint8_t cpuState = TFT_read8(REG_CPURESET);
while ( cpuState != 0x00)
cpuState = TFT_read8(REG_CPURESET);
/* switch to QSPI */
TFT_write8(REG_SPI_WIDTH, 0x02);
if(TFT_qspi_read8(REG_SPI_WIDTH) != 0x02)
Error_Handler();
/* tell EVE that we changed the frequency to 72MHz */
TFT_qspi_write32(REG_FREQUENCY, 72000000);
/* read the frequency to verify */
if(TFT_qspi_read32(REG_FREQUENCY) != 72000000)
Error_Handler();
TFT_qspi_write8(REG_TRIM, 25);
TFT_qspi_write16(REG_HSIZE, DispWidth); /* 800 */
TFT_qspi_write16(REG_VSIZE, DispHeight); /* 480 */
TFT_qspi_write16(REG_HCYCLE, DispHCycle); /* 816 */
TFT_qspi_write16(REG_HOFFSET, DispHOffset); /* 8 */
TFT_qspi_write16(REG_HSYNC0, DispHSync0); /* 0 */
TFT_qspi_write16(REG_HSYNC1, DispHSync1); /* 4 */
TFT_qspi_write16(REG_VCYCLE, DispVCycle); /* 496 */
TFT_qspi_write16(REG_VOFFSET, DispVOffset); /* 8 */
TFT_qspi_write16(REG_VSYNC0, DispVSync0); /* 0 */
TFT_qspi_write16(REG_VSYNC1, DispVSync1); /* 4 */
TFT_qspi_write8(REG_PCLK, DispPCLK); /* 1 */
TFT_qspi_write8(REG_SWIZZLE, DispSwizzle); /* 0 */
TFT_qspi_write8(REG_PCLK_POL, DispPCLKPol); /* 1 */
TFT_qspi_write16(REG_CSPREAD, DispCSpread); /* 0 */
TFT_qspi_write16(REG_DITHER, DispDither); /* 0 */
TFT_qspi_write16(REG_PCLK_FREQ, DispPLCLKFREQ); /* 0xD14 */
TFT_qspi_write8(REG_PCLK_2X, DispPCLK2x); /* 0 */
TFT_qspi_write16(REG_PWM_HZ, 4000);
TFT_qspi_write8(REG_PWM_DUTY, 128);
TFT_qspi_write16(REG_GPIOX_DIR, 0xFFFF);
TFT_qspi_write16(REG_GPIOX, 0xFFFF);
/* turn off back light */
TFT_qspi_write8(REG_PWM_DUTY, 0);
while(TFT_busy()){};
TFT_qspi_cmd(REG_CMDB_WRITE, CMD_SETROTATE, 1);
/* If the status of the flash is 0 (INIT) Attach it */
if (TFT_qspi_read8(REG_FLASH_STATUS) == 0x00) {
uint32_t flashAttachCommand[] = {CMD_FLASHATTACH};
TFT_qspi_display(flashAttachCommand, 1);
}
/* Initialize the onboard flash and put in FAST mode
* Need to check the return value and not proceed if
* there is an error.
*/
if(TFT_init_flash() != E_OK)
Error_Handler();
/* turn on backlight pwm to 25% for any other module */
TFT_qspi_write8(REG_PWM_DUTY, 0x25);
uint32_t commands[] = {
CMD_DLSTART, /* start the display list */
DL_CLEAR_COLOR_RGB | 0x00000000, /* set the default clear color to white */
DL_CLEAR | CLR_COL | CLR_STN | CLR_TAG, /* clear the screen - this and the previous prevent artifacts between lists, Attributes are the color, stencil and tag buffers */
DL_BEGIN | EVE_BITMAPS,
COLOR_RGB(255, 255, 255),
VERTEX2II(DispWidth / 2 , (DispHeight / 2) - 31, 31, 'T'), // ASCII T in font 31
VERTEX2II((DispWidth / 2 ) + 26, (DispHeight / 2) - 31, 31, 'E'), // ASCII E in font 31
VERTEX2II((DispWidth / 2 ) + 50, (DispHeight / 2) - 31, 31, 'X'), // ASCII X in font 31
VERTEX2II((DispWidth / 2 ) + 76, (DispHeight / 2) - 31, 31, 'T'),
DL_END,
COLOR_RGB(160, 22, 22), // change color to red
POINT_SIZE(520), // set point size to 20 pixels in radius
DL_BEGIN | EVE_POINTS, // start drawing points
VERTEX2II((DispWidth / 2 ) - 40, (DispHeight / 2) - 10, 0, 0), // red point
DL_END,
DL_DISPLAY,
CMD_SWAP// display the image
};
TFT_qspi_display(commands, sizeof(commands) / sizeof(commands[0]));
/* turn on backlight pwm to 25% for any other module */
TFT_qspi_write8(REG_PWM_DUTY, 0x25);
HAL_Delay(2000);
}