Skip to content

Commit aac8146

Browse files
Clear I2C status on short slave reads
Fixes #222 The HW needs to have the TXC_ABRT flag cleared when a slave transmission is cut short by the master, or else it will effectively break the I2C bus and never recover.
1 parent 35c974d commit aac8146

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libraries/Wire/Wire.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void TwoWire::begin(uint8_t addr) {
123123
i2c_set_slave_mode(_i2c, true, addr);
124124

125125
// Our callback IRQ
126-
_i2c->hw->intr_mask = (1 << 10) | (1 << 9) | (1 << 5) | (1 << 2);
126+
_i2c->hw->intr_mask = (1 << 10) | (1 << 9) | (1 << 6) | (1 << 5) | (1 << 2);
127127

128128
int irqNo = I2C0_IRQ + i2c_hw_index(_i2c);
129129
irq_set_exclusive_handler(irqNo, i2c_hw_index(_i2c) == 0 ? _handler0 : _handler1);
@@ -139,6 +139,7 @@ void TwoWire::begin(uint8_t addr) {
139139
}
140140

141141
void TwoWire::onIRQ() {
142+
Serial.printf("Wire.IRQ=%08x\n", _i2c->hw->intr_stat);
142143
if (_i2c->hw->intr_stat & (1 << 10)) {
143144
_buffLen = 0;
144145
_buffOff = 0;
@@ -154,6 +155,10 @@ void TwoWire::onIRQ() {
154155
_slaveStartDet = false;
155156
_i2c->hw->clr_stop_det;
156157
}
158+
if (_i2c->hw->intr_stat & (1 << 6)) {
159+
// TX_ABRT
160+
_i2c->hw->clr_tx_abrt;
161+
}
157162
if (_i2c->hw->intr_stat & (1 << 5)) {
158163
// RD_REQ
159164
if (_onRequestCallback) {

0 commit comments

Comments
 (0)