UART
What should be considered when using UART0 as the communication port on ESP32?
- In general,
UART0is not recommended as a normal communication port because it is the default log output UART. - If the chip does not have enough UART resources, or the hardware design can no longer be changed, and
UART0must be used for normal communication, refer to the suggestions below.
Software side: prevent logs from interfering with serial communication. By default, UART0 output comes from three places.
- The first is the first-stage bootloader (
ROM firmware) log. At power-on,MTDOcan be pulled low to suppress ROM log output.- The second is the second-stage bootloader log. In
menuconfig, setBootloader config->Bootloader log verbositytoNo output.- The third is the application log. In
menuconfig, setComponent config->Log output->Default log verbositytoNo output.
Hardware side:
- During firmware download, make sure no other device interferes with
UART0. If another device is connected, it may affect downloading. It is recommended to reserve a0 ohmresistor between ESP32 and the other device so it can be disconnected when needed.
How can the UART baud rate be changed dynamically on ESP32 and take effect immediately?
You can use the uart_set_baudrate() API to change the UART baud rate dynamically.
See the API documentation.
How can the output port of UART0 be changed?
This can be configured in menuconfig:
idf.py menuconfig -> Component config -> Common ESP-related -> Channel for console output (custom UART)
Can UART0 on ESP32 be used both for log output and for receiving input from a PC console?
Yes. UART0 log output only needs the TXD0 pin, while PC console input only needs the RXD0 pin. You can verify this based on the esp-idf/examples/system/console/basic example.
Does ESP32 support the UART IRDA operating mode?
ESP32 hardware supports the UART IRDA operating mode, but there is currently no official software example for it.
When UART resources are limited, is GPIO-based software UART supported?
You can test this based on the soft_uart example in ESP-IDF.
On ESP32-C6, can UART and LP UART be used at the same time when the chip is not in DeepSleep?
Yes. As long as LP Core is enabled, LP UART can be used. See the example: esp-idf/examples/system/ulp/lp_core/lp_uart.