Skip to content

Commit 6c9fc4f

Browse files
committed
Wire: handle arbitration lost with a retry
1 parent 522beff commit 6c9fc4f

File tree

1 file changed

+8
-1
lines changed
  • libraries/Wire/src/utility

1 file changed

+8
-1
lines changed

libraries/Wire/src/utility/twi.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ uint8_t TWI_MasterWriteRead(uint8_t slave_address,
273273
master_bytesRead = 0;
274274
master_sendStop = send_stop;
275275
master_slaveAddress = slave_address<<1;
276-
276+
277+
trigger_action:
278+
277279
/* If write command, send the START condition + Address +
278280
* 'R/_W = 0'
279281
*/
@@ -301,6 +303,11 @@ uint8_t TWI_MasterWriteRead(uint8_t slave_address,
301303
/* Arduino requires blocking function */
302304
while(master_result == TWIM_RESULT_UNKNOWN) {}
303305

306+
// in case of arbitration lost, retry sending
307+
if (master_result == TWIM_RESULT_ARBITRATION_LOST) {
308+
goto trigger_action;
309+
}
310+
304311
uint8_t ret = 0;
305312
if (master_bytesToRead > 0) {
306313
// return bytes really read

0 commit comments

Comments
 (0)