ESP32 - Uart receive problem (Doubled first byte)

antos1726
Posts: 2
Joined: Mon Jul 20, 2020 6:07 pm

ESP32 - Uart receive problem (Doubled first byte)

Postby antos1726 » Mon Jul 20, 2020 6:43 pm

Hi,

Since few weeks im trying to solve problem with receiving data by UART.
I'll try to describe my problem and observations.
When i'm sending any data (ANY SPEED tried all between 19200-921600) to ESP i'm receiving first sent byte twice while the last one is lost.
Everythink works well with optimization -Odebug, problem occurs when i changed optimization to -o2.

Let's say im sending:
0x01 0x02 0x03 0x04 0x05
Then im receiving:
0x01 0x01 0x02 0x03 0x04

Yesterday i realized that its connected with core speed as follows:
240MHz clock speed // -Odebug WORKS FINE
240MHz clock speed // -O2 PROBLEM
160MHz clock speed // -Odebug WORKS FINE
160MHz clock speed // -O2 WORKS FINE

Problem occurs on any UART 0/1
To be sure i took fresh example UART_ECHO (code pasted below), without any modifications.
Looks same, works fine on o2/oD 160MHz but on 240MHz ond o2 causes problem.

Im using ESP-IDF v4.1-dev-1533-g9dbb7526c // I'll try on another SDK version and post results here.
I have tried many different modules from different vendors and problem occurs always.

Have any of you has similar problem ?

[Codebox]
static void echo_task(void *arg)
{
/* Configure parameters of an UART driver,
* communication pins and install the driver */
uart_config_t uart_config = {
.baud_rate = 19200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
};
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);

// Configure a temporary buffer for the incoming data
uint8_t *data = (uint8_t *)malloc(BUF_SIZE);

while (1)
{
// Read data from the UART
int len = uart_read_bytes(UART_NUM_1, data, BUF_SIZE, 20 / portTICK_RATE_MS);
// Write data back to the UART
uart_write_bytes(UART_NUM_1, (const char *)data, len);
}
}

void app_main(void)
{
xTaskCreate(echo_task, "uart_echo_task", 8192, NULL, 10, NULL); // i only increased STACK SIZE
}
[/Codebox]

Yours Mathew

martinloren
Posts: 4
Joined: Fri Nov 13, 2020 2:17 pm

Re: ESP32 - Uart receive problem (Doubled first byte)

Postby martinloren » Fri Nov 13, 2020 2:20 pm

Same problem.


martinloren
Posts: 4
Joined: Fri Nov 13, 2020 2:17 pm

Re: ESP32 - Uart receive problem (Doubled first byte)

Postby martinloren » Wed Nov 18, 2020 4:22 pm

It works, great! :D

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], Majestic-12 [Bot] and 121 guests