NHD-2.4-240320CF-BSXV-F only showing white screen
Hello,
I have a NHD-2.4-240320CF-BSXV-F display and I'm trying to program it using a Teensy 4.0 platform. This MCU is programmable using the arduino IDE and I'm using the example code that is given on the support page about this (https://support.newhavendisplay.com/hc/en-us/articles/4413936999063-NHD-2-4-240320CF-BSXV-F-with-Arduino) with the nececary changes to work for my MCU. Specifially, Teensy doesn't have the PORTD functions that an Arduino Uno has, so I changed those to digitalWrite() functions and I've also changed the pin numbers to match the ones that I'm using. When I run this code, the screen remains showing only white background.
Could you give me any pointers about what I might be doing wrong or any possible issues that I might have encountered and not noticed?
Here is the code that I'm using:
/*
/Program for writing to NHD-2.4-240320CF-BSXV-F with ST7789S controller with serial Interface.
/This code is written for the Arduino Uno using Serial Interface.
/
/Newhaven Display invests time and resources providing this open source code,
/Please support Newhaven Display by purchasing products from Newhaven Display!
* Copyright (c) 2020 Alee Shah - Newhaven Display International, Inc.
*
* This code is provided as an example only and without any warranty by Newhaven Display.
* Newhaven Display accepts no responsibility for any issues resulting from its use.
* The developer on the final application incorporating any parts of this
* sample code is responsible for ensuring its safe and correct operation
* and for any consequences resulting from its use.
* See the GNU General Public License for more details.
*
* 5V voltage regulator on Arduino Uno has been replaced with a 3.3V regulator to provide 3.3V logic
*
*/
/****************************************************
* PINOUT: Teensy 4.0 -> 2.4" TFT *
*****************************************************/
#define SDA 11 //MOSI signal connected to Teensy 4.0 pin 11
#define SCL 13 // SCL signal connected to Teensy 4.0 pin 13
#define DC 8 // DC signal connected to Teensy 4.0 pin 8
#define CS 10 // CS signal connected to Teensy 4.0 pin 10
#define RST 9 // RES signal connected to Teensy 4.0 pin 9
#define IM0 14 // IM0 signal connected to Teensy 4.0 pin 14
#define IM1 15 // IM1 signal connected to Teensy 4.0 pin 15
unsigned char mode = 4; // 3 = 3-Wire Serial // 4 = 4-Wire Serial
/****************************************************
* Function Commands *
******************************************************
** IM0 & IM1 bits set within function *
*****************************************************/
void comm_out(unsigned char c)
{
switch(mode){
case 3:
digitalWrite(IM0, HIGH); //IM0 = 1
digitalWrite(IM1, LOW); //IM1 = 0
digitalWrite(SDA, HIGH); //MOSI = 1 for D/C Bit
digitalWrite(SCL, LOW); //SCL = 0
digitalWrite(SCL, HIGH); //SCL = 1
digitalWrite(SCL, LOW); //SCL = 0
for (int i=0;i<8;i++)
{
if((c & 0x80)== 0x80)
digitalWrite(SDA, HIGH); //MOSI = 1
else
digitalWrite(SDA, LOW); //MOSI = 0
c = (c<<1);
digitalWrite(SCL, LOW); //SCL = 0
digitalWrite(SCL, HIGH); //SCL = 1
digitalWrite(SCL, LOW); //SCL = 0
}
break;
case 4:
digitalWrite(IM0, HIGH); //IM0 = 1
digitalWrite(IM1, LOW); //IM1 = 0
digitalWrite(DC, LOW); //D/C = 0
for (int i=0;i<8;i++)
{
if((c & 0x80)== 0x80)
digitalWrite(SDA, HIGH); //MOSI = 1
else
digitalWrite(SDA, LOW); //MOSI = 0
c = (c<<1);
digitalWrite(SCL, LOW); //SCL = 0
digitalWrite(SCL, HIGH); //SCL = 1
digitalWrite(SCL, LOW); //SCL = 0
}
break;
}
}
void data_out(unsigned char d)
{
switch(mode){
case 3:
digitalWrite(IM0, HIGH); //IM0 = 1
digitalWrite(IM1, LOW); //IM1 = 0
digitalWrite(SDA, HIGH); //MOSI = 1 for D/C Bit
digitalWrite(SCL, LOW); //SCL = 0
digitalWrite(SCL, HIGH); //SCL = 1
digitalWrite(SCL, LOW); //SCL = 0
for (int i=0;i<8;i++)
{
if((d & 0x80)== 0x80)
digitalWrite(SDA, HIGH); //MOSI = 1
else
digitalWrite(SDA, LOW); //MOSI = 0
d = (d<<1);
digitalWrite(SCL, LOW); //SCL = 0
digitalWrite(SCL, HIGH); //SCL = 1
digitalWrite(SCL, LOW); //SCL = 0
}
break;
case 4:
digitalWrite(IM0, HIGH); //IM0 = 1
digitalWrite(IM1, LOW); //IM1 = 0
digitalWrite(DC, HIGH); //D/C = 1
for (int i=0;i<8;i++)
{
if((d & 0x80)== 0x80)
digitalWrite(SDA, HIGH); //MOSI = 1
else
digitalWrite(SDA, LOW); //MOSI = 0
d = (d<<1);
digitalWrite(SCL, LOW); //SCL = 0
digitalWrite(SCL, HIGH); //SCL = 1
digitalWrite(SCL, LOW); //SCL = 0
}
break;
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Window Set Function
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void window_set(unsigned s_x, unsigned e_x, unsigned s_y, unsigned e_y)
{
comm_out(0x2a); //SET column address
digitalWrite(RES, HIGH);
data_out((s_x)>>8); //SET start column address
data_out(s_x);
data_out((e_x)>>8); //SET end column address
data_out(e_x);
comm_out(0x2b); //SET page address
digitalWrite(RES, HIGH);
data_out((s_y)>>8); //SET start page address
data_out(s_y);
data_out((e_y)>>8); //SET end page address
data_out(e_y);
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Fill Screen (All Red -> All Green -> All Blue) Function
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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);
}
for(i=0;i<38400;i++) //fill screen with red pixels
{
data_out(0xF8);
data_out(0x00);
data_out(0xF8);
data_out(0x00);
}
delay(300);
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Fill Screen (Red, Green & Blue Lines) Function
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void disp2()
{
{
unsigned int i;
comm_out(0x2C); //command to begin writing to frame memory
for(i=0;i<12800;i++) //fill screen with blue pixels
{
data_out(0x00); //R
data_out(0x1F); //R
data_out(0x00); //R
data_out(0x1F); //R
data_out(0xF8); //B
data_out(0x00); //B
data_out(0xF8); //B
data_out(0x00); //B
data_out(0x07); //G
data_out(0xE0); //G
data_out(0x07); //G
data_out(0xE0); //G
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Border and Fill Function
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Border_Fill()
{
unsigned int i,j;
window_set(0,239,0,0);
comm_out(0x2C);
digitalWrite(RES, HIGH);
for(i=0;i<240;i++) //Bottom White Border
{
for (j=0;j<1;j++)
{
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
}
}
delay(100);
window_set(0,0,0,319);
comm_out(0x2C);
digitalWrite(RES, HIGH);
for(i=0;i<1;i++) //Left White Border
{
for (j=0;j<320;j++)
{
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
}
}
delay(100);
window_set(0,239,319,319);
comm_out(0x2C);
digitalWrite(RES, HIGH);
for(i=0;i<240;i++) //Top White Border
{
for (j=0;j<1;j++)
{
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
}
}
delay(100);
window_set(239,239,0,319);
comm_out(0x2C);
digitalWrite(RES, HIGH);
for(i=0;i<1;i++) //Right White Border
{
for (j=0;j<240;j++)
{
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
}
}
delay(100);
window_set(1,238,1,318);
comm_out(0x2C);
digitalWrite(RES, HIGH);
for(i=0;i<238;i++) //fill inside with Black Pixels
{
for (j=0;j<318;j++)
{
data_out(0x00);
data_out(0x00);
data_out(0x00);
data_out(0x00);
}
}
delay(250);
window_set(0,239,0,319);
comm_out(0x2C);
digitalWrite(RES, HIGH);
for(i=0;i<38400;i++) //fill screen with White Pixels
{
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Fill Screen (All Black) Function
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void disp3()
{
unsigned int i;
window_set(0,239,0,319);
comm_out(0x2C); //command to begin writing to frame memory
for(i=0;i<38400;i++) //fill screen with black pixels
{
data_out(0x00);
data_out(0x00);
data_out(0x00);
data_out(0x00);
}
}
/****************************************************
* Initialization and Setup Routine *
*****************************************************/
void setup()
{
// DDRB = 0xFF; //Enable All outputs on PortB
// PORTB = 0x00;
// DDRC = 0xFF; //Enable All outputs on PortC
// PORTC = 0x00;
// DDRD = 0xFF; //Enable All outputs on PortD
// PORTD = 0x00;
pinMode(MOSI, OUTPUT); //Enable Outputs for all used pins
pinMode(SCL, OUTPUT);
pinMode(DC, OUTPUT);
pinMode(CS, OUTPUT);
pinMode(RST, OUTPUT);
pinMode(IM0, OUTPUT);
pinMode(IM1, OUTPUT);
digitalWrite(CS, LOW);
digitalWrite(RES, LOW);
delay(250);
digitalWrite(RES, HIGH);
delay(250);
comm_out(0x28); //display off
comm_out(0x11); //exit SLEEP mode
delay(100);
comm_out(0x36); //MADCTL: memory data access control
data_out(0x88);
comm_out(0x3A); //COLMOD: Interface Pixel format *** 65K-colors in 16bit/pixel (5-6-5) format when using 16-bit interface to allow 1-byte per pixel
data_out(0x55);
comm_out(0xB2); //PORCTRK: Porch setting
data_out(0x0C);
data_out(0x0C);
data_out(0x00);
data_out(0x33);
data_out(0x33);
comm_out(0xB7); //GCTRL: Gate Control
data_out(0x35);
comm_out(0xBB); //VCOMS: VCOM setting
data_out(0x2B);
comm_out(0xC0); //LCMCTRL: LCM Control
data_out(0x2C);
comm_out(0xC2); //VDVVRHEN: VDV and VRH Command Enable
data_out(0x01);
data_out(0xFF);
comm_out(0xC3); //VRHS: VRH Set
data_out(0x11);
comm_out(0xC4); //VDVS: VDV Set
data_out(0x20);
comm_out(0xC6); //FRCTRL2: Frame Rate control in normal mode
data_out(0x0F);
comm_out(0xD0); //PWCTRL1: Power Control 1
data_out(0xA4);
data_out(0xA1);
comm_out(0xE0); //PVGAMCTRL: Positive Voltage Gamma control
data_out(0xD0);
data_out(0x00);
data_out(0x05);
data_out(0x0E);
data_out(0x15);
data_out(0x0D);
data_out(0x37);
data_out(0x43);
data_out(0x47);
data_out(0x09);
data_out(0x15);
data_out(0x12);
data_out(0x16);
data_out(0x19);
comm_out(0xE1); //NVGAMCTRL: Negative Voltage Gamma control
data_out(0xD0);
data_out(0x00);
data_out(0x05);
data_out(0x0D);
data_out(0x0C);
data_out(0x06);
data_out(0x2D);
data_out(0x44);
data_out(0x40);
data_out(0x0E);
data_out(0x1C);
data_out(0x18);
data_out(0x16);
data_out(0x19);
comm_out(0x2A); //X address set
data_out(0x00);
data_out(0x00);
data_out(0x00);
data_out(0xEF);
comm_out(0x2B); //Y address set
data_out(0x00);
data_out(0x00);
data_out(0x01);
data_out(0x3F);
delay(10);
comm_out(0x29); //display ON
delay(10);
}
/*****************************************************
* Loop Function, to run repeatedly *
*****************************************************/
void loop()
{
disp();
delay(500);
disp2();
delay(500);
Border_Fill();
delay(500);
}
-
I just noticed that on the code that I uploaded I had a missmatch on the naming of the Reset pin. In some places it's named RST and in others RES. It doesn't solve the issue, but this code doesn't run like this, so just change the deffinition name to RES.
0 -
Hi,
Are you using a SPI library to work with the teensy?
Also, I noticed that your IM settings are incorrect in your 4-Wire case statement for command and data functions:
case 4:
digitalWrite(IM0, HIGH); //IM0 = 1
digitalWrite(IM1, LOW); //IM1 = 0
digitalWrite(DC, LOW); //D/C = 00
Please sign in to leave a comment.
Comments
2 comments