aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire/src/utility/twi.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/Wire/src/utility/twi.c')
-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){