ESP32 s3 UART2 loopback response is abnormal
Posted: 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.
^ Normal output by defining the uart_num as UART_NUM_1 or UART_NUM_0
^ Abnormal output by defining the uart_num as UART_NUM_2
I would like to ask if there is a bug in UART2 of ESP s3 or I made some mistake. Thank you.
- //ESP-IDF Components
- #include "esp_log.h"
- #include "driver/uart.h"
- #define uart_num UART_NUM_2 // UART_NUM_1 and UART_NUM_0 work, UART_NUM_2 did not
- char input[1];
- char output[1];
- void setup() {
- 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_CTS_RTS,
- .rx_flow_ctrl_thresh = 122,
- };
- // Configure UART parameters
- ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
- ESP_ERROR_CHECK(uart_set_pin(uart_num, GPIO_NUM_33, GPIO_NUM_34, GPIO_NUM_NC, GPIO_NUM_NC));
- const int uart_buffer_size = (1024 * 2);
- QueueHandle_t uart_queue;
- // Install UART driver using an event queue here
- ESP_ERROR_CHECK(uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
- uart_set_loop_back(uart_num, 1);
- }
- void loop() {
- input[0] = 0;
- for (int i = 0; i < 0x100; i++) {
- uart_write_bytes(uart_num, input, 1);
- delay(1000);
- uart_read_bytes(uart_num, output, 1, 0xffff);
- ESP_LOGE("input", "%x, %x", i, *input); //input[0] should be equal to i
- ESP_LOGE("output", "%x, %x", i, *output); //output[0] should be equal to i
- input[0]++;
- }
- }
^ Abnormal output by defining the uart_num as UART_NUM_2