Notes / Communication Protocols
RS-232, RS-422, RS-485: sending UART further
The same UART frame, converted to other voltage levels and differential signals, travels tens of metres up to 1 km. How the three standards differ, and RS-485 direction control.
An MCU's UART is a 3.3 V single-ended signal and becomes unreliable beyond 1 to 2 m. A transceiver chip changes only the shape of the signal, so the frame stays the same and travels further.
| Standard | Signal | Distance | Nodes | Characteristics |
|---|---|---|---|---|
| RS-232 | ±3 to 15 V, single-ended | ~15 m | 1:1 | PC serial port. Logic is inverted |
| RS-422 | Differential, one-way pairs | ~1200 m | 1 driver : 10 receivers | Full duplex (4 wires) |
| RS-485 | Differential, bidirectional | ~1200 m | 32 nodes or more | Half duplex (2 wires), the industrial standard |
RS-232 caution
A 1 is a negative voltage. Connecting it straight to an MCU pin destroys the pin. You need a transceiver such as the MAX3232.
RS-485 in practice
- Several devices share one pair (A, B), so the driver must be on only while transmitting. Turn on the transceiver's DE pin with a GPIO and turn it off after the last bit has fully left (the UART TC flag). Turn it off too early and the last byte is corrupted.
- Put a 120 Ω termination resistor at each end of the line.
- Put fail-safe bias resistors in one place to define the line state when nobody is talking.
- Modbus RTU is the most widely used protocol on top of RS-485.