Wednesday, September 3, 2014

Basics of SPI protocol:


Serial Peripheral Interface:

Common serial interface on many microcontrollers
 Simple 8-bit exchange between two devices
 Master initiates transfer and generates clock signal
 Slave device selected by master
 One-byte at a time transfer
 Data protocols are defined by application
 Must be in agreement across devices

SPI Block Diagram:


 8-bits transferred in each direction every time
 Master generates clock
 MOSI: “Master Out Slave In”; MISO: “Master In Slave Out”
 Connect MOSI to MOSI and MISO to MISO
 Very clean terminology, unlike “TX” and “RX” which are easy to confuse
 Slave Select (SS) used to select one of many slaves
 Terminology varies:
 Instead of SS, “Chip Select” (CS)
 Instead of MOSI and MISO, SIMOD and SOMI



Using SPI as a bus:



Configuration details to watch out for:

 CPHA (Clock PHase) aka ~CKPH (MSP430 terminology)
 = 0 or =1, determines when data goes on bus relative to clock
 CPOL (Clock POLarity) aka CKPL (MSP430)
 =0
 clock idles low between transfers
 =1
 clock idles high between transfers
This leads to 4 SPI clock modes

SPI timing diagram:



SPI properties:


 Pros
 Simplest way to connect 1 peripheral to a micro
 Fast (10s of Mbits/s, not on MSP) because all lines 
actively driven, unlike I2C
 Clock does not need to be precise
 Nice for connecting 1 slave
 Cons
 No built-in acknowledgement of data
 Not very good for multiple slaves
 Requires 4 wires
 3 wire variants exist…some get rid of full duplex and share a 
data line, some get rid of slave select.

No comments:

Post a Comment