NHD-0420CW With PIC32MX Controller
Hey Guys
I've been given this LCD to get working with my PIC32MX360F256L microcontroller and I can't for the life of me get anything to happen with it. I've tried the sample code from the datasheet, I've tried several different Arduino examples and nothing I do will allow this LCD to function normally. I current have my SPI configured for IDLE high lock and I've tried sampling in the middle and at the end of the CLK.
My configuration is:
SCLK - SCLK
SDO - SCO
SDI - SDI
SS - LCD_SS
I have everything else hooked up as per the datasheet and yet I can't talk to it no matter what I do. So far the closest I've gotten was to talk to the LCD using this funciton:
void init_lcd(void)
{
LCD_SS_TRIS = 0;
LCD_SS = 1;
delay_10us(10000);
LCD_SS = 0;
delay_10us(5);
writeSPI1(0x01); //clear display
writeSPI1(0x02); // Return home
writeSPI1(0x06);
writeSPI1(0x00);
writeSPI1(0x0C); //display ON
delay_10us(10000);
LCD_SS = 1;
}
this code made a garbage characters show up, but it did turn on the screen.
I have my SPI setup in 8 bit format, I've also tried to bit bang the interface over the SPI lines.
Thanks
Docmur
-
Hello Docmur,
Thank you for reaching out, can you please post your full pin-out.
Based on the configuration you listed below it would appear that you have forgotten to Gnd BS0-BS2 (MPU interface pin selection).
Next, your LCD init function does not appear to be complete. I recommend taking a look the the following example Arduino code for that particular display.
https://github.com/NewhavenDisplay/NHD_US2066
Hope this helps!0 -
Hey Paul
Thanks for your reply.
I've attached the schematic of how we hooked up the LCD, BS0-3 are grounded.
Image: http://postimg.org/image/rg78l29gp/
Below is my full init routine:void init_lcd(void)
{
LCD_SS_TRIS = 0;
LCD_SS = 1;
delay_10us(10000);
LCD_SS = 0;
writeSPI1(0x2A); //function set (extended command set)
writeSPI1(0x71); //function selection A
writeSPI1(0x03); // disable internal VDD regulator (2.8V I/O). data(0x5C) = enable regulator (5V I/O)
writeSPI1(0x28); //function set (fundamental command set)
writeSPI1(0x08); //display off, cursor off, blink off
writeSPI1(0x2A); //function set (extended command set)
writeSPI1(0x79); //OLED command set enabled
writeSPI1(0xD5); //set display clock divide ratio/oscillator frequency
writeSPI1(0x70); //set display clock divide ratio/oscillator frequency
writeSPI1(0x78); //OLED command set disabled
writeSPI1(0x09); //extended function set (4-lines)
writeSPI1(0x06); //COM SEG direction
writeSPI1(0x72); //function selection B
writeSPI1(0x00); //ROM CGRAM selection
writeSPI1(0x2A); //function set (extended command set)
writeSPI1(0x79); //OLED command set enabled
writeSPI1(0xDA); //set SEG pins hardware configuration
writeSPI1(0x10); //set SEG pins hardware configuration
writeSPI1(0xDC); //function selection C
writeSPI1(0x10); //function selection C
writeSPI1(0x81); //set contrast control
writeSPI1(0x7F); //set contrast control
writeSPI1(0xD9); //set phase length
writeSPI1(0xF1); //set phase length
writeSPI1(0xDB); //set VCOMH deselect level
writeSPI1(0x40); //set VCOMH deselect level
writeSPI1(0x78); //OLED command set disabled
writeSPI1(0x28); //function set (fundamental command set)
writeSPI1(0x01); //clear display
writeSPI1(0x80); //set DDRAM address to 0x00
writeSPI1(0x0F); //display ON
LCD_SS = 1;
delay_10us(10000);
}
void output()
{
int i;
writeSPI1(0x01); //clear display
writeSPI1(0x02); //return home
for(i=0;i<20;i++)
{
writeSPI1(0x1F); //write solid blocks
}
writeSPI1(0xA0); //line 2
for(i=0;i<20;i++)
{
writeSPI1(0x1F); //write solid blocks
}
writeSPI1(0xC0); //line 3
for(i=0;i<20;i++)
{
writeSPI1(0x1F); //write solid blocks
}
writeSPI1(0xE0); //line 4
for(i=0;i<20;i++)
{
writeSPI1(0x1F); //write solid blocks
}
}
unsigned char writeSPI1(unsigned char byte ){
/* Make sure the module has been configured */
if( spi1Config == false ){
/* Configure the bus -- It's not configured -- */
init_spi1();
}
/* Write the byte to the buffer */
SPI1BUF = byte;
/* Wait for the transmission to complete */
#ifndef __SIMULATION
while( !SPI1STATbits.SPIRBF);
#endif
/* Clear the buffer by reading it - REQUIRED! */
return SPI1BUF;
}0 -
Excellent, thank you for the clean wiring diagram
The good news is that your wiring is correct, the issue must be within your code.
Your initialization appears to be correct, I suspect the problem is how your SPI is configured.
SPI Example:case 2:
temp = 0xF8;
for(i=0;i<8;i++)
{
digitalWrite(SCLK, LOW);
if((temp&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
temp = temp << 1;
digitalWrite(SCLK, HIGH);
}
for(i=0;i<4;i++)
{
digitalWrite(SCLK, LOW);
if((c&0x01)==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
c = c >> 1;
digitalWrite(SCLK, HIGH);
}
for(i=0;i<4;i++)
{
digitalWrite(SCLK, LOW);
digitalWrite(SDIN, LOW);
digitalWrite(SCLK, HIGH);
}
for(i=0;i<4;i++)
{
digitalWrite(SCLK, LOW);
if((c&0x01)==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
c = c >> 1;
digitalWrite(SCLK, HIGH);
}
for(i=0;i<4;i++)
{
digitalWrite(SCLK, LOW);
digitalWrite(SDIN, LOW);
digitalWrite(SCLK, HIGH);
}
break;
}If you have an oscilloscope on hand I highly recommend checking your data lines and posting some screen shots.
0 -
Done give me a second :-)
Clock Signal Isolatedhttp://postimg.cc/image/fy50lsesv/
Data Signal Isolatedhttp://postimg.cc/image/h8f71y4yb/
Clock and Datahttp://postimg.cc/image/5epyma6zp/e82e3a85/
Clock and Data Single Bytehttp://postimg.cc/image/a2f4nh2kd/
Clock and SShttp://postimg.cc/image/wkq9616vz/
Data and SShttp://postimg.cc/image/hf1nutk4h/
And finally What I was sending to grab the images
LCD_SS = 0;
writeSPI1(0x01); //clear display
writeSPI1(0x02); //return home
writeSPI1(0x1F);
LCD_SS = 1;0 -
Hi Docmur,
I'm experiencing something very similar (and it's very frustrating!) - did you get any further?
Regards
Richard0 -
It's OK, found the problem. I was sending the sync byte lsb first, as well as the data.
0
Please sign in to leave a comment.
Comments
6 comments