-
-
Notifications
You must be signed in to change notification settings - Fork 99
Closed
Labels
conclusion: resolvedIssue was resolvedIssue was resolvedtopic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
Issue: Unexpected SPI Clock Speed Behavior on Arduino R4
Source: Arduino Forum Discussion ITA
Summary
When using the SPI library on Arduino R4, the SPI clock speed does not behave as expected after reinitialization:
- SPI is initialized with
SPI.begin()and configured to 20MHz usingSPISettings. - After calling
SPI.end()and reinitializing, the SPI clock defaults to 1MHz, ignoring the previous 20MHz setting. - This issue occurs only when reusing the same
SPISettingsobject without modifying it.
Problematic Code Example
SPI.begin();
mySettings = SPISettings(20000000, MSBFIRST, SPI_MODE0);
SPI.beginTransaction(mySettings);
SPI.transfer(0x00);
SPI.endTransaction();
SPI.end();
// Repeating the same cycle causes SPI to default to 1MHzTechnical Insight
- The
ArduinoCore-renesasimplementation resets the SPI clock to 1MHz every timeSPI.begin()is called. SPI.beginTransaction()updates the clock only if the newSPISettingsdiffer from the previous ones.- Reusing the same
SPISettingsobject prevents the clock from being updated, resulting in a default 1MHz speed.
Context
The user needs to frequently release SPI pins and dynamically change SPI configurations during runtime, which requires repeated calls to SPI.begin() and SPI.end().
Metadata
Metadata
Assignees
Labels
conclusion: resolvedIssue was resolvedIssue was resolvedtopic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project