SPI Crystalfontz 632 Problems

Hi All,

I’m trying to get a CrystalFontz LCD to print me out some meaningful characters. Right now I have it printing some gibberish. This was only a test to play with SPI and an LCD and has become something more… I am determined to get this to work. Any and all help would be appreciated.

  1. Do I have the SPI setup correctly?
  2. Are there any other libraries that could help me out?
  3. Does the SPI.h only talk with specific chip sets?

I forget what this code was specifically trying to do, I have changed it around so much.
Thanks guys.

http://www.crystalfontz.com/product/CFA632NFAKS This is the Datasheet for the LCD. Little confusing with the \ notation, I’ve never seen that used before. Still pretty new to this stuff.
Arduino 1.0.4
Using Arduino Uno R3

//~~~~~~~~~~~~~~~~~~~~~~~
#include <SPI.h>

char text[] = "Hello World";
int values[24] = {92,48,51,49/*,92,48,48,50,92,48,51,49,92,48,51,48,92,48,48,50,92,49,51,48*/};
void setup()
{
  int SS = 10;
  pinMode(SS, OUTPUT);
  SPI.begin();
}
/*
void sendInfo(int value, amount){
  SPI.transfer(
}
*/
void loop(){
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  SPI.setDataMode(SPI_MODE3);
  while(1){
    digitalWrite(SS, LOW);
    for(int i = 0; i < 4; i++){
      SPI.transfer(values[i]);
//      SPI.transfer(48);
//      SPI.transfer(49);
//      SPI.transfer(52);
//      SPI.transfer(92);
//      SPI.transfer(48);
//      SPI.transfer();
//      SPI.transfer(48);
      SPI.transfer(text[i]);
      delay(100);
    }
    digitalWrite(SS, HIGH);
    delay(5000);
  }
}

Using SPI_CLOCK_DIV128 results in a SPI clock frequency of 125kHz, which is way above the 18kHz this module maximally supports (see appendix A, min. 55µs clock period). Don’t use the SPI hardware interface but use a simple shift out function:

void softSPItransfer(uint8_t data) {
  digitalWrite(SS_PIN, LOW);
  for (uint8_t i = 0; i < 8; i++) {
    if (data & 0x80) {
      digitalWrite(MOSI_PIN, HIGH);
    } else {
      digitalWrite(MOSI_PIN, LOW);
    }
    data <<= 1;
    digitalWrite(SCLK_PIN, LOW);
    delayMicroseconds(27);
    digitalWrite(SCLK_PIN, HIGH);
    delayMicroseconds(27);
  }
  digitalWrite(SS_PIN, HIGH);
}

Hey, thanks for the help Pylon! I appreciate the help. Hope it didn't take you to long to figure it out. Hopefully tonight I'll get to try it out. I'm out spending the day with my kids (fell asleep in the car so I'm sitting with them). I'll let you know how it works out.

Works great!!! Thanks a lot Pylon. Here’s the code I ended up playing with to get it to work. Only question I have now is how do I put the cursor where I want? The datasheet says to send it the code \017 and some other stuff but how do I send a \ ? is it ASCII or ??? don’t worry about it too much i’ll play with it again tomorrow. I have an idea. Thanks again.

char text[15] = {\017"Hello  World "};
int values[15] = {72,69,76,76,79,32,87,79,82,76,68,32,32,32,32};
int SCLK_PIN = 13;
int SS_PIN = 10;
int MOSI_PIN = 11;
//int MISO_PIN = 12;
int data = 0;
int data1 = 0;
void softSPItransfer(int data);

void setup()
{
  pinMode(SS_PIN, OUTPUT);
  pinMode(MOSI_PIN, OUTPUT);
  //pinMode(MISO_PIN, INPUT);
  pinMode(SCLK_PIN, OUTPUT);
}

void loop(){
  delay(5000);
  for(int i = 0; i < 16; i++)
  {
    data1 = text[i];
    softSPItransfer(data1);
    delay(1000);
  }
}

void softSPItransfer(int data) 
{
  digitalWrite(SS_PIN, LOW);
  for (uint8_t i = 0; i < 8; i++) {
    if (data & 0x80) {
      digitalWrite(MOSI_PIN, HIGH);
    } else {
      digitalWrite(MOSI_PIN, LOW);
    }
    data <<= 1;
    digitalWrite(SCLK_PIN, LOW);
    delayMicroseconds(27);
    digitalWrite(SCLK_PIN, HIGH);
    delayMicroseconds(27);
  }
  digitalWrite(SS_PIN, HIGH);
}

They use the unusual format \017 to describe an ASCII value of 17 (decimal).

So you send the cursor home with:

softSPItransfer(0x01);

to move the cursor to column 5 in the second row:

softSPItransfer(0x11);
softSPItransfer(0x04);
softSPItransfer(0x01);

At least that’s my interpretation of the datasheet.