You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Universal Asynchronous Receiver/Transmitter (UART) is a hardware feature that handles communication (i.e., timing requirements and data framing) using widely-adopted asynchronous serial communication interfaces, such as RS232, RS422, RS485. A UART provides a widely adopted and cheap method to realize full-duplex or half-duplex data exchange among different devices.
11
+
A Universal Asynchronous Receiver/Transmitter (UART) is a hardware feature that handles communication (i.e., timing requirements and data framing) using widely-adopted asynchronous serial communication interfaces, such as RS232, RS422, and RS485. A UART provides a widely adopted and cheap method to realize full-duplex or half-duplex data exchange among different devices.
12
12
13
-
The {IDF_TARGET_NAME} chip has {IDF_TARGET_UART_NUM} UART controllers (also referred to as port), each featuring an identical set of registers to simplify programming and for more flexibility.
13
+
The {IDF_TARGET_NAME} chip has {IDF_TARGET_UART_NUM} UART controllers (also referred to as port), each featuring an identical set of registers to simplify programming and add flexibility.
14
14
15
-
Each UART controller is independently configurable with parameters such as baud rate, data bit length, bit ordering, number of stop bits, parity bit etc. All the controllers are compatible with UART-enabled devices from various manufacturers and can also support Infrared Data Association protocols (IrDA).
15
+
Each UART controller is independently configurable with parameters such as baud rate, data bit length, bit ordering, number of stop bits, parity bit, etc. All the controllers are compatible with UART-enabled devices from various manufacturers and can also support Infrared Data Association (IrDA) protocols.
16
16
17
17
Functional Overview
18
18
-------------------
19
19
20
-
The following overview describes how to establish communication between an {IDF_TARGET_NAME} and other UART devices using the functions and data types of the UART driver. The overview reflects a typical programming workflow and is broken down into the sections provided below:
20
+
The overview describes how to establish communication between an {IDF_TARGET_NAME} and other UART devices using the functions and data types of the UART driver. A typical programming workflow is broken down into the sections provided below:
21
21
22
22
1. :ref:`uart-api-setting-communication-parameters` - Setting baud rate, data bits, stop bits, etc.
23
-
2. :ref:`uart-api-setting-communication-pins` - Assigning pins for connection to a device.
24
-
3. :ref:`uart-api-driver-installation` - Allocating {IDF_TARGET_NAME}'s resources for the UART driver.
25
-
4. :ref:`uart-api-running-uart-communication` - Sending / receiving data
23
+
2. :ref:`uart-api-setting-communication-pins` - Assigning pins for connection to a device
24
+
3. :ref:`uart-api-driver-installation` - Allocating {IDF_TARGET_NAME}'s resources for the UART driver
25
+
4. :ref:`uart-api-running-uart-communication` - Sending/receiving data
26
26
5. :ref:`uart-api-using-interrupts` - Triggering interrupts on specific communication events
27
27
6. :ref:`uart-api-deleting-driver` - Freeing allocated resources if a UART communication is no longer required
28
28
@@ -33,7 +33,7 @@ The UART driver's functions identify each of the UART controllers using :cpp:typ
33
33
34
34
.. _uart-api-setting-communication-parameters:
35
35
36
-
Setting Communication Parameters
36
+
Set Communication Parameters
37
37
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38
38
39
39
UART communication parameters can be configured all in a single step or individually in multiple steps.
@@ -89,12 +89,12 @@ Each of the above functions has a ``_get_`` counterpart to check the currently s
89
89
90
90
.. _uart-api-setting-communication-pins:
91
91
92
-
Setting Communication Pins
92
+
Set Communication Pins
93
93
^^^^^^^^^^^^^^^^^^^^^^^^^^
94
94
95
95
After setting communication parameters, configure the physical GPIO pins to which the other UART device will be connected. For this, call the function :cpp:func:`uart_set_pin` and specify the GPIO pin 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 :c:macro:`UART_PIN_NO_CHANGE`.
96
96
97
-
The same macro should be specified for pins that will not be used.
97
+
The same macro :c:macro:`UART_PIN_NO_CHANGE` should be specified for pins that will not be used.
98
98
99
99
.. code-block:: c
100
100
@@ -103,7 +103,7 @@ The same macro should be specified for pins that will not be used.
103
103
104
104
.. _uart-api-driver-installation:
105
105
106
-
Driver Installation
106
+
Install Drivers
107
107
^^^^^^^^^^^^^^^^^^^
108
108
109
109
Once the communication pins are set, install the driver by calling :cpp:func:`uart_driver_install` and specify the following parameters:
@@ -129,7 +129,7 @@ Once this step is complete, you can connect the external UART device and check t
129
129
130
130
.. _uart-api-running-uart-communication:
131
131
132
-
Running UART Communication
132
+
Run UART Communication
133
133
^^^^^^^^^^^^^^^^^^^^^^^^^^
134
134
135
135
Serial communication is controlled by each UART controller's finite state machine (FSM).
@@ -146,11 +146,11 @@ The process of receiving data is similar, but the steps are reversed:
146
146
2. FSM writes the data into Rx FIFO buffer
147
147
3. Read the data from Rx FIFO buffer
148
148
149
-
Therefore, an application will be limited to writing and reading data from a respective buffer using :cpp:func:`uart_write_bytes` and :cpp:func:`uart_read_bytes` respectively, and the FSM will do the rest.
149
+
Therefore, an application will only write and read data from a specific buffer using :cpp:func:`uart_write_bytes` and :cpp:func:`uart_read_bytes` respectively, and the FSM will do the rest.
150
150
151
151
152
-
Transmitting
153
-
""""""""""""
152
+
Transmit Data
153
+
"""""""""""""
154
154
155
155
After preparing the data for transmission, call the function :cpp:func:`uart_write_bytes` and pass the data buffer's address and data length to it. The function will copy the data to the Tx ring buffer (either immediately or after enough space is available), and then exit. When there is free space in the Tx FIFO buffer, an interrupt service routine (ISR) moves the data from the Tx ring buffer to the Tx FIFO buffer in the background. The code below demonstrates the use of this function.
156
156
@@ -178,8 +178,8 @@ There is a 'companion' function :cpp:func:`uart_wait_tx_done` that monitors the
178
178
ESP_ERROR_CHECK(uart_wait_tx_done(uart_num, 100)); // wait timeout is 100 RTOS ticks (TickType_t)
179
179
180
180
181
-
Receiving
182
-
"""""""""
181
+
Receive Data
182
+
""""""""""""
183
183
184
184
Once the data is received by the UART and saved in the Rx FIFO buffer, it needs to be retrieved using the function :cpp:func:`uart_read_bytes`. Before reading data, you can check the number of bytes available in the Rx FIFO buffer by calling :cpp:func:`uart_get_buffered_data_len`. An example of using these functions is given below.
185
185
@@ -214,10 +214,10 @@ The UART controller supports a number of communication modes. A mode can be sele
214
214
215
215
.. _uart-api-using-interrupts:
216
216
217
-
Using Interrupts
217
+
Use Interrupts
218
218
^^^^^^^^^^^^^^^^
219
219
220
-
There are many interrupts that can be generated following specific UART states or detected errors. The full list of available interrupts is provided in *{IDF_TARGET_NAME} Technical Reference Manual* > *UART Controller (UART)* > *UART Interrupts* and *UHCI Interrupts* [`PDF <{IDF_TARGET_TRM_EN_URL}#uart>`__]. You can enable or disable specific interrupts by calling :cpp:func:`uart_enable_intr_mask` or :cpp:func:`uart_disable_intr_mask` respectively.
220
+
There are many interrupts that can be generated depending on specific UART states or detected errors. The full list of available interrupts is provided in *{IDF_TARGET_NAME} Technical Reference Manual* > *UART Controller (UART)* > *UART Interrupts* and *UHCI Interrupts* [`PDF <{IDF_TARGET_TRM_EN_URL}#uart>`__]. You can enable or disable specific interrupts by calling :cpp:func:`uart_enable_intr_mask` or :cpp:func:`uart_disable_intr_mask` respectively.
221
221
222
222
The :cpp:func:`uart_driver_install` function installs the driver's internal interrupt handler to manage the Tx and Rx ring buffers and provides high-level API functions like events (see below).
223
223
@@ -231,7 +231,7 @@ The API provides a convenient way to handle specific interrupts discussed in thi
231
231
- Enable the interrupts using the functions :cpp:func:`uart_enable_tx_intr` and :cpp:func:`uart_enable_rx_intr`
232
232
- Disable these interrupts using the corresponding functions :cpp:func:`uart_disable_tx_intr` or :cpp:func:`uart_disable_rx_intr`
233
233
234
-
- **Pattern detection**: An interrupt triggered on detecting a 'pattern' of the same character being received/sent repeatedly for a number of times. This functionality is demonstrated in the example :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 'pattern') added at the end of the command string. The following functions are available:
234
+
- **Pattern detection**: An interrupt triggered on detecting a 'pattern' of the same character being received/sent repeatedly. This functionality is demonstrated in the example :example:`peripherals/uart/uart_events`. It can be used, e.g., to detect a command string with a specific number of identical characters (the 'pattern') at the end. The following functions are available:
235
235
236
236
- Configure and enable this interrupt using :cpp:func:`uart_enable_pattern_det_intr`
237
237
- Disable the interrupt using :cpp:func:`uart_disable_pattern_det_intr`
@@ -251,7 +251,7 @@ Deleting a Driver
251
251
If the communication established with :cpp:func:`uart_driver_install` is no longer required, the driver can be removed to free allocated resources by calling :cpp:func:`uart_driver_delete`.
252
252
253
253
254
-
Overview of RS485 specific communication options
254
+
Overview of RS485 Specific Communication 0ptions
255
255
------------------------------------------------
256
256
257
257
.. note::
@@ -268,7 +268,7 @@ The collision detection feature allows handling collisions when their interrupts
268
268
269
269
The collision detection feature can work with circuit A and circuit C (see Section `Interface Connection Options`_). In the case of using circuit A or B, the RTS pin connected to the DE pin of the bus driver should be controlled by the user application. Use the function :cpp:func:`uart_get_collision_flag` to check if the collision detection flag has been raised.
270
270
271
-
The {IDF_TARGET_NAME} UART controllers themselves do not support half-duplex communication as they cannot provide automatic control of the RTS pin connected to the ~RE/DE input of RS485 bus driver. However, half-duplex communication can be achieved via software control of the RTS pin by the UART driver. This can be enabled by selecting the :cpp:enumerator:`UART_MODE_RS485_HALF_DUPLEX` mode when calling :cpp:func:`uart_set_mode`.
271
+
The {IDF_TARGET_NAME} UART controllers themselves do not support half-duplex communication as they cannot provide automatic control of the RTS pin connected to the RE/DE input of RS485 bus driver. However, half-duplex communication can be achieved via software control of the RTS pin by the UART driver. This can be enabled by selecting the :cpp:enumerator:`UART_MODE_RS485_HALF_DUPLEX` mode when calling :cpp:func:`uart_set_mode`.
272
272
273
273
Once the host starts writing data to the Tx FIFO buffer, the UART driver automatically asserts the RTS pin (logic 1); once the last bit of the data has been transmitted, the driver de-asserts the RTS pin (logic 0). To use this mode, the software would have to disable the hardware flow control function. This mode works with all the used circuits shown below.
274
274
@@ -400,7 +400,7 @@ The UART peripherals have dedicated IO_MUX pins to which they are connected dire
400
400
401
401
1. :c:macro:`UART_NUM_2_TXD_DIRECT_GPIO_NUM` returns the IO_MUX pin number of UART channel 2 TXD pin (pin 17)
402
402
2. :c:macro:`UART_GPIO19_DIRECT_CHANNEL` returns the UART number of GPIO 19 when connected to the UART peripheral via IO_MUX (this is UART_NUM_0)
403
-
3. :c:macro:`UART_CTS_GPIO19_DIRECT_CHANNEL` returns the UART number of GPIO 19 when used as the UART CTS pin via IO_MUX (this is UART_NUM_0). Similar to the above macro but specifies the pin function which is also part of the IO_MUX assignment.
403
+
3. :c:macro:`UART_CTS_GPIO19_DIRECT_CHANNEL` returns the UART number of GPIO 19 when used as the UART CTS pin via IO_MUX (this is UART_NUM_0). It is similar to the above macro but specifies the pin function which is also part of the IO_MUX assignment.
0 commit comments