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.

MCU SPI PeripheralSTM32 (SPI\_CR1 BR\[2:0\] /2../256)Nordic nRF52840 (SPIM FREQUENCY)ESP32 / ESP32-S3 (SPI\_CLOCK\_REG)RP2040 PL022 (CPSDVSR \* (1+SCR))AVR ATmega (SPR1:0 + SPI2X)Power-of-2 prescalers 2, 4, 8, 16, 32, 64, 128, 256

SPI peripheral clock (MHz)APB1/APB2 clock (STM32) or peri clock

Slave max SCLK (MHz)e.g. 5 MHz (MAX31855), 10 MHz (BMI088), 18 MHz (SX1280)

SPI Mode (CPOL / CPHA)Mode 0 (CPOL=0, CPHA=0)Mode 1 (CPOL=0, CPHA=1)Mode 2 (CPOL=1, CPHA=0)Mode 3 (CPOL=1, CPHA=1)Idle Low (0); sample Rising (leading)

Fastest Safe SCLK 5.25 MHz BR\[2:0\] = 0b011 (/16)

Byte Transfer Time 1.52 us 8 SCLK cycles (excluding CS setup)

Selected SPI Mode Mode 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.                                                                         |

[Guide: SPI bus fault testing](https://circuittwin.ai/guides/spi-bus-fault-testing) [Twin: Bosch BMI088 IMU](https://circuittwin.ai/twins/bmi088) [Twin: MAX31855 Thermocouple](https://circuittwin.ai/twins/max31855) [Twin: Semtech SX1280 Radio](https://circuittwin.ai/twins/sx1280) [Tool: I2C Pull-Up Calculator](https://circuittwin.ai/tools/i2c-pullup-calculator)

> ## Verify SPI chip-select timing and dummy bytes in CI
>
> Run your SPI driver binary against datasheet-generated sensor and radio twins, then inject CS glitches or busy-pin drops.
>
> [Start now](https://app.circuittwin.ai/try) [SPI fault-testing guide](https://circuittwin.ai/guides/spi-bus-fault-testing) [Connect a coding agent](https://circuittwin.ai/docs/agents)
