NHD-7.0-800480FT-CSXV-CTP - communication not responding arduino zero
Hello, I am currently using the NHD-7.0-800480FT-CSXV-CTP screen to establish spi communication between my screen and my arduino zero board, so I have created my own library using the FT81x Series Programmers Guide. But currently when I launch the communication towards my impossible screen I find myself with a black screen without being able to write information on this one, and I obtain a problem of addressing like this:
Start of screen initialisation
SPI initialised
Send the CLKEXT command
Activate screen
Value read from address 302000: 42
ID read: 42
Error: ID incorrect
yet in the FT81x doc the 0x42 does not exist could someone help me to communicate with my screen? thank you
NHD7Display.cpp
#include "NHD7Display.h"
// Function to send a host command
void NHD7Display::hostCommand(uint8_t command) {
digitalWrite(CS_PIN, LOW);
SPI.transfer(command);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(CS_PIN, HIGH);
}
// Function to write 8-bit value to FT81x register
void NHD7Display::wr8(uint32_t addr, uint8_t value) {
digitalWrite(CS_PIN, LOW);
SPI.transfer((addr >> 16) & 0x3F);
SPI.transfer((addr >> 8) & 0xFF);
SPI.transfer(addr & 0xFF);
SPI.transfer(value);
digitalWrite(CS_PIN, HIGH);
}
// Function to write 16-bit value to FT81x register
void NHD7Display::wr16(uint32_t addr, uint16_t value) {
digitalWrite(CS_PIN, LOW);
SPI.transfer((addr >> 16) & 0x3F);
SPI.transfer((addr >> 8) & 0xFF);
SPI.transfer(addr & 0xFF);
SPI.transfer(value & 0xFF);
SPI.transfer((value >> 8) & 0xFF);
digitalWrite(CS_PIN, HIGH);
}
// Function to write 32-bit value to FT81x register
void NHD7Display::wr32(uint32_t addr, uint32_t value) {
digitalWrite(CS_PIN, LOW);
SPI.transfer((addr >> 16) & 0x3F);
SPI.transfer((addr >> 8) & 0xFF);
SPI.transfer(addr & 0xFF);
SPI.transfer(value & 0xFF);
SPI.transfer((value >> 8) & 0xFF);
SPI.transfer((value >> 16) & 0xFF);
SPI.transfer((value >> 24) & 0xFF);
digitalWrite(CS_PIN, HIGH);
}
// Function to read 8-bit value from FT81x register
uint8_t NHD7Display::rd8(uint32_t addr) {
digitalWrite(CS_PIN, LOW);
SPI.transfer((addr >> 16) & 0x3F | 0x80); // Commande de lecture
SPI.transfer((addr >> 8) & 0xFF);
SPI.transfer(addr & 0xFF);
uint8_t value = SPI.transfer(0x00); // Recevoir la valeur
digitalWrite(CS_PIN, HIGH);
Serial.print("Valeur lue de l'adresse ");
Serial.print(addr, HEX);
Serial.print(" : ");
Serial.println(value, HEX);
return value;
}
// Function to delay
void NHD7Display::delayMS(unsigned long ms) {
delay(ms);
}
// Function to initialize the display
void NHD7Display::begin() {
Serial.begin(115200);
Serial.println("Début de l'initialisation de l'écran");
pinMode(CS_PIN, OUTPUT);
pinMode(PD_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
digitalWrite(PD_PIN, LOW);
delayMS(20);
digitalWrite(PD_PIN, HIGH);
delayMS(20);
SPI.begin();
Serial.println("SPI initialisé");
// Send host command to set external clock
Serial.println("Envoi de la commande CLKEXT");
hostCommand(0x44); // CLKEXT
// Activate the FT81X
Serial.println("Activation de l'écran");
hostCommand(0x00); // ACTIVE
// Wait for the FT81X to initialize and read the ID once
delayMS(300); // Attendre un peu pour l'initialisation
uint8_t id = rd8(REG_ID); // Lire l'ID
Serial.print("ID lu : ");
Serial.println(id, HEX);
// Check the ID register
if (id != 0x7C) {
Serial.println("Erreur : ID incorrect");
while (true); // Boucle infinie en cas d'erreur
}
Serial.println("ID vérifié avec succès");
// Configure the display registers
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, 1);
wr16(REG_HSIZE, 800);
wr16(REG_VSIZE, 480);
// Set the initial display list
wr32(RAM_DL + 0, CLEAR_COLOR_RGB(0, 0, 0));
wr32(RAM_DL + 4, CLEAR(1, 1, 1));
wr32(RAM_DL + 8, DISPLAY());
// Swap display lists
wr8(REG_DLSWAP, 0x02);
// Enable the backlight
wr8(REG_GPIO_DIR, rd8(REG_GPIO_DIR) | 0x80);
wr8(REG_GPIO, rd8(REG_GPIO) | 0x80);
// Set the pixel clock
wr8(REG_PCLK, 5);
}
// Function to display "Hello World"
void NHD7Display::displayHelloWorld() {
// Start a new display list
wr32(RAM_DL + 0, CMD_DLSTART);
wr32(RAM_DL + 4, CLEAR_COLOR_RGB(0, 0, 0));
wr32(RAM_DL + 8, CLEAR(1, 1, 1));
wr32(RAM_DL + 12, CMD_TEXT);
wr32(RAM_DL + 16, 400); // x coordinate
wr32(RAM_DL + 20, 240); // y coordinate
wr32(RAM_DL + 24, 31); // font
wr32(RAM_DL + 28, 0); // options
wr32(RAM_DL + 32, 'H');
wr32(RAM_DL + 36, 'e');
wr32(RAM_DL + 40, 'l');
wr32(RAM_DL + 44, 'l');
wr32(RAM_DL + 48, 'o');
wr32(RAM_DL + 52, ' ');
wr32(RAM_DL + 56, 'W');
wr32(RAM_DL + 60, 'o');
wr32(RAM_DL + 64, 'r');
wr32(RAM_DL + 68, 'l');
wr32(RAM_DL + 72, 'd');
wr32(RAM_DL + 76, 0);
// End the display list
wr32(RAM_DL + 80, DISPLAY());
wr32(RAM_DL + 84, CMD_SWAP);
// Swap display lists
wr8(REG_DLSWAP, 0x02);
}
.h
#ifndef NHD7DISPLAY_H
#define NHD7DISPLAY_H
#include <SPI.h>
// Pin definitions
#define MOSI_PIN PB10
#define MISO_PIN PA12
#define SCK_PIN PB11
#define CS_PIN 10
#define PD_PIN 5
// FT81x register addresses
#define REG_ID 0x302000
#define REG_HCYCLE 0x30202C
#define REG_HOFFSET 0x302030
#define REG_HSYNC0 0x302034
#define REG_HSYNC1 0x302038
#define REG_VCYCLE 0x30203C
#define REG_VOFFSET 0x302040
#define REG_VSYNC0 0x302044
#define REG_VSYNC1 0x302048
#define REG_SWIZZLE 0x30204C
#define REG_PCLK_POL 0x302050
#define REG_CSPREAD 0x302054
#define REG_HSIZE 0x302058
#define REG_VSIZE 0x30205C
#define REG_GPIO_DIR 0x302090
#define REG_GPIO 0x302094
#define REG_PCLK 0x302070
#define REG_DLSWAP 0x302068
#define RAM_DL 0x300000
// Display list commands
#define CLEAR_COLOR_RGB(r, g, b) (0x02000000UL | ((r) << 16) | ((g) << 8) | (b))
#define CLEAR(c, s, t) (0x26000000UL | (((c) & 1) << 2) | (((s) & 1) << 1) | ((t) & 1))
#define DISPLAY() 0x00000000UL
#define CMD_DLSTART 0xFFFFFF00UL
#define CMD_SWAP 0xFFFFFF01UL
#define CMD_TEXT 0x0FFFFFFCUL
class NHD7Display {
public:
void begin();
void displayHelloWorld();
private:
void hostCommand(uint8_t command);
void wr8(uint32_t addr, uint8_t value);
void wr16(uint32_t addr, uint16_t value);
void wr32(uint32_t addr, uint32_t value);
uint8_t rd8(uint32_t addr);
void delayMS(unsigned long ms);
};
#endif
-
Hi,
Here are some easy and quick trouble-shooting steps.
-
Verify SPI Settings: Double-check that SPI Mode 0 is selected and that the clock polarity and phase are set correctly.
-
Inspect Connections: Ensure that all physical connections between the Arduino and the display are secure and correct, especially the SPI, power, and control lines.
-
Validate Command Sequences: Confirm the host command sequences, including
CLKEXT
,ACTIVE
, and others, are sent correctly and in the proper order. -
Use Logic Analyzer: Consider using a logic analyzer to monitor SPI traffic and confirm that the data and addresses sent/received are correct.
-
Review Power-Up Sequence: Ensure the correct sequence of powering up and resetting the device as described in the datasheet.
-
Test Alternate Configurations: If possible, test with another known working setup or example code to rule out hardware faults.
The root cause of the problem with the FT81x display is most likely incorrect SPI communication or initialization sequence. Specifically, the SPI mode may be improperly configured (it must be Mode 0), or the commands to initialize the device might not be sent in the correct order, leading to an incorrect chip ID readback of
0x42
instead of the expected0x7C
. It's crucial to verify the SPI settings, command sequence, and proper wiring connections to ensure correct communication with the display.Please let us know what you find.
0 -
Please sign in to leave a comment.
Comments
1 comment