File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -409,10 +409,17 @@ size_t TwoWire::write(uint8_t ucData) {
409
409
}
410
410
411
411
if (_slave) {
412
- // Wait for a spot in the TX FIFO
413
- while (0 == (_i2c->hw ->status & (1 << 1 ))) { /* noop wait */ }
414
- _i2c->hw ->data_cmd = ucData;
415
- return 1 ;
412
+ // Wait for a spot in the TX FIFO and return in case of timeout
413
+ auto end = make_timeout_time_ms (_timeout);
414
+ while ((i2c_get_write_available (_i2c) == 0 ) && !time_reached (end)) { /* noop wait */ }
415
+
416
+ if (i2c_get_write_available (_i2c) > 0 ) {
417
+ _i2c->hw ->data_cmd = ucData;
418
+ return 1 ;
419
+ } else {
420
+ _handleTimeout (_reset_with_timeout);
421
+ return 0 ;
422
+ }
416
423
} else {
417
424
if (!_txBegun || (_buffLen == sizeof (_buff))) {
418
425
return 0 ;
You can’t perform that action at this time.
0 commit comments