Skip to content

Commit 9113831

Browse files
alextsamsandeepmistry
authored andcommitted
Fix I2C lock-up when endTransmission() is called with empty txBuffer
The problem (at least in the case of the I2C scanner that I had to deal with) was related to an empty tx buffer, so the LASTTX event never occurres, resulting into an endless loop.
1 parent 41f2aad commit 9113831

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libraries/Wire/Wire_nRF52.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ uint8_t TwoWire::endTransmission(bool stopBit)
222222
while(!_p_twim->EVENTS_TXSTARTED && !_p_twim->EVENTS_ERROR);
223223
_p_twim->EVENTS_TXSTARTED = 0x0UL;
224224

225-
while(!_p_twim->EVENTS_LASTTX && !_p_twim->EVENTS_ERROR);
225+
if (txBuffer.available()) {
226+
while(!_p_twim->EVENTS_LASTTX && !_p_twim->EVENTS_ERROR);
227+
}
226228
_p_twim->EVENTS_LASTTX = 0x0UL;
227229

228230
if (stopBit || _p_twim->EVENTS_ERROR)

0 commit comments

Comments
 (0)