SPI Mode Helper (CPOL/CPHA Waveforms)
Pick SPI mode 0–3 to draw SCK, MOSI, MISO and CS with sample and shift edges, a byte's bits (MSB/LSB first), transfer time and vendor names for CPOL/CPHA.
Mode table
| Mode | CPOL | CPHA | Idle SCK | Sample | Shift |
|---|---|---|---|---|---|
| 0 | 0 | 0 | Low | rising ↑ | falling ↓ |
| 1 | 0 | 1 | Low | falling ↓ | rising ↑ |
| 2 | 1 | 0 | High | falling ↓ | rising ↑ |
| 3 | 1 | 1 | High | rising ↑ | falling ↓ |
Vendor notations
| Mode | Generic (CPOL/CPHA) | Linux spidev | Arduino SPI | TI MSP430 USCI | Microchip PIC MSSP |
|---|---|---|---|---|---|
| 0 | CPOL=0 CPHA=0 | SPI_MODE_0 | SPI_MODE0 | UCCKPL=0 UCCKPH=1 | CKP=0 CKE=1 |
| 1 | CPOL=0 CPHA=1 | SPI_MODE_1 | SPI_MODE1 | UCCKPL=0 UCCKPH=0 | CKP=0 CKE=0 |
| 2 | CPOL=1 CPHA=0 | SPI_MODE_2 | SPI_MODE2 | UCCKPL=1 UCCKPH=1 | CKP=1 CKE=1 |
| 3 | CPOL=1 CPHA=1 | SPI_MODE_3 | SPI_MODE3 | UCCKPL=1 UCCKPH=0 | CKP=1 CKE=0 |
MSP430 UCCKPH and PIC CKE are the inverse of CPHA — UCCKPH = 1 or CKE = 1 means «capture on the first edge» (CPHA 0). Check against the register description in the datasheet (which edge captures, which edge changes).
What CPHA means
- CPOL is the SCK level while idle (0 = low, 1 = high). The idle → active edge is the «leading edge», the return is the «trailing edge».
- CPHA 0: sample on the leading edge, change on the trailing edge. So the first bit must already be on the line before the first edge — as soon as CS goes low.
- CPHA 1: put the bit out on the leading edge and sample on the trailing edge.
- If the two sides use different modes, bits shift by one position or only the first byte is wrong. Pick the mode from the device datasheet timing diagram: SCK idle level and which SCK edge latches data.
FAQ
Which mode is most common?
Modes 0 and 3. Both sample on the rising edge, so many devices accept either. The device datasheet timing diagram is the authority.
My read data is shifted by one bit
Likely causes: CPHA differs from the device, the clock is too fast for the device's output delay on MISO, long wiring. Lower the clock and see if it persists.
Do I raise CS after every byte?
Depends on the device. Devices that take a multi-byte command (flash memory, for example) need CS held low for the whole command. This drawing keeps CS low across all bytes.
For UART, I2C and CAN: UART Waveform Drawer · I2C Tools · CAN Frame Decoder