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 / DividerActual SCLKByte PeriodWithin Slave Max (10 MHz)
BR[2:0] = 0b000 (/2)42 MHz0.19 usOverclocked
BR[2:0] = 0b001 (/4)21 MHz0.38 usOverclocked
BR[2:0] = 0b010 (/8)10.5 MHz0.76 usOverclocked
BR[2:0] = 0b011 (/16)5.25 MHz1.52 usWithin spec
BR[2:0] = 0b100 (/32)2.625 MHz3.05 usWithin spec
BR[2:0] = 0b101 (/64)1.313 MHz6.10 usWithin spec
BR[2:0] = 0b110 (/128)656.3 kHz12.19 usWithin spec
BR[2:0] = 0b111 (/256)328.1 kHz24.38 usWithin spec

SPI Mode 0–3 reference table

SPI ModeCPOLCPHASCLK IdleData SampledTypical Parts
Mode 000LowRising edgeBMI088, SX1276, SX1280, MAX31855, NOR Flash
Mode 101LowFalling edgeSelected TI / ADI precision ADCs
Mode 210HighFalling edgeLegacy shift-register peripherals
Mode 311HighRising edgeADXL345, LSM6DSO, BMI088 (0 or 3)

Common SPI bring-up bugs

BugCause & fix
Dummy byte on readParts 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-assertionRaising 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 mismatchReading 0xFF or bit-shifted chip IDs (e.g. 0xD0 instead of 0x68) usually means CPHA is inverted.