From cd6535c27f55ba359450b6a5720801b38df0539d Mon Sep 17 00:00:00 2001 From: stijncarelsbergh Date: Thu, 8 Oct 2026 00:04:27 +0200 Subject: [PATCH] fix(magnetic sensor spi): the data mask must not be a static local `const static word data_mask` is initialised once and then reused by every MagneticSensorSPI instance, so a second sensor with a different bit resolution gets the mask (and therefore the angle) of the first one. Two sensors of different resolution on the same MCU silently read wrong angles. --- src/sensors/MagneticSensorSPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensors/MagneticSensorSPI.cpp b/src/sensors/MagneticSensorSPI.cpp index baaab2de4..e12cbffff 100644 --- a/src/sensors/MagneticSensorSPI.cpp +++ b/src/sensors/MagneticSensorSPI.cpp @@ -166,7 +166,7 @@ word MagneticSensorSPI::read(word angle_register){ register_value = register_value >> (1 + data_start_bit - bit_resolution); //this should shift data to the rightmost bits of the word - const static word data_mask = 0xFFFF >> (16 - bit_resolution); + const word data_mask = 0xFFFF >> (16 - bit_resolution); return register_value & data_mask; // Return the data, stripping the non data (e.g parity) bits }