Fix SPI register masking in busWriteBuf #11242
Open
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User description
Summary
Corrects SPI register address masking in busWriteBuf() to clear the MSB instead of setting it.
Problem
For SPI protocol, the MSB indicates read (1) or write (0) operations. The busWriteBuf() function incorrectly used
reg | 0x80which sets the MSB, when it should usereg & 0x7Fto clear it for write operations.This is inconsistent with the correct implementation in busWrite() at line 318.
Solution
Change line 286 from:
To:
Impact
Current hardware: None - all devices using busWriteBuf() are I2C-based (VL53L0X, VL53L1X, MLX90393, TERARANGER_EVO, US42 rangefinders).
Future hardware: Prevents silent failures if SPI devices use multi-byte buffer writes.
This is a defensive fix for code correctness.
Fixes #10674
PR Type
Bug fix
Description
Corrects SPI register masking in busWriteBuf() to clear MSB for writes
Changes register operation from OR (0x80) to AND (0x7F) masking
Aligns implementation with correct busWrite() function behavior
Prevents future silent failures in SPI multi-byte buffer writes
Diagram Walkthrough
File Walkthrough
bus.c
Fix SPI write register masking operationsrc/main/drivers/bus.c
reg | 0x80toreg & 0x7FinbusWriteBuf()
I2C-based