SPI data transfers

By | February 21, 2008

I use SPI  on my micromouse both to talk to the Nokia graphical LCD and to talk to the LS7366 quadrature encoders. A large number of devices can be connected to the SPI data lines, MOSI and MISO. Each device needs its own select line. This all appear very simple and friendly. There is, however a potential problem due to the flexibility of the SPI configuration.

Aside from the device select line, three wires are used to transfer data between a a master and a slave. MOSI is the Master-Out-Slave-In line while MISO is the Master-In-Slave-Out. There is also a clock signal SCK. Data transfers occur simultaneously on the data lines and the clock edges are used to shift and latch the data at each device. Now rather than have a single standard for which clock edges do what, there are four possibilities:

Mode 0:
The clock is active high, data latched on the rising edge, data clocked out on the falling edge.

Mode 1:
The clock is active high, data  latched on the falling edge, data clocked out on the rising edge.

Mode 2:
The clock is active low, data latched on the falling edge, data clocked out on the rising edge.

Mode 3:
The clock is active low, data latched on the rising edge, data clocked out on the falling edge.

Note that some microcontrollers may not be able to set up their SPI peripheral in all of these modes and may be limited to just one – probably Mode 0

Confused yet? So am I.

Let’s have a look at the data sheet for the LS7366. On the very first page it says

Received bytes are shifted in [latched] on MOSI with the leading edges (high transition) of SCK. Output data is shifted out on MISO with the trailing edges of the SCK clocks.

Figure 2 of the datasheet has a timing diagram and the statement that SCK is idle low. This then is operating in Mode 0.

In itself, this is not a big deal but if you have other devices using the same SPI port, it will be important to know if they also use Mode 0 or will require reconfiguration of the port for use with each device.

The Nokia display uses the same protocol as the PCD8544 chip on the Nokia 3310 displays. The data sheet for this says, at the beginning of section 8, ‘SDIN is sampled at the positive edge of SCLK’ . So far then, it could be either Mode 0 or Mode 3. Fortunately, Figure 12:


Makes it reasonably clear we are dealing with Mode 0 again. Note that the Nokia display only accepts data and cannot communicate back to the master device.

Having both devices use Mode 0 will make it all that bit easier to talk to them.

Find out more here:

Introduction to Serial Peripheral Interface [embedded.com]

SPI – Serial Peripheral Interface [mct.net]

SPI, Microwire and I2C Protocol Formats [uspros.com]

About SPI [elm-chan.org]

2 thoughts on “SPI data transfers

  1. sam

    is this the color 132×132 nokia display that sparkfun sells? [since i’ve been trying to find out what SPI mode it uses, and if it’s that display, you’ve answered my question]


  2. peteh

    Oh – how embarrassing. I didn’t notice your comment util today.

    Sorry, this is a standard Nokia display, not the Sparkfun one

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.