SPI connection and initialization of NHD-C12864A1Z-FSW-FBW-HTT
Hello,
I have the display quoted on the title, and I would like to use it with an Arduino Uno (with an ATMega328).
I wrote a test program to switch on the whole display during 3 seconds and switch it off during 3 other seconds.
However, it doesn't work, and I need your help to understand why.
Here my code :
/* Pins definition
* Pin Arduino - function - Pin Newhaven screen
* P10 - SS (SPI Bus Master Slave select) chip select - P6
* P11 - MOSI (SPI Bus Master Output/Slave Input) - P2
* P12 - MISO - None
* P13 - Serial Clock MOSI - P1
*
* P9 - Reset : Operation Active LOW Reset signal - P5
* P8 - A0 - Register Select. 0: instruction; 1: data - P4
*
* 3.3V - power supply - P3
* GND - ground - P10
* 5V and resistor 1 kohm - backlight LED - P11
*/
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//sck
#define SLAVESELECT 10//ss
#define RESET 9
#define A0 8
uint8_t display_on = 0b10101111;
uint8_t display_all_points = 0b10100101;
uint8_t shutdown_all_points = 0b10100100;
uint8_t n;
/* ======================================= Functions ================================================*/
void spi_transfer(volatile uint8_t data,volatile bool instruc_or_data) // char = int_8
{
if (instruc_or_data) // instruction 0, data 1
{ digitalWrite(A0,HIGH); } // write data
else
{ digitalWrite(A0,LOW); } // write instruction
digitalWrite(SLAVESELECT,LOW); //enable device
// writing a byte to the SPI Data Register SPDR starts the SPI clock generator
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission
{
//write the data
}; // return the received byte
Serial.print("Tranfer done \n");
delay(500);
digitalWrite(SLAVESELECT,HIGH); //disable device
}
/* ======================================== SETUP ===================================================*/
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //run the UART : serial monitor
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,LOW); //enable device
digitalWrite(RESET,LOW); // reset active
delay(1000); //wait 1 second
digitalWrite(RESET,HIGH); //reset inactive
digitalWrite(SLAVESELECT,HIGH); //disable device
// We want SPCR = 01010000
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
//sample on leading edge of clk,system clock/4 rate (fastest)
SPCR = (1<<SPE)|(1<<MSTR);
spi_transfer(display_on, 0);
}
/* ======================================= LOOP =====================================================*/
void loop() {
// put your main code here, to run repeatedly:
spi_transfer(display_all_points, 0);
delay(3000);
Serial.print("test \n");
spi_transfer(shutdown_all_points, 0);
delay(3000);
}
Thank you,
Nicolas
-
Hello Nico,
The Arduino Uno is a 5v MPU, can you confirm whether you are using a level shifter or if you have some protection built in so that you are not providing 5V to the rest of the display?
This display also would require an initialization sequence where you have to write certain registers before you are able to write to the display.
You can find a basic initialization sequence on page 8 of the datasheet for this display.https://newhavendisplay.com/content/specs/NHD-C12864A1Z-FSW-FBW-HTT.pdf
You can then use the following code to start writing to the display:https://newhavendisplay.com/content/app_notes/NHD-C12832A1Z.txt
0
Please sign in to leave a comment.
Comments
1 comment