embeddedspihalbaud-rate

The best SPI Baudrate Prescaler


my question partains SPI speed. How do i know which prescaler to use based? should it be based on the device that i would like to talk to over the protocol?

An example using the HAL library is that it has the following prescaler variables

Lower prescaler variables result in a faster datarate. But how do i know which one to use or which one gives the best optimal results?


Solution

  • You need to read the documentation of the device you like to talk to. It has a maximum clock rate.

    Then you need to look up the system clock of your system, how this is used by the SPI module, and how the prescaler divides this clock. You could write down a table with a line for each prescaler option.

    Now estimate how fast you need to read the device to meet the requirements of your application. For this you need to look up the number of bytes to transmit including adressing and commands and so on.

    Then compare the resulting SPI clocks with the maximum allowed clock of the device. Use the one that is fast enough for your application and below the maximum.

    If you need a higher clock than the device's maximum, it is not possible to satisfy the requirements.