2
\$\begingroup\$

I am trying to communicate with a Nokia 1202 LCD with my Arduino using SPI.

The LCD using the STE2007 Controller. As per the datasheet here @ page 12, you find that the min time for SCLK is 250ns => 4MHz and no maximum value listed. So what i understand is that this driver can communicate using SPI with SCLK being max. of 4MHz.

Since my arduino board is running at 16MHz, and I will be using the 'spi' library this is what I think i should do:

  1. set bits SPR0 and SPR1 in the SPCR register to set the spi clock speed @ 4MHz
  2. do spi.begin()
  3. execute spi commands as normal

Is this correct ?

Something like ...

void setup()
{
  pinMode(SPI_SS, OUTPUT);
  pinMode(SPI_DC_SEL, OUTPUT);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  //set spi register to set SCLK @ 4Mhz
  //SPI2X = SPR1 = SPR0 = 0 
  SPCR &= ~(1<<SPR1);
  SPCR &= ~(1<<SPR0);
  SPSR &= ~(1<<SPIX2);
}
\$\endgroup\$
  • \$\begingroup\$ why don't you try that and see if it works, e.g. try to read a register from the LCD, and come back here if/when you have a problem. \$\endgroup\$ – mux Oct 4 '12 at 6:12
2
\$\begingroup\$

You can set the SPI speed (and many other things!) using the Arduino SPI library without specifying any register values. You already did it with MSBFIRST. Like so:

  SPI.setDataMode(SPI_MODE3);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV4); // 16/4 MHz
  SPI.begin(); 

Also, SPI.begin sets all the pin modes for you, so no need to do that.

\$\endgroup\$
  • \$\begingroup\$ thanks! should have checked the arduino SPI library documentation before asking the question. \$\endgroup\$ – Ankit Oct 4 '12 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.