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
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
How can I re-configure the UART correctly?