From 864597198196c8dd2fed999daf02e4f889238cbc Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 5 Apr 2021 15:15:09 +0300 Subject: [PATCH] Fix delayMicroseconds() to use 64bit period fixes: https://github.com/espressif/arduino-esp32/issues/5000 --- cores/esp32/esp32-hal-misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 4be22160..e640b36a 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -160,15 +160,15 @@ void delay(uint32_t ms) void ARDUINO_ISR_ATTR delayMicroseconds(uint32_t us) { - uint32_t m = micros(); + uint64_t m = (uint64_t)esp_timer_get_time(); if(us){ - uint32_t e = (m + us); + uint64_t e = (m + us); if(m > e){ //overflow - while(micros() > e){ + while((uint64_t)esp_timer_get_time() > e){ NOP(); } } - while(micros() < e){ + while((uint64_t)esp_timer_get_time() < e){ NOP(); } }