You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SPI configuration is using a SPISettings class from ArduinoCore-API, which is converted to a temporary object of type SPISettingsMegaAVR .
This conversion in
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.
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
The SPI configuration is using a SPISettings class from ArduinoCore-API, which is converted to a temporary object of type SPISettingsMegaAVR .
This conversion in
ArduinoCore-megaavr/libraries/SPI/src/SPI.h
Lines 179 to 181 in 5717c2a
ArduinoCore-megaavr/libraries/SPI/src/SPI.h
Line 69 in 5717c2a
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/
The text was updated successfully, but these errors were encountered: