Interface Protocols · All levels

SPI Modes & Chip-Select Rules

Embedded Peripherals (I2C / SPI / UART): SPI relies on CPOL/CPHA, chip-select timing, shift order, and device-specific framing agreements.

What this topic teaches

SPI Modes & Chip-Select Rules is about converting a protocol rule into a measurable silicon contract. SPI relies on CPOL/CPHA, chip-select timing, shift order, and device-specific framing agreements. The hard part is never the happy-path diagram; it is proving, under real traffic, which layer and which transaction broke the contract.

The senior-engineer question

When frame error rate, chip-select timing violation, throughput moves, can you identify the transaction, the protocol layer, the responsible owner, and the smallest experiment that proves the root cause?

diagram
PROTOCOL STACK VIEW — SPI Modes & Chip-Select Rules

software / firmware intent
        |
        v
transaction semantics: address, ID, length, attributes, ordering
        |
        v
link / channel behavior: handshake, credits, backpressure, retries
        |
        v
physical or timing layer: clocking, reset, pins, lanes, PHY
        |
        v
observability: waveform, VIP transaction, counter, analyzer trace

Debug rule: never jump layers without carrying the transaction identity with you.

Picture the protocol

Start every study session by drawing the behavior before reading signals. The diagrams below are the mental models to reproduce on a whiteboard.

SPI modes (CPOL/CPHA)

diagram
SPI MODES

Mode | CPOL | CPHA | sample edge
-----+------+------+-------------
  0  |  0   |  0   | rising
  1  |  0   |  1   | falling
  2  |  1   |  0   | falling
  3  |  1   |  1   | rising

WAVE (Mode 0):
CS   ‾‾\____________________/‾‾
SCLK ____|‾|_|‾|_|‾|_|‾|________
MOSI    D7  D6  D5  D4
        ^ sampled on rising edge

Transaction sequence

diagram
SEQUENCE — SPI Modes & Chip-Select Rules

  initiator            interconnect/PHY            target
      |  request (id) ------->  |                     |
      |                         |  forward ----------> |
      |                         |                     | work
      |                         |  <---- response ---- |
      |  <----- complete ------ |                     |
      |
   metric captured here: frame error rate, chip-select timing violation, throughput

Who owns which layer

diagram
LAYER RESPONSIBILITY — SPI Modes & Chip-Select Rules

layer          owns                         common failure
-----------    --------------------------   -----------------------
software       intent, ordering needs       wrong assumption
transaction    id/addr/len/attributes       ordering / outstanding
link/channel   handshake, credits, retry    backpressure / deadlock
physical       clock/reset/lanes/PHY        timing / training / SI
observability  waveform/log/counter         missing evidence

Evidence to collect

  • Primary metric: frame error rate, chip-select timing violation, throughput.

  • Primary artifact: MOSI/MISO/SCLK/CS waveform, mode table, device timing spec.

  • Owners to bring into review: IP owner, firmware owner, verification owner.

  • Spec clause or requirement ID for every claim.

  • One traffic replay that fails and one reduced sequence that isolates the rule.

Ownership map

diagram
OWNERSHIP MAP — SPI Modes & Chip-Select Rules

evidence type        owner who reads it
-----------------    ---------------------------
waveform/RTL        IP owner
spec/VIP            firmware owner
firmware/system     verification owner

Rule: every metric must have a named owner before a review starts.

Subpages in this topic

Each topic is taught across mechanism, inputs/outputs, reports, debug, worked example, pitfalls, interview, checklist, theory, design space, expanded case study, walkthrough, comparison matrix, software view, and silicon PPA impact.

Key takeaways

  • Carry transaction identity across waveform, log, counter, and spec view.

  • Separate protocol violation, integration configuration, and performance bottleneck before proposing a fix.

  • Draw the diagram first; the waveform should confirm the picture, not replace it.

Common pitfalls

  • Debugging only one channel or layer.

  • Treating a VIP error message as root cause instead of evidence.

  • Quoting peak interface bandwidth without payload efficiency.

Protocol deep dive

I2C/SPI/UART bugs are contract bugs: timing, reset value, IRQ type, and DMA watermark.

Concept diagram

diagram
PERIPHERAL CONTRACT

firmware writes regs -> RTL state machine -> pins -> board -> device
        ^                    |
        +------- IRQ/DMA ----+

If IRQ is level but driver assumes edge, you get lost events.

Metric graph

diagram
FIFO WATERMARK vs DMA

FIFO fill
 100%|        *** overrun risk
  75%|     ***
  50%|  ***     <- ideal DMA trigger band
  25%| *
   0%+----------------> time

Metrics and artifacts to collect

  • NACK rate

  • overrun count

  • CS setup/hold violations

  • IRQ miss rate

Mini case study

SPI flash worked in loopback but failed in system: CS deasserted one cycle early relative to device hold time. Board + RTL + mode bits together formed the contract.

Debug branches

  • If overrun, FIFO depth vs ISR latency vs DMA burst.

  • If NACK on I2C, pull-ups, speed, and clock stretch.

  • If garbage data, CPOL/CPHA and MSB/LSB first.

Senior review question

Ask: what is the first transaction that deviates, and which spec rule does it test?

Key takeaways

  • Connect every protocol claim to a transaction identity and measurable metric.

  • Store the artifact (waveform, log, counter) next to every signoff decision.

Common pitfalls

  • Debugging timeouts without finding the first bad transaction.

  • Quoting peak bus width without payload efficiency and retry overhead.

  • Treating VIP compliance as a substitute for system integration replay.