aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire/src/utility
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2020-06-11 15:39:45 +0200
committerMartino Facchin <m.facchin@arduino.cc>2020-06-11 15:39:52 +0200
commitf1fe5e8f08a54c053e12d84810a62e677a69294e (patch)
tree0821091f033c5c6250331c27ee8725480c280353 /libraries/Wire/src/utility
parent38ff552087efdbe0d98a88e9f74bfeb5e1504997 (diff)
Wire: improve comments on timeout
Diffstat (limited to 'libraries/Wire/src/utility')
-rw-r--r--libraries/Wire/src/utility/twi.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/libraries/Wire/src/utility/twi.c b/libraries/Wire/src/utility/twi.c
index b3096c6..5539633 100644
--- a/libraries/Wire/src/utility/twi.c
+++ b/libraries/Wire/src/utility/twi.c
@@ -413,7 +413,9 @@ void twi_stop(void)
// wait for stop condition to be exectued on bus
// TWINT is not set after a stop condition!
- volatile uint32_t counter = twi_timeout_us/10ul; // approximate the timeout
+ // We cannot use micros() from an ISR, so approximate the timeout with cycle-counted delays
+ const uint8_t us_per_loop = 8;
+ uint32_t counter = (twi_timeout_us + us_per_loop - 1)/us_per_loop; // Round up
while(TWCR & _BV(TWSTO)){
if(twi_timeout_us > 0ul){
if (counter > 0ul){