Closed sylque closed 4 months ago
Hey, thanks for reporting it, and yes, it should be changed.
I'm not sure it is the correct approach in terms of your particular problem regarding thread safety, but if it works for you, then so much the better.
Its also necessary to change it just from the point of view of correctness, although the examples and documentation from Arduino isn't very clear, I believe the current version also leads to incorrect SPI behaviour in absence of any multi-threading.
It will be fixed for the next release.
These changes are now on the dev branch of the library. Please let me know if you have a chance to test it on esp32...
Thanks @runger1101001, I confirm the dev branch works well on ESP32.
This code from AS5048A.cpp is not therad-safe on ESP32:
It causes issues if the AS5048A is on the same SPI bus as another device, and both are accessed from separate tasks.
The reason is that the Arduino ESP32 SPI library implements thread safety in
beginTransaction()
andendTransaction()
. SodigitalWrite(nCS)
should be placed inside those two in order to benefit from the mutex.There's an example in
MagneticSensorSPI.cpp
, which doesn't have the issue: