Skip to content
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

SPI default configuration fails #106

Open
JojoS62 opened this issue Jun 30, 2021 · 1 comment
Open

SPI default configuration fails #106

JojoS62 opened this issue Jun 30, 2021 · 1 comment

Comments

@JojoS62
Copy link

JojoS62 commented Jun 30, 2021

The SPI configuration is using a SPISettings class from ArduinoCore-API, which is converted to a temporary object of type SPISettingsMegaAVR .
This conversion in

void config(SPISettings settings) {
config(SPISettingsMegaAVR(settings));
}
is using this constructor:
SPISettingsMegaAVR(SPISettings& x) { SPISettingsMegaAVR(x.getClockFreq(), x.getBitOrder(), x.getDataMode()); }

There the SPISettingsMegaAVR object is created on the stack, and then destroyed. It does not initialize the SPISettingsMegaAVR that is used in the config() call.
This problem is hidden because it works by sudden and is compiler version dependant. There is a discussion and some test code to reproduce the problem in https://forum.arduino.cc/t/houston-spi-has-a-problem-with-avr-gcc-11-1-0
The assumption that this is a compiler problem was false, its simply an uninitialized SPISettingsMegaAVR object.

A solution would be to use constructor delegation as explained here:
https://www.geeksforgeeks.org/constructor-delegation-c/

@mikrocoder
Copy link

mikrocoder commented Jun 30, 2021

Hi,

Thanks Jojo for the description of the problem. This causes the SPI registers to be overwritten with random numbers in the begin() method. Likewise in the beginTransaction(...) method.

In April 2020 the API was changed. What was the reason for this? That it is better understood.
port to ArduinoAPI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants