help delayMicroseconds() on esp?
Posted: Mon May 10, 2021 1:04 pm
by Simepy
Hello everyone, I'm transferring a project from the arduino to the ESP32, is there a command to insert the delayMicroseconds () function as in the arduino?
because it seems to me that delayMicroseconds does not work on esp or am I wrong?
is there something like this for ESP?
Re: help delayMicroseconds() on esp?
Posted: Thu Jul 29, 2021 3:01 pm
by mbratch
Are you using the Arduino platform for ESP32 development? If so, I think `delayMicroseconds()` is available.
Re: help delayMicroseconds() on esp?
Posted: Wed Aug 04, 2021 12:36 pm
by dmaxben
delayMicroseconds() works in arduino.
For ESP-IDF, you can use this:
Code: Select all
unsigned long IRAM_ATTR micros()
{
return (unsigned long)(esp_timer_get_time());
}
void IRAM_ATTR delayMicros(uint32_t us)
{
uint32_t m = micros();
if (us)
{
uint32_t e = (m + us);
if (m > e)
{ //overflow
while (micros() > e)
{
NOP();
}
}
while (micros() < e)
{
NOP();
}
}
}