Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
I'm using ESP32-S3 and encountering occasional delays when sending more than 128 bytes (e.g., 200 bytes) via uart_write_bytes().
Normally, the notification completes within about 10ms, but sometimes it takes between 50ms and 200ms.
Even after setting the task priority to the maximum (24), the issue still occurs.
I suspect that some interrupt handling inside ESP-IDF might be causing this behavior.
Does anyone know what might be causing this or how to resolve it?
Best regards,
Normally, the notification completes within about 10ms, but sometimes it takes between 50ms and 200ms.
Even after setting the task priority to the maximum (24), the issue still occurs.
I suspect that some interrupt handling inside ESP-IDF might be causing this behavior.
Does anyone know what might be causing this or how to resolve it?
Best regards,
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
What's your baud rate? I'm thinking that normally the data fits into the FIFO buffer of the UART, but <128 bytes won't fit and as such the write blocks until the first block of data has been sent.
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
The baud rate is 115200. Since the TX buffer size specified in uart_driver_install() is 0, I assume the FIFO buffer is using the default size of 128 bytes.
-
MicroController
- Posts: 2669
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
Baudrate 115200 = 11520 bytes/s max -> 1ms/11.5 bytes
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
This issue involves sending 200 bytes of data, for example.
After transmitting the first 128 bytes, an interval of 50 to 200 milliseconds occurs,
followed by the transmission of the remaining 72 bytes.
This behavior has been confirmed using an oscilloscope.
We would like to understand why this behavior occurs and request a solution.
After transmitting the first 128 bytes, an interval of 50 to 200 milliseconds occurs,
followed by the transmission of the remaining 72 bytes.
This behavior has been confirmed using an oscilloscope.
We would like to understand why this behavior occurs and request a solution.
-
MicroController
- Posts: 2669
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
You say that something like
causes a 50-200ms pause on the UART TX in the middle of the transmission?
More code needed.
Code: Select all
uart_write_bytes(UART_PORT,buffer,200);
More code needed.
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
Yes,the following processing is implemented, causing a pause of 50 to 200 milliseconds during transfer.causes a 50-200ms pause on the UART TX in the middle of the transmission?
The task running this process has the highest priority.
Code: Select all
uart_write_bytes(UART_NUM_1, buffer, 200);
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
Maybe I'm doing something wrong.Yes,the following processing is implemented, causing a pause of 50 to 200 milliseconds during transfer.causes a 50-200ms pause on the UART TX in the middle of the transmission?
The task running this process has the highest priority.Code: Select all
uart_write_bytes(UART_NUM_1, buffer, 200);
Sending 500 bytes, without any intervals.
For example, a screenshot from the analyzer - 120-140 characters.
Code: Select all
static const int RX_BUF_SIZE = 1024;
static const int RX_DATA_SIZE = 550;
static const int TX_DATA_SIZE = 500;
// esp32s3 free pin
#define TXD_PIN (GPIO_NUM_1)
#define RXD_PIN (GPIO_NUM_2)
void init(void)
{
const uart_config_t uart_config = {
.baud_rate = 115200,
.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_DEFAULT,
};
// We won't use a buffer for sending data.
uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, TXD_PIN, TXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// connect RX & TX pin without wire, reeset tx connection
gpio_set_direction(TXD_PIN, GPIO_MODE_INPUT_OUTPUT);
esp_rom_gpio_connect_out_signal(TXD_PIN, UART_PERIPH_SIGNAL(UART_NUM_1, SOC_UART_TX_PIN_IDX), 0, 0);
}
static void tx_task(void *arg)
{
static const char *TX_TASK_TAG = "TX_TASK";
uint8_t* data_txd = (uint8_t*) calloc(TX_DATA_SIZE + 1,1);
//memset(data_txd, 0x55, TX_DATA_SIZE);
esp_log_level_set(TX_TASK_TAG, ESP_LOG_INFO);
while (1) {
const int txBytes = uart_write_bytes(UART_NUM_1, data_txd, TX_DATA_SIZE);
ESP_LOGI("UART_TX_TASK", "Wrote %d bytes", txBytes);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
static void rx_task(void *arg)
{
static const char *RX_TASK_TAG = "RX_TASK";
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
uint8_t* data = (uint8_t*) malloc(RX_DATA_SIZE + 1);
while (1) {
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_DATA_SIZE, 1000 / portTICK_PERIOD_MS);
if (rxBytes > 0) {
data[rxBytes] = 0;
ESP_LOGI(RX_TASK_TAG, "Read %d bytes", rxBytes);
}
}
free(data);
}
void app_main(void)
{
//logic_analyzer_cli();
init();
xTaskCreate(rx_task, "uart_rx_task", 1024 * 4, NULL, 5, NULL);
xTaskCreate(tx_task, "uart_tx_task", 1024 * 4, NULL, 5, NULL);
}
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
Code: Select all
const uart_config_t uart_config = {
.baud_rate = 115200,
.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_DEFAULT,
};
// We won't use a buffer for sending data.
uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);.parity = UART_PARITY_EVEN,
.source_clk = UART_SCLK_APB,
RX_BUF_SIZE * 2・・・18KB
Could these differences be affecting it...?
Could you please try it with the same settings?
Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3
no difference at speeds from 115200 to 1500000The differences from my environment are as follows.
.parity = UART_PARITY_EVEN,
.source_clk = UART_SCLK_APB,
RX_BUF_SIZE * 2・・・18KB
Could these differences be affecting it...?
Could you please try it with the same settings?
Who is online
Users browsing this forum: Bing [Bot], ChatGPT-User and 2 guests
