From f1fe5e8f08a54c053e12d84810a62e677a69294e Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 11 Jun 2020 15:39:45 +0200 Subject: Wire: improve comments on timeout --- libraries/Wire/src/utility/twi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libraries/Wire/src/utility') 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){ -- cgit v1.2.3-18-g5258