ESP32 s3 UART2 loopback response is abnormal

marco2009
Posts: 1
Joined: Wed Jul 05, 2023 3:35 pm

ESP32 s3 UART2 loopback response is abnormal

Postby marco2009 » Sat Jan 27, 2024 10:53 am

I found the UART_NUM_2 of ESP32 s3 does not work like the other uart ports in my project, therefore I coded the following loopback test in Arduino IDE, and the result are the same; normally "output" should be equal to "input" and "i", but only UART2's "output" gives the previous number as showing in the figures.

I would like to ask if there is a bug in UART2 of ESP s3 or I made some mistake. Thank you.

  1. //ESP-IDF Components
  2. #include "esp_log.h"
  3. #include "driver/uart.h"
  4. #define uart_num UART_NUM_2 // UART_NUM_1 and UART_NUM_0 work, UART_NUM_2 did not
  5. char input[1];
  6. char output[1];
  7. void setup() {
  8.   uart_config_t uart_config = {
  9.     .baud_rate = 115200,
  10.     .data_bits = UART_DATA_8_BITS,
  11.     .parity = UART_PARITY_DISABLE,
  12.     .stop_bits = UART_STOP_BITS_1,
  13.     .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
  14.     .rx_flow_ctrl_thresh = 122,
  15.   };
  16.   // Configure UART parameters
  17.   ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
  18.   ESP_ERROR_CHECK(uart_set_pin(uart_num, GPIO_NUM_33, GPIO_NUM_34, GPIO_NUM_NC, GPIO_NUM_NC));
  19.   const int uart_buffer_size = (1024 * 2);
  20.   QueueHandle_t uart_queue;
  21.   // Install UART driver using an event queue here
  22.   ESP_ERROR_CHECK(uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
  23.   uart_set_loop_back(uart_num, 1);
  24. }
  25.  
  26. void loop() {
  27.   input[0] = 0;
  28.   for (int i = 0; i < 0x100; i++) {
  29.     uart_write_bytes(uart_num, input, 1);
  30.     delay(1000);
  31.     uart_read_bytes(uart_num, output, 1, 0xffff);
  32.     ESP_LOGE("input", "%x, %x", i, *input); //input[0] should be equal to i
  33.     ESP_LOGE("output", "%x, %x", i, *output); //output[0] should be equal to i
  34.     input[0]++;
  35.   }
  36. }
normal.JPG
normal.JPG (33.87 KiB) Viewed 745 times
^ Normal output by defining the uart_num as UART_NUM_1 or UART_NUM_0

uart2.JPG
uart2.JPG (41.61 KiB) Viewed 745 times
^ Abnormal output by defining the uart_num as UART_NUM_2

josephl
Posts: 1
Joined: Thu Feb 01, 2024 8:50 pm

Re: ESP32 s3 UART2 loopback response is abnormal

Postby josephl » Thu Feb 01, 2024 9:04 pm

I am using an ESP32-S3-WROOM-1, also having an issue with UART2. The output of UART2 seems to be delayed, with the data getting "stuck" in the buffer until the next read occurs, causing the output to be offset. This seems to be a bug, which I wouldn't have even considered until I found this post. UART1 works correctly. Not sure how this can get reported and fixed?

Who is online

Users browsing this forum: No registered users and 88 guests