Skip to content

Commit a3a5aba

Browse files
Fix Wire I2C restart handling (earlephilhower#586)
Fixes earlephilhower#585 On an I2C bus restart, call the onReceive callback and clear the buffer. Thanks to @DWiskow for the debug and patch!
1 parent 8054015 commit a3a5aba

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void TwoWire::begin(uint8_t addr) {
126126
i2c_set_slave_mode(_i2c, true, addr);
127127

128128
// Our callback IRQ
129-
_i2c->hw->intr_mask = (1 << 10) | (1 << 9) | (1 << 6) | (1 << 5) | (1 << 2);
129+
_i2c->hw->intr_mask = (1 << 12) | (1 << 10) | (1 << 9) | (1 << 6) | (1 << 5) | (1 << 2);
130130

131131
int irqNo = I2C0_IRQ + i2c_hw_index(_i2c);
132132
irq_set_exclusive_handler(irqNo, i2c_hw_index(_i2c) == 0 ? _handler0 : _handler1);
@@ -142,6 +142,15 @@ void TwoWire::begin(uint8_t addr) {
142142
}
143143

144144
void TwoWire::onIRQ() {
145+
if (_i2c->hw->intr_stat & (1 << 12)) {
146+
if (_onReceiveCallback && _buffLen) {
147+
_onReceiveCallback(_buffLen);
148+
}
149+
_buffLen = 0;
150+
_buffOff = 0;
151+
_slaveStartDet = false;
152+
_i2c->hw->clr_restart_det;
153+
}
145154
if (_i2c->hw->intr_stat & (1 << 10)) {
146155
_buffLen = 0;
147156
_buffOff = 0;

0 commit comments

Comments
 (0)