Espressif ESP32-S2 Programming Manual page 472

Table of Contents

Advertisement

Chapter 2. API Reference
Software Flow Control
levels by using the functions
Communication Mode Selection
can be selected using the function uart_set_mode(). Once a specific mode is selected, the UART driver will
handle the behavior of a connected UART device accordingly. As an example, it can control the RS485 driver chip
using the RTS line to allow half-duplex RS485 communication.
// Setup UART
in
rs485 half duplex mode
ESP_ERROR_CHECK(uart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX));
Using Interrupts
There are many interrupts that can be generated following specific UART states or detected
errors. The full list of available interrupts is provided in ESP32-S2 Technical Reference Manual > UART Controller
(UART) > UART Interrupts and UHCI Interrupts [PDF]. You can enable or disable specific interrupts by calling
uart_enable_intr_mask()
is available as UART_INTR_MASK.
By default, the
uart_driver_install()
age the Tx and Rx ring buffers and provides high-level API functions like events (see below). It is also possi-
ble to register a lower level interrupt handler instead using uart_isr_register(), and to free it again using
uart_isr_free(). Some UART driver functions which use the Tx and Rx ring buffers, events, etc. will not
automatically work in this case - it is necessary to handle the interrupts directly in the ISR. Inside the custom handler
implementation, clear the interrupt status bits using uart_clear_intr_status().
The API provides a convenient way to handle specific interrupts discussed in this document by wrapping them into
dedicated functions:
• Event detection: There are several events defined in
user application using the FreeRTOS queue functionality. You can enable this functionality when calling
uart_driver_install()
found in peripherals/uart/uart_events.
• FIFO space threshold or transmission timeout reached: The Tx and Rx FIFO buffers can trigger an inter-
rupt when they are filled with a specific number of characters, or on a timeout of sending or receiving data. To
use these interrupts, do the following:
– Configure respective threshold values of the buffer length and timeout by entering them in the structure
uart_intr_config_t
– Enable
the
uart_enable_rx_intr()
– Disable these interrupts using the corresponding functions
uart_disable_rx_intr()
• Pattern detection: An interrupt triggered on detecting a 'pattern' of the same character being received/sent re-
peatedly for a number of times. This functionality is demonstrated in the example peripherals/uart/uart_events.
It can be used, e.g., to detect a command string followed by a specific number of identical characters (the'pat-
tern') added at the end of the command string. The following functions are available:
– Configure and enable this interrupt using uart_enable_pattern_det_intr()
– Disable the interrupt using
Macros
The API also defines several macros. For example,
FIFO buffers;
UART_BITRATE_MAX
Deleting a Driver
If the communication established with
the driver can be removed to free allocated resources by calling uart_driver_delete().
Espressif Systems
If the hardware flow control is disabled, you can manually set the RTS and DTR signal
uart_set_rts()
and
The UART controller supports a number of communication modes. A mode
or
uart_disable_intr_mask()
function installs the driver's internal interrupt handler to man-
described in
Driver
and calling
uart_intr_config()
interrupts
using
uart_disable_pattern_det_intr()
gives the maximum baud rate supported by the UART controllers, etc.
Submit Document Feedback
uart_set_dtr()
respectively.
respectively. The mask of all interrupts
uart_event_type_t
Installation. An example of using Event detection can be
the
functions
uart_enable_tx_intr()
uart_disable_tx_intr()
UART_FIFO_LEN
uart_driver_install()
461
that may be reported to a
defines the length of hardware
is no longer required,
Release v4.4
and
or

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF