📡 SPI (Serial Peripheral Interface)

SPI is a synchronous, full-duplex protocol used for short-distance communication, usually between a microcontroller and fast peripherals like SD cards, displays, or high-speed ADCs.

Unlike I2C, SPI does not use device addresses. Instead, it uses a hardware Chip Select (CS) or Slave Select (SS) wire for every device on the bus.

1. Physical Wiring

SPI typically uses four wires:

  • SCLK (Serial Clock): Generated by the Master to synchronize data.
  • MOSI (Master Out Slave In): Data sent from the Master to the Slave.
  • MISO (Master In Slave Out): Data sent from the Slave to the Master.
  • CS / SS (Chip Select): The Master pulls this line LOW to “talk” to a specific slave.

2. Full-Duplex Nature

Because there are two independent data lines (MOSI and MISO), SPI can send and receive data at the exact same time. This makes it significantly faster than I2C or UART for data-heavy tasks.

ParameterDescription
CommunicationFull-duplex (simultaneous TX/RX).
SpeedVery high (typically 1MHz to 100MHz+).
ConfigurationSingle Master / Multiple Slaves.
Clock PolarityCPOL and CPHA settings define when data is sampled (4 modes).
FeatureUARTI2CSPI
Wires22 (plus pull-ups)3 + N (Slaves)
SpeedSlowMediumVery High
DistanceMediumShortVery Short
ComplexitySimpleModerateModerate

When setting up SPI, you must match the Mode of your Master to your Slave.

  • CPOL (Polarity): Is the clock High or Low when idle?
  • CPHA (Phase): Is data sampled on the leading or trailing edge of the clock?
  • If these don’t match, your data will be shifted by one bit or completely corrupted.

Scroll to Top