Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SPI::setClockDivider implementation is incorrect #299

Copy link
Copy link
Closed
@tve

Description

@tve
Issue body actions

The implementation of SPIClass::setClockDivider does not do what it should. For compatibility/history's sake it should interpret the SPI_CLOCK_DIVn relative the original 16Mhz Arduino clock. Instead, it applies the divider to the current SPI device clock.
Specifically:

      spiSettings[idx].clk = spiClkFreq/_divider;

at https://github.com/stm32duino/Arduino_Core_STM32/blob/master/libraries/SPI/src/SPI.cpp#L255 should be replaced by something like

      spiSettings[idx].clk = 16000000/_divider;

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.