How to re-configure UART

ci4rail
Posts: 4
Joined: Thu Sep 02, 2021 1:49 pm

How to re-configure UART

Postby ci4rail » Tue Oct 12, 2021 11:07 am

Hi,
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?

grs_26
Posts: 1
Joined: Mon Dec 11, 2023 12:48 pm

Re: How to re-configure UART

Postby grs_26 » Mon Dec 11, 2023 12:52 pm

Hey @ci4rail, were you able to reconfigure your UART ?

Who is online

Users browsing this forum: No registered users and 105 guests