Skip to content

Commit 380fccf

Browse files
committed
Fix SPI register masking in busWriteBuf
Correct the SPI register address masking in busWriteBuf() to clear the MSB instead of setting it. For SPI protocol, the MSB indicates read (1) or write (0) operations. Write operations should use (reg & 0x7F) to clear the MSB, not (reg | 0x80) which sets it. This matches the correct implementation in busWrite() at line 318 which uses (reg & 0x7F) for write operations. Note: This bug affects theoretical future SPI devices using buffer writes. Current devices using busWriteBuf() are all I2C-based (VL53L0X, VL53L1X, MLX90393, TERARANGER_EVO, US42 rangefinders) and are unaffected. Fixes #10674
1 parent 0e9f842 commit 380fccf

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/main/drivers/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ bool busWriteBuf(const busDevice_t * dev, uint8_t reg, const uint8_t * data, uin
283283
return spiBusWriteBuffer(dev, reg, data, length);
284284
}
285285
else {
286-
return spiBusWriteBuffer(dev, reg | 0x80, data, length);
286+
return spiBusWriteBuffer(dev, reg & 0x7F, data, length);
287287
}
288288
#else
289289
return false;

0 commit comments

Comments
 (0)