Protocol

SPI

Serial Peripheral Interface

Build Full lab

Overview

Full-duplex synchronous bus with SCLK, MOSI, MISO, and per-device chip select. Mode is defined by CPOL/CPHA (or mode 0–3); there is no standard framing beyond shifting bits on agreed edges.

Tags

synchronouscpolcphafull-duplexcs

History

Origin

1979 · Motorola

Full-duplex synchronous bus with SCLK, MOSI, MISO, and per-device chip select. Mode is defined by CPOL/CPHA (or mode 0–3); there is no standard framing beyond shifting bits on agreed edges.

Timeline

  1. 1979

    SPI introduced

  2. 1989

    SPI broadly deployed / revised

Why designed this way

Full-duplex synchronous bus with SCLK, MOSI, MISO, and per-device chip select.

Mode is defined by CPOL/CPHA (or mode 0–3); there is no standard framing beyond shifting bits on agreed edges.

Howto

Modes (CPOL/CPHA)

CPOL=0: clock idle low; CPOL=1: idle high. CPHA=0: sample on first edge; CPHA=1: sample on second edge. Modes 0–3 are the four combinations.

Mismatch shifts every bit by one edge — data looks “almost right” but wrong. Always confirm against the slave datasheet timing diagram.

Some parts use “mode 0” naming inconsistently; trust setup/hold relative to CS and first clock.

Chip select and duplex

Each slave needs its own CS (or a decode). Floating CS causes multi-drive on MISO — use pull-ups and never share MISO without tri-state.

SPI is full duplex: while you write a command you also shift out old MISO bits. Protocol layers define which bytes are meaningful.

Dummy clocks after address phases (flash reads) are part of the command, not idle.

Signal integrity

Fast SCLK with long stubs produces ringing; series resistors and shorter wires help. Return paths matter as much as the four signal names.

Multi-slave buses: deselect all CS before changing mode/speed if slaves disagree on mode.

Wire

Frame map

SPI frame

Tap a field for detail.

Frame field descriptions
FieldSizeDescription
SS1 bitSlave select asserted.
MOSI byte1 byteMaster-out bits on SCLK edges (mode 0–3).
MISO byte1 byteMaster-in simultaneous bits.

Operation trace

SPI engineer walkthrough

Full-duplex synchronous bus with SCLK, MOSI, MISO, and per-device chip select. Mode is defined by CPOL/CPHA (or mode 0–3); there is no standard framing beyond shifting bits on agreed edges.

  1. 1. Howto CPOL=0: clock idle low; CPOL=1: idle high. CPHA=0: sample on first edge; CPHA=1: sample on second edge. Modes 0–3 are the four combinations.
  2. 2. Howto Mismatch shifts every bit by one edge — data looks “almost right” but wrong. Always confirm against the slave datasheet timing diagram.
  3. 3. Howto Some parts use “mode 0” naming inconsistently; trust setup/hold relative to CS and first clock.

Lab

Interactive bench for SPI — decode captures, step traces, and probe fields without leaving the browser.

SPI

MOSISCLKMISOCS

bit 104.2 µs · tick 26.0 µs · frame ~ 2.03 ms · 4 samp/bit · VCD 1 us/tick (bit 104.167 µs)

Sample clock: 26.042 µs/tick · 4 ticks/bit · 104.167 µs/bit

SPI mode 0 (CPOL=0 CPHA=0)

Lanes: MOSI, SCLK, MISO, CS

Decoded wire

Bytes: 48 69 (Hi)

  • MOSI 1 48 CS active from tick 6
  • MOSI 2 69 CS active from tick 37
  • CS glitch byte 3 bit 0 CS mid-byte

CS released mid-byte at bit 0

SPI framing

Tap a field for detail.

Frame field descriptions
FieldSizeDescription
SS1 bitSlave select asserted.
MOSI byte1 byteMaster-out bits on SCLK edges (mode 0–3).
MISO byte1 byteMaster-in simultaneous bits.
Open full-page lab →

Specs

Related protocols