Skip to content

Commit 265d24c

Browse files
committed
Reducing excessive I2C communication timeout (added however the possibility to set the timeout to custom value)
1 parent 989073d commit 265d24c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

libraries/Wire/Wire.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ TwoWire::TwoWire(int scl, int sda, WireAddressMode_t am /*= ADDRESS_MODE_7_BITS*
191191
is_master(true),
192192
is_sci(false),
193193
address_mode(am),
194-
timeout(1000),
194+
timeout(1),
195195
transmission_begun(false),
196196
data_too_long(false),
197197
rx_index(0),
@@ -835,7 +835,11 @@ void TwoWire::flush(void) {
835835
while(bus_status != WIRE_STATUS_TX_COMPLETED && bus_status != WIRE_STATUS_TRANSACTION_ABORTED) {}
836836
}
837837

838-
838+
/* -------------------------------------------------------------------------- */
839+
void TwoWire::setTimeout(unsigned int t) {
840+
/* -------------------------------------------------------------------------- */
841+
timeout = t;
842+
}
839843

840844

841845
#if WIRE_HOWMANY > 0

libraries/Wire/Wire.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class TwoWire : public arduino::HardwareI2C {
125125

126126
void setBusStatus(WireStatus_t);
127127

128+
void setTimeout(unsigned int t);
129+
128130
inline size_t write(unsigned long n) { return write((uint8_t)n); }
129131
inline size_t write(long n) { return write((uint8_t)n); }
130132
inline size_t write(unsigned int n) { return write((uint8_t)n); }

0 commit comments

Comments
 (0)