ST
A world leader in providing the semiconductor solutions that make a positive contribution to people’s lives, both today and in the future.
You are viewing an older revision! See the latest version
SPI output clock frequency
The SPI output frequency can only be equal to some values. This is due because the SPI output frequency is divided by a prescaler which is equal to 2, 4, 8, 16, 32, 64, 128 or 256. It depends also on the frequency that clocks the SPI peripheral.
In practice, for example on the NUCLEO_F103RB, the SPI1 clock is equal to 72 MHz.
(this value can be seen in the mbed-os\targets\TARGET_STM\TARGET_STM32F1\TARGET_NUCLEO_F103RB\device\system_clock.c file inside the SetSysClock_PLL_HSE function).
So, you can only have these output frequencies: 36 MHz (72 MHz / 2), 18 MHz (72 MHz / 4), 9 MHz, 4.5 MHz, 2.25 MHz, 1.125 MHz, 562 kHz and 281 kHz (72 MHz / 256).
If you want to have a SPI output frequency equal to 1 MHz, you need to pass a value above 1.125 MHz in the frequency method.
For example:
mydevice.frequency(1200000); // real value = 1.125 MHz