SPI Bus Timing
SPI Clock Divider & Mode 0–3 Calculator
Pick the fastest legal SPI prescaler below your slave device’s maximum SCLK rating and verify CPOL/CPHA sampling edges across Modes 0–3.
Power-of-2 prescalers 2, 4, 8, 16, 32, 64, 128, 256
APB1/APB2 clock (STM32) or peri clock
e.g. 5 MHz (MAX31855), 10 MHz (BMI088), 18 MHz (SX1280)
Idle Low (0); sample Rising (leading)
Fastest Safe SCLK5.25 MHzBR[2:0] = 0b011 (/16)
Byte Transfer Time1.52 us8 SCLK cycles (excluding CS setup)
Selected SPI ModeMode 0 (0/0)Sample: Rising (leading)
CS ‾‾\_________________________________________/‾‾
SCLK ____/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\____
DATA ---< D7 >< D6 >< D5 >< D4 >< D3 >< D2 >< D1 >< D0 >---
^sample on rising edge (CPOL=0, CPHA=0)| Register / Divider | Actual SCLK | Byte Period | Within Slave Max (10 MHz) |
|---|---|---|---|
BR[2:0] = 0b000 (/2) | 42 MHz | 0.19 us | Overclocked |
BR[2:0] = 0b001 (/4) | 21 MHz | 0.38 us | Overclocked |
BR[2:0] = 0b010 (/8) | 10.5 MHz | 0.76 us | Overclocked |
BR[2:0] = 0b011 (/16) | 5.25 MHz | 1.52 us | Within spec |
BR[2:0] = 0b100 (/32) | 2.625 MHz | 3.05 us | Within spec |
BR[2:0] = 0b101 (/64) | 1.313 MHz | 6.10 us | Within spec |
BR[2:0] = 0b110 (/128) | 656.3 kHz | 12.19 us | Within spec |
BR[2:0] = 0b111 (/256) | 328.1 kHz | 24.38 us | Within spec |
SPI Mode 0–3 reference table
| SPI Mode | CPOL | CPHA | SCLK Idle | Data Sampled | Typical Parts |
|---|---|---|---|---|---|
| Mode 0 | 0 | 0 | Low | Rising edge | BMI088, SX1276, SX1280, MAX31855, NOR Flash |
| Mode 1 | 0 | 1 | Low | Falling edge | Selected TI / ADI precision ADCs |
| Mode 2 | 1 | 0 | High | Falling edge | Legacy shift-register peripherals |
| Mode 3 | 1 | 1 | High | Rising edge | ADXL345, LSM6DSO, BMI088 (0 or 3) |
Common SPI bring-up bugs
| Bug | Cause & fix |
|---|---|
| Dummy byte on read | Parts like the Bosch BMI088 accelerometer insert a mandatory dummy byte between the register address and the first valid data byte in SPI mode (the gyroscope does not). |
| Premature CS de-assertion | Raising CS right after writing the last byte to the TX FIFO truncates the shift register. Poll BSY == 0 (STM32) or DMA RX-complete before raising CS. |
| Clock mode mismatch | Reading 0xFF or bit-shifted chip IDs (e.g. 0xD0 instead of 0x68) usually means CPHA is inverted. |