Author Topic: NHD-0420CW With PIC32MX Controller  (Read 3760 times)

docmur

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
NHD-0420CW With PIC32MX Controller
« on: May 11, 2015, 12:25:06 PM »
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

Paul_B

  • Administrator
  • Sr. Member
  • *****
  • Posts: 248
  • Karma: 16
    • View Profile
Re: NHD-0420CW With PIC32MX Controller
« Reply #1 on: May 12, 2015, 08:05:22 AM »
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!



docmur

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: NHD-0420CW With PIC32MX Controller
« Reply #2 on: May 12, 2015, 08:53:32 AM »
Hey Paul

Thanks for your reply. 

I've attached the schematic of how we hooked up the LCD, BS0-3 are grounded.

Below is my full init routine:
Code: [Select]
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;
}


Image:
http://postimg.org/image/rg78l29gp/

Paul_B

  • Administrator
  • Sr. Member
  • *****
  • Posts: 248
  • Karma: 16
    • View Profile
Re: NHD-0420CW With PIC32MX Controller
« Reply #3 on: May 12, 2015, 09:37:32 AM »
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:

Code: [Select]
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.

docmur

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: NHD-0420CW With PIC32MX Controller
« Reply #4 on: May 12, 2015, 10:06:05 AM »
Done give me a second :-)

Clock Signal Isolated
http://postimg.org/image/fy50lsesv/

Data Signal Isolated
http://postimg.org/image/h8f71y4yb/

Clock and Data
http://postimg.org/image/5epyma6zp/e82e3a85/

Clock and Data Single Byte
http://postimg.org/image/a2f4nh2kd/

Clock and SS
http://postimg.org/image/wkq9616vz/

Data and SS
http://postimg.org/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;

richardms

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: NHD-0420CW With PIC32MX Controller
« Reply #5 on: June 25, 2015, 07:27:01 AM »
Hi Docmur,

I'm experiencing something very similar (and it's very frustrating!) - did you get any further?

Regards
Richard

richardms

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: NHD-0420CW With PIC32MX Controller
« Reply #6 on: June 26, 2015, 11:53:09 AM »
It's OK, found the problem. I was sending the sync byte lsb first, as well as the data.


 

NHD‐0420CW‐AB3 I2C Interface

Started by andersonpdBoard OLEDs

Replies: 1
Views: 2630
Last post January 23, 2015, 10:00:06 AM
by Michael_L
NHD‐0420CW‐AG3 Contrast question

Started by RichardRBoard OLEDs

Replies: 2
Views: 2147
Last post January 16, 2016, 09:52:02 AM
by RichardR
NHD‐0420CW‐AG3: blinking part of text?

Started by RichardRBoard OLEDs

Replies: 2
Views: 2299
Last post February 28, 2017, 03:27:02 PM
by BobG
NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started

Started by RichardRBoard OLEDs

Replies: 4
Views: 3143
Last post December 17, 2015, 03:12:49 AM
by RichardR
MOVED: NHD-0420CW-AY3 display, text is mirror image

Started by Saurabh_BBoard Character LCDs

Replies: 0
Views: 2065
Last post March 11, 2016, 07:51:03 AM
by Saurabh_B