SPI Protocol Explained: Full-Duplex Speed on Four Wires
How a shared clock, separate send and receive lines, and push-pull drivers push SPI past 20 MHz — plus CPOL/CPHA modes, chip-select wiring, and timing budgets.
For Readers who have wired sensors or displays to a microcontroller and understand basic bits, clocks, and digital voltages.
A simpler explanation with fewer formulas.
When a microcontroller needs to refresh a color LCD, stream audio to a DAC, or read megabytes from an SD card, I2C runs out of breath. SPI (Serial Peripheral Interface) trades two-wire minimalism for raw speed: four push-pull wires, simultaneous two-way data flow, and clocks measured in tens of megahertz.
Think of SPI as two people passing cards across a table on every beat of a metronome. On each tick, you push one card out while the other person pushes one back — full-duplex, both directions at once. Instead of broadcasting addresses like I2C, the microcontroller pulls one dedicated wire LOW to wake up the exact chip it wants.
Introduced by Motorola in the mid-1980s and never frozen into one rigid standard, SPI is a synchronous, full-duplex, push-pull serial bus linking one controller to one or more peripherals. Because drivers actively pull lines both HIGH and LOW instead of waiting on passive pull-up resistors, edges stay crisp past 20 MHz.
The four wires
Every basic SPI link uses four signal wires (plus shared ground): SCLK (clock from the microcontroller), MOSI / COPI (data out to the chip), MISO / CIPO (data back from the chip), and CS / SS (one dedicated wire per chip — pull LOW to select it, HIGH to ignore the bus).
A 4-wire SPI bus shares three lines across all devices and assigns one active-low Chip Select (CS̄) per target:
| Signal | Legacy | Modern (OSHWA / JEDEC) | Driver | Role |
|---|---|---|---|---|
| Clock | SCLK | SCLK | Controller | Synchronizes every bit shift |
| Outbound | MOSI | COPI (SDI on target) | Controller | Controller → Peripheral |
| Inbound | MISO | CIPO (SDO on target) | Selected target | Peripheral → Controller (Hi-Z when idle) |
| Select | SS̄ | CS̄ | Controller | Active-low frame boundary |
Watch for one datasheet trap: chip datasheets often name pins from the chip’s own view (SDI = in, SDO = out). Wire controller SDO (MOSI) to target SDI, and target SDO back to controller SDI (MISO).
Circular shift register: why reading still sends bytes
Both chips hold an 8-bit shift register. On every clock tick, one bit leaves the controller over MOSI into the sensor while one bit returns over MISO. After 8 ticks they have swapped bytes — which is why even a read-only transfer has to send a dummy byte (0x00 or 0xFF) just to generate 8 clock pulses.
Electrically, SPI wires two shift registers into a closed ring through MOSI and MISO. Every 8- or 16-clock transaction exchanges one word both ways with no address byte, no per-byte ACK, and no RC rise-time ceiling:
The trade-off is zero hardware acknowledgment. An unplugged chip silently returns all 0x00 or 0xFF; firmware must verify presence explicitly via a fixed WHO_AM_I register or CRC.
The four SPI modes (CPOL and CPHA)
SPI lets each chip pick one of four clock modes (Mode 0–3): whether SCLK idles LOW or HIGH, and whether bits are captured on the rising or falling edge. Most SD cards, OLEDs, and flash chips use Mode 0. If readings look shifted by one bit or scrambled, check the datasheet’s SPI mode first.
Two bits set SPI’s clock geometry: CPOL (idle state of SCLK: 0 = LOW, 1 = HIGH) and CPHA (0 = sample on 1st edge after CS̄ drops, 1 = sample on 2nd edge):
| Mode | CPOL | CPHA | Idle SCLK | Sample edge | Shift edge | Typical devices |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | LOW | Rising (1st) | Falling (2nd) | SD cards, NOR flash, TFT/OLED |
| 1 | 0 | 1 | LOW | Falling (2nd) | Rising (1st) | Specialized ADCs, thermocouples |
| 2 | 1 | 0 | HIGH | Falling (1st) | Rising (2nd) | Rare legacy peripherals |
| 3 | 1 | 1 | HIGH | Rising (2nd) | Falling (1st) | MEMS IMUs, sensors (often 0 & 3) |
When sharing a bus across different CPOL values, reconfigure the controller before pulling the next chip’s CS̄ LOW so the idle-level change is not read as a false first clock.
Scaling speed and timing budgets
Adding devices requires one extra CS̄ pin per chip (or daisy-chaining MISO → MOSI across LED drivers and shift registers under one shared CS̄). That makes SPI ideal for 1–4 fast peripherals, while I2C wins for a dozen slow sensors on scarce pins.
At high clock rates, SPI hits a hard physical ceiling: round-trip propagation on MISO. In Mode 0, the controller’s falling edge travels to the target (t_prop), the target outputs a valid bit after t_v, the bit returns (t_prop), and it must beat the next rising edge by setup time t_su:
With realistic flash numbers (t_v = 12 ns, t_su = 5 ns, 2·t_prop = 2 ns), T_SCLK ≥ 38 ns — capping reads at f_max ≈ 26.3 MHz even if the MCU can drive 50 MHz. Faster systems add delayed MISO sampling, Quad/Octal SPI (4–8 bidirectional lanes, reaching 50–200+ MB/s for XIP flash with DQS strobe), DMA rings to avoid CPU polling stalls, and 22 Ω–47 Ω series damping resistors on SCLK/MOSI/MISO to tame trace reflections.
| Feature | UART | I2C | SPI |
|---|---|---|---|
| Wires | 2 (TX, RX) | 2 (SCL, SDA) | 3 + N (SCLK, MOSI, MISO, N × CS̄) |
| Duplex | Full | Half | Full |
| Typical speed | 9.6 kbps – 3 Mbps | 100 kHz – 1 MHz | 1 MHz – 50+ MHz |
| Built-in ACK | No | Yes | No |
| Best for | Consoles, GPS | Many slow sensors | Displays, SD cards, flash, fast ADCs |