ESP32-C3 IDF5.0串口报错

Moderator: ESP_Bob

alphasion
Posts: 7
Joined: Sat Apr 15, 2023 9:12 am

ESP32-C3 IDF5.0串口报错

Postby alphasion » Sat Apr 15, 2023 9:16 am

  1. uart_config_t uart_config = {
  2.         .baud_rate = 115200,
  3.         .data_bits = UART_DATA_8_BITS,
  4.         .parity = UART_PARITY_DISABLE,
  5.         .stop_bits = UART_STOP_BITS_1,
  6.         .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
  7.         .source_clk = UART_SCLK_DEFAULT
  8.     };
  9.     uart_param_config(UART_NUM_1, &uart_config);
  10.     uart_set_pin(UART_NUM_1, GPIO_NUM_7, GPIO_NUM_6, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
  11.     uart_driver_install(UART_NUM_1, 16, 0, 0, NULL, 0);
  12.    
  13.     char* send_check = "AT\r\n";
  14.     uart_write_bytes(UART_NUM_1, send_check, strlen(send_check));
  15.     char recv_check[128];
  16.     uart_read_bytes(UART_NUM_1, &recv_check, 128, 100);
  17.     ESP_LOGI(TAG, "dataIn:%s", &recv_check);
这是我根据example写出来的代码,但是会报错
  1. [0;31mE (253) uart: uart_driver_install(1562): uart rx buffer length error[0m
  2. [0;31mE (253) uart: uart_write_bytes(1244): uart driver error[0m
  3. [0;31mE (263) uart: uart_read_bytes(1281): uart driver error[0m
  4. [0;32mI (263) scan: dataIn:[0m
根据报错,uart_driver_install的缓存大小已经从16设置到128,都是如此,请问原因在哪

yake827
Posts: 43
Joined: Mon Aug 09, 2021 7:51 am

Re: ESP32-C3 IDF5.0串口报错

Postby yake827 » Tue Apr 18, 2023 9:00 am

你应该把 rx_buffer_size 配置为比 FIFO 值 128 要大,一般建议1024.
这个是软件的Buffer值,也就是UART收到数据会先先从FIFO缓存到这个buffer里面,然后你read的时候可以取出来

alphasion
Posts: 7
Joined: Sat Apr 15, 2023 9:12 am

Re: ESP32-C3 IDF5.0串口报错

Postby alphasion » Thu May 04, 2023 5:12 am

好的,我试试看,谢谢

Who is online

Users browsing this forum: No registered users and 15 guests