Home / Learn Embedded C / SPI Clock Modes: CPOL and CPHA

SPI Clock Modes: CPOL and CPHA

The four configuration combinations that determine exactly when data is sampled relative to the clock edge.

Bottom lineThe four configuration combinations that determine exactly when data is sampled relative to the clock edge.

Breaking it down

What it is

SPI clock polarity (CPOL) sets the clock's idle level (high or low when not transferring), and clock phase (CPHA) sets whether data is sampled on the first or second clock edge of each cycle — together these define 4 possible "SPI modes" (0-3).

Why it matters

Master and slave must be configured to the same SPI mode, or data will be sampled at the wrong moments relative to the clock, producing garbled results — a very common first-bring-up SPI bug.

Mechanically speaking

A device's datasheet specifies exactly which SPI mode(s) it supports; matching the master's mode configuration to that spec is a required step before any SPI communication will work correctly.

Shows up in

  • SPI device bring-up
  • Datasheet-driven configuration
  • Debugging unresponsive SPI devices

Try it

Looking up the CPOL/CPHA pair for a device's required SPI modeC: edit and run

Looking this up correctly from the datasheet before configuring the master is exactly what avoids the "doesn't respond" bring-up trap mentioned above.

ModeCPOLCPHA
000 (most common default)
101
210
311
Careful:Always check the target device's datasheet for its required SPI mode — using the wrong mode is one of the most common reasons an SPI device "doesn't respond" on first bring-up.

Try it: detecting a mode mismatch between master and slave

Comparing a configured mode against a device's required modeC: edit and run

This is exactly the kind of mismatch that makes a device "not respond" on first bring-up, even though every wire is connected correctly.

Check yourself

1. What do CPOL and CPHA together determine?