-
Notifications
You must be signed in to change notification settings - Fork 1k
SPI::setClockDivider implementation is incorrect #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
Please explain. Isn't |
Oh yes, you're right. Probably, too much task in // :)
or allow use the real input clock of SPI.
I would guess the first option (as you suggested) is the best. |
I would agree with you, however, I did notice that in the rogerclark core the second interpretation ( |
Hi @tve,
So in fact, it should be possible to divide the clock by any value. Moreover, it is not possible to define SPI_CLOCK_DIVx to match the 16MHz value for avr as SPI frequency depends of system clock configuration. I will update also the wrong comment to avoid any confusion. |
Fix stm32duino#299 Signed-off-by: Frederic.Pillon <[email protected]>
As said in Arduino API: https://www.arduino.cc/en/Reference/SPISetClockDivider "On the Due, the system clock can be divided by values from 1 to 255. The default value is 21, which sets the clock to 4 MHz like other Arduino boards." So in fact, it should be possible to divide the clock by any value. Then HAL will use the best prescaler to fit requested Freq. Moreover, it is not possible to define SPI_CLOCK_DIVx to match the 16MHz value for avr as SPI frequency depends of system clock configuration. Fix stm32duino#299 Signed-off-by: Frederic.Pillon <[email protected]>
As said in Arduino API: https://www.arduino.cc/en/Reference/SPISetClockDivider "On the Due, the system clock can be divided by values from 1 to 255. The default value is 21, which sets the clock to 4 MHz like other Arduino boards." So in fact, it should be possible to divide the clock by any value. Then HAL will use the best prescaler to fit requested Freq. Moreover, it is not possible to define SPI_CLOCK_DIVx to match the 16MHz value for avr as SPI frequency depends of system clock configuration. Fix stm32duino#299 Signed-off-by: Frederic.Pillon <[email protected]>
The implementation of
SPIClass::setClockDivider
does not do what it should. For compatibility/history's sake it should interpret theSPI_CLOCK_DIVn
relative the original 16Mhz Arduino clock. Instead, it applies the divider to the current SPI device clock.Specifically:
at https://github.com/stm32duino/Arduino_Core_STM32/blob/master/libraries/SPI/src/SPI.cpp#L255 should be replaced by something like
Of course other ways to implement the same notion are also possible. If you want to look at what one of the official ARM cores does, see https://github.com/arduino/ArduinoCore-sam/blob/master/libraries/SPI/src/SPI.h#L138-L146 and https://github.com/arduino/ArduinoCore-sam/blob/master/libraries/SPI/src/SPI.cpp#L167-L173, i.e., they define the divider values such that it comes out right, which probably works because they fix the processor's clock speed.
The text was updated successfully, but these errors were encountered: