NHD-3.5-320240FT-CSXP-T - Interface with Custom Board
Hello,
We are designing a custom board for one of our products. The custom board is run by an NXP LPC55S69 Microcontroller as the host with many interfaces. We have purchased the NHD-3.5-320240FT-CSXP-T TFT Display modules for our display.
Using the FT81x Programmers Guide and the NHD-3.5-320240FT-CSXP-T datasheet, We created an simple C code to begin the initiation of the display with the host microcontroller. But, there is no output or backlight switching on the display when the code is executed.
We kindly request you to peruse the code attached below and let us know if we have missed any initiations or definitions for the display to work. We have gone through the programmers guide, the github links and the datasheet but we can't seem to find what is the issue in our code. Any references to a C Code for the display interface would also be much helpful as we are not using Arduino for our application.
#include "fsl_spi.h"
#include "fsl_power.h"
#include "board.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "fsl_gpio.h" // Include GPIO header
#define EXAMPLE_SPI_MASTER SPI4
#define EXAMPLE_SPI_MASTER_IRQ FLEXCOMM4_IRQn
#define EXAMPLE_SPI_MASTER_CLK_SRC kCLOCK_Flexcomm4
#define EXAMPLE_SPI_MASTER_CLK_FREQ CLOCK_GetFlexCommClkFreq(4U)
#define EXAMPLE_SPI_SSEL 3
#define EXAMPLE_SPI_SPOL kSPI_SpolActiveAllLow
#define BUFFER_SIZE (128)
// Definitions for display initialization commands
#define CMD_ACTIVE 0x00
#define CMD_STANDBY 0x41
#define CMD_SLEEP 0x42
#define CMD_PWRDOWN 0x50
#define CMD_CLKINT 0x48
#define CMD_CLKEXT 0x44
#define CMD_CLK48M 0x62
#define CMD_CLK36M 0x61
#define CMD_CORERESET 0x68
#define CMD_APPEND 0xFFFFFF1E
#define CMD_BGCOLOR 0xFFFFFF09
#define CMD_BUTTON 0xFFFFFF0D
#define CMD_CALIBRATE 0xFFFFFF15 // 4294967061UL
#define CMD_CLOCK 0xFFFFFF14
#define CMD_COLDSTART 0xFFFFFF32
#define CMD_CRC 0xFFFFFF18
#define CMD_DIAL 0xFFFFFF2D
#define CMD_DLSTART 0xFFFFFF00
#define CMD_FGCOLOR 0xFFFFFF0A
#define CMD_GAUGE 0xFFFFFF13
#define CMD_GETMATRIX 0xFFFFFF33
#define CMD_GETPROPS 0xFFFFFF25
#define CMD_GETPTR 0xFFFFFF23
#define CMD_GRADCOLOR 0xFFFFFF34
#define CMD_GRADIENT 0xFFFFFF0B
#define CMD_INFLATE 0xFFFFFF22
#define CMD_INFLATE2 0xFFFFFF50
#define CMD_INTERRUPT 0xFFFFFF02
#define CMD_KEYS 0xFFFFFF0E
#define CMD_LOADIDENTITY 0xFFFFFF26
#define CMD_LOADIMAGE 0xFFFFFF24
#define CMD_LOGO 0xFFFFFF31
#define CMD_MEDIAFIFO 0xFFFFFF39
#define CMD_MEMCPY 0xFFFFFF1D
#define CMD_MEMCRC 0xFFFFFF18
#define CMD_MEMSET 0xFFFFFF1B
#define CMD_MEMWRITE 0xFFFFFF1A
#define CMD_MEMZERO 0xFFFFFF1C
#define CMD_NUMBER 0xFFFFFF2E
#define CMD_PLAYVIDEO 0xFFFFFF3A
#define CMD_PROGRESS 0xFFFFFF0F
#define CMD_REGREAD 0xFFFFFF19
#define CMD_ROTATE 0xFFFFFF29
#define CMD_SCALE 0xFFFFFF28
#define CMD_SCREENSAVER 0xFFFFFF2F
#define CMD_SCROLLBAR 0xFFFFFF11
#define CMD_SETBITMAP 0xFFFFFF43
#define CMD_SETFONT 0xFFFFFF2B
#define CMD_SETMATRIX 0xFFFFFF2A
#define CMD_SETROTATE 0xFFFFFF36
#define CMD_SKETCH 0xFFFFFF30
#define CMD_SLIDER 0xFFFFFF10
#define CMD_SNAPSHOT 0xFFFFFF1F
#define CMD_SPINNER 0xFFFFFF16
#define CMD_STOP 0xFFFFFF17
#define CMD_SWAP 0xFFFFFF01
#define CMD_TEXT 0xFFFFFF0C
#define CMD_TOGGLE 0xFFFFFF12
#define CMD_TRACK 0xFFFFFF2C
#define CMD_TRANSLATE 0xFFFFFF27
#define CMD_VIDEOFRAME 0xFFFFFF41
#define REG_CSPREAD 0x68
#define REG_DITHER 0x60
#define REG_DLSWAP 0x54
#define REG_HCYCLE 0x2C
#define REG_HOFFSET 0x30
#define REG_HSIZE 0x34
#define REG_HSYNC0 0x38
#define REG_HSYNC1 0x3C
#define REG_OUTBITS 0x5C
#define REG_PCLK 0x70
#define REG_PCLK_POL 0x6C
#define REG_PLAY 0x8C
#define REG_PLAYBACK_FORMAT 0xC4
#define REG_PLAYBACK_FREQ 0xC0
#define REG_PLAYBACK_LENGTH 0xB8
#define REG_PLAYBACK_LOOP 0xC8
#define REG_PLAYBACK_PLAY 0xCC
#define REG_PLAYBACK_READPTR 0xBC
#define REG_PLAYBACK_START 0xB4
#define REG_PWM_DUTY 0xD4
#define REG_ROTATE 0x58
#define REG_SOUND 0x88
#define REG_SWIZZLE 0x64
#define REG_TAG 0x7C
#define REG_TAG_X 0x74
#define REG_TAG_Y 0x78
#define REG_VCYCLE 0x40
#define REG_VOFFSET 0x44
#define REG_VOL_SOUND 0x84
#define REG_VOL_PB 0x80
#define REG_VSYNC0 0x4C
#define REG_VSYNC1 0x50
#define REG_VSIZE 0x48
#define CMD_VIDEOSTART 0xFFFFFF40
#define CMD_ROMFONT 0xFFFFFF3F
#define REG_TOUCH_CONFIG 0x168
#define REG_TOUCH_TRANSFORM_A 0x150
#define REG_TOUCH_TRANSFORM_B 0x154
#define REG_TOUCH_TRANSFORM_C 0x158
#define REG_TOUCH_TRANSFORM_D 0x15C
#define REG_TOUCH_TRANSFORM_E 0x160
#define REG_TOUCH_TRANSFORM_F 0x164
#define REG_TOUCH_ADC_MODE 0x108
#define REG_TOUCH_CHARGE 0x10C
#define REG_TOUCH_DIRECT_XY 0x18C
#define REG_TOUCH_DIRECT_Z1Z2 0x190
#define REG_TOUCH_MODE 0x104
#define REG_TOUCH_OVERSAMPLE 0x114
#define REG_TOUCH_RAW_XY 0x11C
#define REG_TOUCH_RZ 0x120
#define REG_TOUCH_RZTHRESH 0x118
#define REG_TOUCH_SCREEN_XY 0x124
#define REG_TOUCH_SETTLE 0x110
#define REG_TOUCH_TAG 0x12C
#define REG_TOUCH_TAG_XY 0x128
/*Flash related registers*/
#define REG_FLASH_STATUS 0x5F0
#define REG_FLASH_SIZE 0x7024
/*Miscellaneous Registers - FT81x Series Programmers Guide Section 3.6 - Document inspecific about base address
Addresses assumed to be defined as offsets from the base address called RAM_REG and located at 0x302000*/
#define REG_CPU_RESET 0x20
#define CMD_PWM_DUTY 0xD4
#define REG_PWM_HZ 0xD0
#define REG_INT_MASK 0xB0
#define REG_INT_EN 0xAC
#define REG_INT_FLAGS 0xA8
#define REG_GPIO 0x94
#define REG_GPIO_DIR 0x90
#define REG_GPIOX 0x9C
#define REG_GPIOX_DIR 0x98
#define REG_FREQUENCY 0x0C
#define REG_CLOCK 0x08
#define REG_FRAMES 0x04
#define REG_ID 0x00
#define REG_TRIM 0x10256C
#define REG_SPI_WIDTH 0x180
#define REG_CHIP_ID 0xC0000 // Temporary Chip ID location in RAMG
#define RAM_G 0x00000
#define RAM_G_WORKING 0x0FF000 // This address may be used as the start of a 4K block to be used for copying data
#define RAM_DL 0x300000
#define RAM_REG 0x302000
#define RAM_CMD 0x308000
#define RAM_ERR_REPORT 0x309800 // max 128 bytes null terminated string
#define RAM_FLASH 0x800000
#define RAM_FLASH_POSTBLOB 0x801000
/*Flash Statuse*/
#define FLASH_STATUS_INIT 0UL
#define FLASH_STATUS_DETACHED 1UL
#define FLASH_STATUS_BASIC 2UL
#define FLASH_STATUS_FULL 3UL
/* Chip ID address for FT81x */
#define FT81X_CHIP_ID_ADDR 0xC0000
#define DISPLAY_POWERDOWN_PIN 31
#define FT81X_BACKLIGHT_PIN 28
/* SPI settings ... */
uint32_t ReadChipID(void) {
uint8_t chipIDBytes[4];
spi_transfer_t xfer = {0};
// Set CS to low to select the device
GPIO_PinWrite(GPIO, 1, EXAMPLE_SPI_SSEL, 0); // Assert CS line
// Send command to read chip ID
xfer.txData = 0x12; // Command to read chip ID
xfer.rxData = chipIDBytes;
xfer.dataSize = sizeof(chipIDBytes);
xfer.configFlags = kSPI_FrameAssert;
SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
// Set CS to high to deselect the device
GPIO_PinWrite(GPIO, 1, EXAMPLE_SPI_SSEL, 1); // Deassert CS line
// Convert bytes to a 32-bit chip ID
uint32_t chipID = (uint32_t)(chipIDBytes[3] << 24) |
(uint32_t)(chipIDBytes[2] << 16) |
(uint32_t)(chipIDBytes[1] << 8) |
(uint32_t)chipIDBytes[0];
return chipID;
}
int main(void) {
spi_master_config_t userConfig = {0};
uint32_t srcFreq = 0;
spi_transfer_t xfer = {0};
/* Set BOD VBAT level to 1.65V */
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
/* Attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* Attach 12 MHz clock to SPI3 */
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4);
/* Reset FLEXCOMM for SPI */
RESET_PeripheralReset(kFC4_RST_SHIFT_RSTn);
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
PRINTF("\n\rMaster Start...\n\r");
/* Initialize SPI master settings */
SPI_MasterGetDefaultConfig(&userConfig);
srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ;
userConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL;
userConfig.sselPol = (spi_spol_t)EXAMPLE_SPI_SPOL;
SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq);
/* Set up the GPIO for slave select line (CS) */
gpio_pin_config_t cs_config = {
kGPIO_DigitalOutput, // Set as digital output
1 // Initialize as high (deselected)
};
GPIO_PinInit(GPIO, 1, EXAMPLE_SPI_SSEL, &cs_config); // Initialize CS pin
/* Set up the GPIO for backlight pin */
gpio_pin_config_t backlight_config = {
kGPIO_DigitalOutput, // Set as digital output
1 // Initialize as high (backlight enabled)
};
GPIO_PinInit(GPIO, 1, FT81X_BACKLIGHT_PIN, &backlight_config); // Initialize backlight pin
/* Set the power-down pin high to take the display out of power-down mode */
GPIO_PinWrite(GPIO, 1, DISPLAY_POWERDOWN_PIN, 1);
/* Read Chip ID */
uint32_t chipID = ReadChipID();
if (chipID == 0x012) {
PRINTF("Chip ID is correct: 0x%08X\n\r", chipID);
/* Send the display initialization commands */
uint8_t displayInitCommands[] = {
CMD_CLKEXT, 0x44, 0x00, 0x00,
CMD_ACTIVE, 0x00, 0x00, 0x00,
// ... Other commands ...
CMD_BGCOLOR, 0x00, 0x00, 0x00, // Set background color to black
CMD_PWM_DUTY, 0x80, // Set backlight brightness (0x80 is an example value)
// ... Other commands ...
};
// Select slave device (CS low)
GPIO_PinWrite(GPIO, 1, EXAMPLE_SPI_SSEL, 0);
xfer.txData = displayInitCommands;
xfer.rxData = NULL; // No need to receive data
xfer.dataSize = sizeof(displayInitCommands);
xfer.configFlags = kSPI_FrameAssert;
SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
// Deselect slave device (CS high)
GPIO_PinWrite(GPIO, 1, EXAMPLE_SPI_SSEL, 1);
// Turn off backlight
GPIO_PinWrite(GPIO, 1, FT81X_BACKLIGHT_PIN, 0);
}
else {
PRINTF("Incorrect Chip ID: 0x%08X\n\r", chipID);
}
while (1) {
// Your application code
}
}
-
Hi Cherkupally,
There are a few lines you should add to your initialization commands. First is the PWM HZ. Although the default value is 250, you need to change this to between 800Hz and 10kHz for this display. Please see here for more info - https://support.newhavendisplay.com/hc/en-us/articles/8580473151767-08-31-22-EVE2-Backlight-Driver-IC-Change
Next, you will need to add the timing characteristics shown in the below image.
0
Please sign in to leave a comment.
Comments
1 comment