SPI Clock Divider Calculator — prescaler and actual clock

Prescaler settings to hit a target SPI clock without exceeding your peripheral's maximum.

Example: A ÷16 prescaler gives 5.25 MHz from a 84 MHz clock — the fastest that stays within the device's 10 MHz limit.

Check it against real silicon

Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.

Chiprun docs

Formula

f_SPI = f_peripheral / divider

Worked example

A ÷16 prescaler gives 5.25 MHz from a 84 MHz clock — the fastest that stays within the device's 10 MHz limit.

  1. smallest divider with f_clk / divider ≤ f_max

    84 MHz / 16 = 5.25 MHz ≤ 10 MHz

    ÷16

    Rounding up is mandatory — exceeding the slave's maximum is a functional failure, not just an error.

Frequently asked questions

How do I pick an SPI clock divider?

Take the smallest divider whose resulting clock stays at or below the slave's maximum. Because dividers are powers of two on most microcontrollers, you often end up well under the device's limit — that is normal and safe.

Why round up rather than to the nearest divider?

Because the target is a hard maximum, not a nominal value. A UART running 2% fast still works; an SPI slave clocked past its rated maximum returns corrupt data or nothing. Always land at or below the limit.

Which clock feeds the SPI peripheral?

The APB bus clock it sits on, not the core clock. On STM32 parts SPI1 is usually on APB2 and SPI2/3 on APB1, and the two buses often run at different speeds — so the same divider gives different results on different instances.

Why does my SPI device fail at higher clock speeds?

Often signal integrity rather than the divider. The slave's rated maximum assumes a clean edge at its own pin; long traces, missing ground return and capacitive loading all degrade that. Slow the clock to confirm, then fix the layout rather than living with the slower speed.

Related tools