Chapter 2. API Reference
const
uart_port_t uart_num
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_CTS_RTS,
.rx_flow_ctrl_thresh
};
// Configure UART parameters
ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
Multiple Steps
Configure specific parameters individually by calling a dedicated function from the table given
below. These functions are also useful if re-configuring a single parameter.
Table 5: Functions for Configuring specific parameters individually
Parameter to Configure
Baud rate
Number of transmitted bits
Parity control
Number of stop bits
Hardware flow control mode
Communication mode
Each of the above functions has a _get_ counterpart to check the currently set value. For example, to check the
current baud rate value, call uart_get_baudrate().
Setting Communication Pins
the other UART device will be connected. For this, call the function
numbers to which the driver should route the Tx, Rx, RTS, and CTS signals. If you want to keep a currently allocated
pin number for a specific signal, pass the macro UART_PIN_NO_CHANGE.
The same macro should be specified for pins that will not be used.
// Set UART pins(TX: IO4, RX: IO5, RTS: IO18, CTS: IO19)
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, 4, 5, 18, 19));
Driver
Installation
Once
uart_driver_install()
• Size of Tx ring buffer
• Size of Rx ring buffer
• Event queue handle and size
• Flags to allocate an interrupt
The function will allocate the required internal resources for the UART driver.
// Setup UART buffered IO with event queue
const
int
uart_buffer_size
QueueHandle_t uart_queue;
// Install UART driver using an event queue here
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_1, uart_buffer_size, \
Once this step is complete, you can connect the external UART device and check the communication.
Espressif Systems
=
UART_NUM_1;
=
{
=
122,
Function
uart_set_baudrate()
uart_set_word_length()
uart_set_parity()
uart_set_stop_bits()
uart_set_hw_flow_ctrl()
uart_hw_flowcontrol_t
uart_set_mode()
After setting communication parameters, configure the physical GPIO pins to which
the
communication
pins
and specify the following parameters:
=
(1024
*
2);
uart_buffer_size, 10, &uart_queue, 0));
459
Submit Document Feedback
selected out of
uart_word_length_t
selected out of
uart_parity_t
selected out of
uart_stop_bits_t
selected
selected out of
uart_mode_t
uart_set_pin()
are
set,
install
out
of
and specify the GPIO pin
the
driver
by
calling
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?