Thursday, May 27, 2010

Serial Peripheral Interface

SPI is a serial link standard used between chips. Now days most microcontrollers have an on board SPI block. SPI link is made of atleast one master and one slave. The link is composed of four wires:
  1. SCLK - Serial Clock, always provided by the Master
  2. MOSI - Master Out Slave In, Data (from master to slave)
  3. MISO - Master In Slave Out, Data (from slave to master, clock still has to be provided by master)
  4. nSS - Slave Select, usually the Chip Select signal for the slave.
Sensors, ADC/DAC, memory and many other devices had slave SPI interfaces. Some examples of SPI compatible ICs/Devices:-
  • Accelerometers (ADIS16201)
  • 4-20mA current control (AD420)
  • Flash Memory (EN25T80)
  • Nokia 6610 Colour Graphical STN LCD (PCF8833)
  • Nokia 3310 Monochrome Graphical LCD (PCD8544)
  • EEPROM (25AA640)
  • SD Card
  • 10BASET Ethernet Controller (ENC28J60)
Many microcontrollers - like AT89S52 and all the AVR devices available from Atmel - are programmed via SPI.

Here is a screen shot of SPI signals captured as a master sends a byte to a slave:


All signals captured are from microcontroller (master) to slave device
Channel 4: nSS
Channel 2: SCLK
Channel 3: MOSI
In this particular case, each data bit is clocked in by the slave device at the falling edge of the clock. Some slaves sample the data at the rising edge.




Here is another example of SCLK (Channel 1 Yellow) and MOSI (Channel 2 Blue). It shows the transmission of 6 bytes of the string "Hello,"
i.e. The ASCII codes, left to right in the waveform:
0x48 (01001000)
0x65 (01100101)
0x6C (01101100)
0x6C (01101100)
0x6F (01101111)
0x2C (00101100)


SPI as captured from SPI0  pins of TM4C129DNCPDT microcontroller

0 comments:

Post a Comment