SPI (Serial Peripheral Interface)

Overview

  • Synchronousfull-duplex serial bus.
  • Master-slave architecture (1 master, multiple slaves).
  • Uses 4 wires:
    • SCLK (clock), MOSI (Master Out Slave In), MISO (Master In Slave Out), SS/CS (Slave Select).

Physical Layer

  • Push-pull outputs (faster than open-drain).
  • Each slave requires a dedicated SS line.

Data Frame Structure

  • No start/stop bits – continuous stream synchronized to SCLK.
  • Data sampled on clock edges defined by CPOL (clock polarity) and CPHA (clock phase):
    • Mode 0: CPOL=0 (idle low), CPHA=0 (sample on rising edge).
    • Mode 3: CPOL=1 (idle high), CPHA=1 (sample on falling edge).
SCLK | MOSI (Data from Master) | MISO (Data from Slave) | CS (Active Low)

Key Features

  • Full-duplex communication (simultaneous MOSI/MISO).
  • No addressing – slaves selected via SS lines.
  • Speeds: Up to 100+ Mbps (depends on hardware).

Pros & Cons

ProsCons
High-speed communicationHigh pin count (n+3 for n slaves)
Simple protocol, flexible modesNo built-in error detection
Full-duplex supportNo multi-master support

Use Cases

  • High-speed sensors (e.g., IMUs).
  • Display controllers (OLED, TFT).
  • SD cards, NOR flash memory.

Comparison Table

FeatureUARTI2CSPI
ClockNone (async)Shared (SCL)Shared (SCLK)
DuplexFull-duplexHalf-duplexFull-duplex
TopologyPoint-to-pointMulti-deviceMaster-slave
SpeedLow (≤115kbps)Moderate (≤3.4Mbps)High (≥10Mbps)
AddressingNone7/10-bitHardware (SS lines)
Pins2 (TX/RX)2 (SCL/SDA)4 + n (SS per slave)
Error HandlingParity bitACK/NACKNone