help delayMicroseconds() on esp?

Simepy
Posts: 1
Joined: Mon May 10, 2021 12:55 pm

help delayMicroseconds() on esp?

Postby Simepy » Mon May 10, 2021 1:04 pm

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?

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: help delayMicroseconds() on esp?

Postby mbratch » Thu Jul 29, 2021 3:01 pm

Are you using the Arduino platform for ESP32 development? If so, I think `delayMicroseconds()` is available.

dmaxben
Posts: 108
Joined: Thu Nov 16, 2017 6:04 pm

Re: help delayMicroseconds() on esp?

Postby dmaxben » Wed Aug 04, 2021 12:36 pm

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();
        }
    }
}

Who is online

Users browsing this forum: No registered users and 19 guests