diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2020-06-11 15:39:45 +0200 |
---|---|---|
committer | Martino Facchin <m.facchin@arduino.cc> | 2020-06-11 15:39:52 +0200 |
commit | f1fe5e8f08a54c053e12d84810a62e677a69294e (patch) | |
tree | 0821091f033c5c6250331c27ee8725480c280353 /libraries/Wire/src/utility | |
parent | 38ff552087efdbe0d98a88e9f74bfeb5e1504997 (diff) |
Wire: improve comments on timeout
Diffstat (limited to 'libraries/Wire/src/utility')
-rw-r--r-- | libraries/Wire/src/utility/twi.c | 4 |
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){ |