Go Down

Topic: Problems using shiftOut for SPI LCD (Read 995 times) previous topic - next topic

So I'm trying to hook up this LCD to my Nano.

http://www.newhavendisplay.com/specs/NHD-C0216CZ-NSW-BBW-3V3.pdf

I've double checked all my connections and everything appears correct. however I can't get it to even turn on. After rechecking my connections I realized that while I have 3.3 going to the power for the chip, all the SPI lines are running at 5V because that's what the Nano runs at. So is it possible I fried my board by doing that? Or is that ok? Here's my code. I based it on a few different examples I've seen, but I feel quite confident that I screwed something up in it. It doesn't even seem like it's turning the board on. I don't know what it would do when it turned on, but I sorta feel like I'd see SOMETHING happen, even if it wasn't printing the data properly to the display.

Code: [Select]
#define RE 17
#define CS 6
#define SC 7
#define SI 8
int serialcounter = 1;
#define RS 5

void setup()
//initialize the LCD
{
  pinMode(RE, OUTPUT);
  pinMode(RS, OUTPUT);
  pinMode(CS, OUTPUT);
  pinMode(SC, OUTPUT);
  pinMode(SI, OUTPUT);

  digitalWrite(CS, HIGH);
  digitalWrite(RS, HIGH);

  initLCD();
}

void initLCD(){
  digitalWrite(RE,LOW);
  delay(2);
  digitalWrite(RE,HIGH);
  delay(20);
  digitalWrite(RS, LOW);
  digitalWrite(CS, LOW);
  spi_transfer(B00110000);
  delay(2);
  spi_transfer(B00110000); //wake up
  spi_transfer(B00110000); //wake up
  spi_transfer(B00111001); //function set
  spi_transfer(B00010100); //internal osc frequency
  spi_transfer(B01010110); //power control
  spi_transfer(B01101101); //follower control
  spi_transfer(B01110000); //contrast
  spi_transfer(B00001100); //display on
  spi_transfer(B00000110); //entry mode
  spi_transfer(B00000001); //clear
  delay(10);
  digitalWrite(CS, HIGH);
}

void spi_transfer(int data) {
  digitalWrite(CS, LOW);
  digitalWrite(RS, HIGH);
  shiftOut(SI,SC,MSBFIRST,data);
  digitalWrite(CS, HIGH);
}

void clearDisplay() {
  digitalWrite(CS,LOW);
  digitalWrite(RS,LOW);

  //clear the display
  spi_transfer(B00000001); //clear
  digitalWrite(RS,HIGH);
  digitalWrite(CS,HIGH);

}


void loop(){
  spi_transfer(B00000001);
  digitalWrite(13, HIGH);
  delay(1000);
  clearDisplay();
  digitalWrite(13, LOW);
  delay(1000);
}


Well, I just noticed one problem, I'm calling RS HIGH in my spi_transfer function which means all my "command" transfers during init are being transfered as data, which would of course make nothing turn on. I kinda doubt that's the whole problem though, as I just had added that to spi_transfer thinking it would save me calling it out every time I called spi_transfer. I'll just write separate data_transfer() and com_transfer() functions.

olikraus

You could use http://code.google.com/p/doglcd/. doglcd was written for ST7036, but it should be compatible to your ST7032 based display.

Oliver

Awesome, I'll give it a shot.

Do you know about the voltage issue? I need to know if I have to order a 3.3V board from somewhere. Thank you for the help!
-Rich

Also, there isn't a problem with using a output pin to ground a circuit as opposed to power it is there? In otherwords I want to put the pin between the backlight led and ground as opposed to between VCC and the backlight. Thanks!

olikraus

Well, good question. I never tried to apply 5V inputs to a 3.3V display. Sometimes, the data sheet says that the inputs are 5V tolerant, but i did not find such an information in the ST7032 data sheet. So maybe you could try the display with a valid software to check if the display still works.

Oliver

It works! You are my hero. :-) I can't tell you how frustrated I was with this silly thing. Note that it does not work unless you set the parameters in doglcd to 3.3V (duh). I kinda doubt having the 5V inputs are good for it, but it didn't kill it. the controller can be run at 5V but I doubt it's good for it to have 3.3V power and 5V inputs. Certainly not a long term solution, but for the moment, the screen is working and this guy is happy. :-)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy