Chapter 2. API Reference
Overview of RS485 specific communication options
Note: The following section will use [UART_REGISTER_NAME].[UART_FIELD_BIT] to refer to UART
register fields/bits. For more information on a specific option bit, see ESP32-S2 Technical Reference Manual > UART
Controller (UART) > Register Summary [PDF]. Use the register name to navigate to the register description and then
find the field/bit.
• UART_RS485_CONF_REG.UART_RS485_EN: setting this bit enables RS485 communication mode sup-
port.
• UART_RS485_CONF_REG.UART_RS485TX_RX_EN: if this bit is set, the transmitter’s output signal
loops back to the receiver’s input signal.
• UART_RS485_CONF_REG.UART_RS485RXBY_TX_EN: if this bit is set, the transmitter will still be send-
ing data if the receiver is busy (remove collisions automatically by hardware).
The ESP32-S2’s RS485 UART hardware can detect signal collisions during transmission of a datagram and generate
the interrupt UART_RS485_CLASH_INT if this interrupt is enabled. The term collision means that a transmitted
datagram is not equal to the one received on the other end. Data collisions are usually associated with the presence
of other active devices on the bus or might occur due to bus errors.
The collision detection feature allows handling collisions when their interrupts are activated and triggered. The in-
terrupts UART_RS485_FRM_ERR_INT and UART_RS485_PARITY_ERR_INT can be used with the collision
detection feature to control frame errors and parity bit errors accordingly in RS485 mode. This functionality is
supported in the UART driver and can be used by selecting the UART_MODE_RS485_APP_CTRL mode (see the
function uart_set_mode()).
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 uart_get_collision_flag() to check if the collision detection flag has
been raised.
The ESP32-S2 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 com-
munication can be achieved via software control of the RTS pin by the UART driver. This can be enabled by selecting
the UART_MODE_RS485_HALF_DUPLEX mode when calling uart_set_mode().
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.
Interface Connection Options This section provides example schematics to demonstrate the basic aspects of
ESP32-S2’s RS485 interface connection.
Note:
• The schematics below do not necessarily contain all required elements.
• The analog devices ADM483 & ADM2483 are examples of common RS485 transceivers and can be replaced
with other similar transceivers.
Circuit A: Collision Detection Circuit
VCC ---------------+
|
+-------x-------+
RXD <------| R |
| B|----------<> B
TXD ------>| D ADM483 |
(continues on next page)
Espressif Systems 462
Submit Document Feedback
Release v4.4