Home | Projects | Notes > MCU Peripheral Drivers > Introduction to SPI

Introduction to SPI

 

Serial Peripheral Interface (SPI)

 

spi

 

 

SPI Communication Sequence

  1. The master selects the slave device by asserting the Slave Select (SS) line.

    • Only after the SS line is pulled to GND, the other three lines (SCLK, MOSI, MISO) will be activated.

    • Without SS being pulled to GND, the slave's data communication lines (MOSI, MISO) will be in HI-Z (or high impedance) state.

  2. The master generates a clock signal (SCK) to establish the timing. (Synchronization)

  3. The master sends data on the MOSI line, while the slave reads it.

  4. Simultaneously, the slave prepares its response and sends it on the MISO line.

  5. The clock cycles, and data is exchanged bit by bit until the desired number of bits is transmitted.

  6. Once the data transfer is complete, the master deasserts the Slave Select (SS) line, indicating the end of communication.

 

Minimal SPI Bus

 

minimal-spi-bus

 

 

SPI Hardware: Behind the Scenes

 

spi-behind-the-scenes

 

 

Customizing SPI Bus: Bus Configuration

Full-Duplex Communication

 

spi-full-duplex-communication

 

Half-Duplex Communication

 

spi-half-duplex-communication

Typical resistance of the resistor placed between MOSI and MISO line is 1Kohm.

 

Simplex Communication

 

spi-simplex-communicationn

 

 

SPI Block Diagram

 

spi-block-diagram

 

 

Slave Select (NSS) Pin Management

 

2 Types of Slave Managements

Hardware Slave Management

Software Slave Management

Example

 

master-and-three-independent-slaves

 

Summary

 

SPI Communication Format

CLOCK POLARITY (CPOL)

CLOCK PHASE (CPHA)

Summary

 

spi-cpha-0

 

 

spi-cpha-1

 

 

SPI Serial Clock (SCLK)

 

spi2-spi3-clock

 

 

SPI Tx/Rx Algorithms

 

spi-send-data-flow-chart

 

 

spi-receive-data-flow-chart

 

 

SPI Interrupts

 

spi-interrupt-requests

 

 

spi-interrupting-the-processor

 

 

example-of-spi-interrupt-handling-sequence

 

 

Various Serial Communication Protocols

ProtocolTypeMax Distance (ft.)Max SpeedTypical Usage
USB 3.0Dual simplex serial9 (typical)
(Up to 49 with 5 hubs)
5GMass storage video
USB 2.0Half duplex serial16 (98 ft. with 5 hubs)1.5M, 12M, 480MKeyboard, mouse, drive, speakers, printer, camera
EthernetSerial160010GNetwork, communications
I2CSynchronous serial183.4M in high-speed modeMicrocontroller communications
RS-232Asynchronous serial50-10020KModem, mouse, instrumentation
RS-485Asynchronous serial400010MData acquisition and control systems SPI
SPISynchronous serial10fPCLK/2Collect data from sensors, communicate with display

SPI - Achieving high-speed data transfer rate within short distance between the devices.

I2C - Similar usage to SPI but supports lower-speed

In general, SPI/I2C can be used for communications between on-board peripherals or devices. To cover greater distances and support better quality of service CAN, Ethernet, RS485, RS232 or combination of these can be used.