receiving on uart is delayed after calling uart_enable_intr_mask

bewatermyfriendxd
Posts: 21
Joined: Wed Apr 03, 2019 1:29 pm

receiving on uart is delayed after calling uart_enable_intr_mask

Postby bewatermyfriendxd » Fri Oct 22, 2021 1:55 pm

Hello,


I am using esp-idf release version 4.2 on a ESP32-WROOM32-D.

I am currently developing a UART based communication protocol to talk to a vehicle.
Sometimes I want to avoid that the bytes that I send get stored in the UART RxRingBuffer.

Therefore I am calling this functions before calling uart_tx_chars.

Code: Select all

    if((nErr = uart_flush(pstHW->nUART)) != ESP_OK)
    {
        NETLOG_ERROR("uart_flush failed with err-code: %d", nErr);
        return ESP_FAIL;
    }
    if((nErr = uart_disable_intr_mask(pstHW->nUART, UART_IRQ_FLAGS)) != ESP_OK)
    {
        NETLOG_ERROR("uart_disable_intr_mask failed with err-code: %d", nErr);
        return ESP_FAIL;
    }
Later on, when I am ready to receive again, I am calling this functions:

Code: Select all

    if((nErr = uart_flush(pstHW->nUART)) != ESP_OK)
    {
        NETLOG_ERROR("uart_flush failed with err-code: %d", nErr);
        return ESP_FAIL;
    }
    if(uart_enable_intr_mask(pstHW->nUART, UART_IRQ_FLAGS) != ESP_OK)
    {
        NETLOG_ERROR("uart_enable_intr_mask failed");
        return ESP_FAIL;
    }
The problem is the following:

I noticed that after calling uart_enable_intr_mask it takes about 28 ms until the next incoming byte is ready to be received from the ring buffer, even though the sender sends the data 10 ms after uart_enable_intr_mask has been called.

This leads to situations in which I run into protocol timeouts, even though the sender met the timing constraints.

My question is:

Why does it take so long after calling uart_enable_intr_mask that the UART is able to receive again / put the data in the ring buffer.
Do you know of any methods to improve the situation ?

Thank you very much for the help

bewatermyfriendxd
Posts: 21
Joined: Wed Apr 03, 2019 1:29 pm

Re: receiving on uart is delayed after calling uart_enable_intr_mask

Postby bewatermyfriendxd » Mon Nov 01, 2021 3:00 pm

Ive been able to fix the issue.
All I needed to do was call:

Code: Select all

    nError = uart_set_rx_timeout(g_arrDevices[ucDev].stHW.nUART, 1);

    if(nError != ESP_OK)
    {
        NETLOG_ERROR("uart_set_rx_timeout failed for device=%u with err-code: %d", ucDev, nError);
        return ESP_FAIL;
    }
This way, uart rx events are triggered for each byte that is received. Otherwise the uart driver will wait until a certain amount of bytes has been received before generating a rx event.

Who is online

Users browsing this forum: No registered users and 115 guests