添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I currently using the UART0 on my ESP32S2 for data exchange (while UART1 is used for the console output) and I would like to change its configuration at runtime. First I tried this:

Code: Select all

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_APB,
uart_driver_install(UART_NUM_0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
uart_param_config(UART_NUM_0, &uart_config);
... // Firmware continues. It does not matter whether a data exchange via the UART0 takes place.
uart_config.baud_rate = 9600;
uart_param_config(UART_NUM_0, &uart_config); // changed baud and apply configuration again
This caused the communication via the UART0 to stop working. I tried to exchange data with the UART via picocom. Before the reconfiguration, this worked (-> hardware works fine, no wire problem).
Then I tried deleting and installing the driver again before re-configuring it:

Code: Select all

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_APB,
uart_driver_install(UART_NUM_0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
uart_param_config(UART_NUM_0, &uart_config);
... // Firmware continues. It does not matter whether a data exchange via the UART0 takes place.
uart_config.baud_rate = 9600;
uart_driver_delete(UART_NUM_0);
uart_driver_install(UART_NUM_0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
uart_param_config(UART_NUM_0, &uart_config); // changed baud and apply configuration again
This led to the same problem.
How can I re-configure the UART correctly?