Skip to content

Commit 25b9ca8

Browse files
Only call Wire.onReceive if data is available (#423)
The Pico HW seems to generate an interrupt on the end of every I2C write cycle, even if the slave address wasn't actually targeted. This would cause the onReceive method to be called with a 0-len parameter for every write on the I2C bus. Now, only call onReceive if there is 1 or more bytes of data available.
1 parent d5ddf4c commit 25b9ca8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void TwoWire::onIRQ() {
146146
_i2c->hw->clr_start_det;
147147
}
148148
if (_i2c->hw->intr_stat & (1 << 9)) {
149-
if (_onReceiveCallback) {
149+
if (_onReceiveCallback && _buffLen) {
150150
_onReceiveCallback(_buffLen);
151151
}
152152
_buffLen = 0;

0 commit comments

Comments
 (0)