RS485
Best for: Long-distance, multi-drop industrial environments (motor controls, PLCs, building automation).
How it works: Uses a differential signaling standard across a twisted pair of wires (A and B). Instead of comparing voltage to a single ground, receivers look at the voltage difference between the two wires. This makes it highly immune to electromagnetic interference (EMI). It is typically half-duplex (devices must take turns transmitting).
Speed: Up to 10 Mbps (at very short distances), dropping to around 100 kbps at maximum range.
Distance: Up to 1200 meters (4000 feet)
RS485 and Modbus RTU Technical Reference Guide
This document provides a comprehensive technical overview of the physical layer, differential signaling mechanics, network topologies, and fail-safe biasing of the RS485 interface, alongside an architectural overview of Modbus RTU protocol integration.
1. RS485 Physical Connection
RS485 (TIA/EIA-485) is an industrial physical layer standard defining a high-speed, multi-drop, differential signaling communication network. It is engineered for long distances and structurally immune to harsh electromagnetic interference (EMI) commonly found in industrial environments.
A standard half-duplex RS485 network requires exactly two signal wires plus a shared reference/ground line:
- A (Non-Inverting Line): Often labeled as Data+ or RxTx+.
- B (Inverting Line): Often labeled as Data- or RxTx-.
- GND / SC (Signal Reference): A crucial shared reference line used to balance ground potentials across distant nodes.
Node 1 Node 2 Node 3
+-----------------+ +-----------------+ +-----------------+
| Micro/UART Ctrl | | Micro/UART Ctrl | | Micro/UART Ctrl |
+--------+--------+ +--------+--------+ +--------+--------+
| (TX/RX/DE) | (TX/RX/DE) | (TX/RX/DE)
+--------+--------+ +--------+--------+ +--------+--------+
|485 Transceiver | |485 Transceiver | |485 Transceiver |
+----+--------+---+ +----+--------+---+ +----+--------+---+
| | | | | |
======+========+==================+========+==================+========+====== Line A (+)
[120 Ω] [120 Ω]
======+========+==================+========+==================+========+====== Line B (-)
Differential Signaling and Termination
RS485 interprets data states based on the voltage difference between the two lines: $V_{\text{diff}} = V_A - V_B$.
- Mark State (Logic 1 / Idle): Line A is at a higher voltage than Line B ($V_A > V_B$). The differential voltage is positive (typically $> +200\text{ mV}$).
- Space State (Logic 0 / Active): Line A is at a lower voltage than Line B ($V_A < V_B$). The differential voltage is negative (typically $< -200\text{ mV}$).
- Termination Resistors: An RS485 bus uses a parallel bus configuration. To prevent electrical signal reflections over long distances, exactly two 120 Ω termination resistors must be connected across lines A and B at the absolute physical ends of the main trunk cable.
2. Packet Structure and Data Transfer
RS485 only defines the physical and electrical (OSI Layer 1) characteristics of the bus. It has no native packet structure, frame formatting, or addressing rules. Instead, it acts as a transparent physical pipe that almost universally transports standard asynchronous UART data frames (Start, Data, Parity, Stop bits).
Transmit Direction Control
Because a 2-wire RS485 bus is half-duplex, devices must share the same twisted pair of wires. Nodes cannot transmit and receive simultaneously.
- Hardware Control Pins: RS485 transceivers break out two critical digital logic pins to the microcontroller: RE# (Receiver Enable, active low) and DE (Driver Enable, active high).
- The Switching Sequence: These two pins are typically tied together to a single GPIO pin on the microcontroller.
- Idle/Receive Mode: The GPIO is held low, disabling the transmitter and opening up the receiver to listen to the bus.
- Transmit Mode: Before dumping data into the UART TX register, the microcontroller drives the GPIO high to claim the physical wire. The moment the UART transmission completes (after the final Stop bit has fully cleared the shift register), the microcontroller must instantly drop the GPIO low to avoid clipping incoming responses or jamming the bus.
3. RS485 Oscilloscope Timing Diagram
The visual representation below shows how the electrical voltages on Line A and Line B shift relative to ground during standard UART data transitions, alongside the resulting differential waveform.
MARK STATE SPACE STATE MARK STATE
Volt (Logic 1) (Logic 0) (Logic 1)
3.6V ............ ________ ............................ ________ ............ Line A (+) (~3.6V)
: / \ / \
2.5V ============================================================================ Idle Midpoint
: \________/ \________/
1.4V ............ : :............................ : :............ Line B (-) (~1.4V)
: : : : :
: : : : :
Vdiff ____ ________ ________ Differential
(+2V) \________/ \_____________________________/ \_____________ Voltage (A-B)
: : : : :
-2V .............: : __________________________ : :............ B > A (Logic 0)
: : : / \: :
Logic __________ ______________________________ __________ Output of RX
Output \__________/ \__________/ Pin to MCU UART
Key Oscilloscope Identification Markers
- Symmetrical Inversion: When a bit transition occurs, Line A and Line B must invert symmetrically. If both lines spike upward or downward simultaneously, look for external ground loops or an ungrounded system shield.
- The Minimum Threshold Window: A valid RS485 receiver expects the differential voltage swing to clear an absolute dead-zone threshold of $\pm 200\text{ mV}$. Anything floating between $-200\text{ mV}$ and $+200\text{ mV}$ is structurally undefined.
- Data Validity: Because RS485 runs standard asynchronous UART packets, use the vertical transition edge of the first falling Space state bit (the Start bit) as your horizontal time base trigger.
4. Bus Topologies and Fail-Safe Biasing
Strict Daisy-Chain Topology
RS485 networks require a strict daisy-chain linear layout. The main trunk line must run sequentially from Node 1 to Node 2 to Node 3.
- Stub Lengths: T-junction branches or "stub" lines connecting a device to the main backbone must be kept as short as humanly possible (ideally under 30cm). Long stubs create impedance mismatches that manifest as severe signal distortion and data corruption on an oscilloscope.
Fail-Safe Biasing
When an RS485 bus is completely idle, or if a cable becomes disconnected, no transceivers are actively driving the lines. The 120 ohm termination resistors will quickly collapse the voltage difference between Line A and Line B to 0V.
- The Problem: Because 0 V sits squarely inside the undefined 200 mV input dead-zone, the internal receiver circuits can interpret random environmental noise as valid alternating Start/Stop bits, feeding ghost characters directly into the microcontroller's UART.
- The Fix: Hardware designers implement Fail-Safe Biasing by placing a pull-up resistor from V_CC to Line A, and a pull-down resistor from Line B to Ground. These resistors form a voltage divider that forces a steady differential bias of approximately 250 mV across the wires when the bus is idle, locking the bus into a clean, predictable Mark (Logic 1) state.
5. Modbus RTU Integration Protocol
Because RS485 lacks a native network layer, industrial architectures almost universally overlay the Modbus RTU protocol over the RS485 physical hardware to handle multi-drop routing, node addressing, and error detection.
| Feature | RS485 (Physical Layer) | Modbus RTU (Application/Data Link) |
|---|---|---|
| Responsibility | Voltage scales, wiring, bit-level timings | Node addresses, function commands, data unpacking |
| Addressing Scope | None (all assets receive all bits) | Master-Slave / Client-Server routing (1 to 247 addresses) |
| Data Framing | Asynchronous serial frames (e.g., 8N1) | Modbus PDU (Address, Function Code, Data, CRC) |
| Error Verification | None | 16-bit Cyclic Redundancy Check (CRC-16) |
| Topology Rule | Hardware differential multi-drop trunk | Strictly half-duplex Master queries, Slave replies |
Modbus RTU Message Frame Profile
A complete Modbus RTU packet sent over an RS485 bus consists of four sequential fields. The frame structure is restricted by precise silent timing boundaries rather than specific starting characters.
[ 3.5 Character Silent Time ] -> [ 1-Byte Slave ID ] -> [ 1-Byte Function Code ] -> [ N-Byte Data Payload ] -> [ 2-Byte CRC-16 ] -> [ 3.5 Character Silent Time ]
- Temporal Framing (Silent Intervals): Modbus RTU frames do not use start-of-packet delimiters. A frame begins and ends with a mandatory transmission pause of at least 3.5 character times (the time it takes to transmit 3.5 complete serial data bytes at the active baud rate). Any silent pause longer than 1.5 character times inside a message tells receivers that the frame has timed out or broken.
- Slave Address Field: A single byte targeting a specific node on the network ($1$ to $247$). Address $0$ is universally reserved for master broadcast messages.
- Function Code: A single byte specifying the internal register operation command (e.g.,
0x03to Read Holding Registers,0x06to Write Single Register). - CRC-16 Error Check: A robust 16-bit Cyclic Redundancy Check code appended to the final bytes of the frame. Every receiving slave re-calculates this polynomial math; if the local calculation fails to match the appended CRC bytes, the entire frame is silently rejected to preserve system state safety.
6. Interfacing with ESP32
ESP32 ↔ RS-485 via MAX3485
Design notes for adding a half-duplex RS-485 port to an ESP32 on a custom PCB.
1. Why MAX3485
The MAX3485 is a 3.3 V half-duplex RS-485/RS-422 transceiver, so it interfaces
directly with the ESP32 — no level shifting needed.
A MAX485 (the more commonly seen part) is 5 V and would require a divider or
level shifter on the RO line to avoid overdriving the ESP32 GPIO.
| Variant | Notes |
|---|---|
| MAX3485 | Base part. Fail-safe only for open inputs. No meaningful ESD protection. |
| MAX3485E | ±15 kV ESD protected. |
| MAX3485AE | ±20 kV ESD + true fail-safe (high output when inputs are open, shorted, or on an idle three-state bus). Preferred for new designs. |
Recommendation: use the MAX3485AE. It removes the need for external
fail-safe bias resistors and for a separate TVS array. Drop-in pinout.
2. Pinout (SO-8)
| Pin | Name | Direction | Connects to |
|---|---|---|---|
| 1 | RO | out | ESP32 RX |
| 2 | RE̅ | in | tied to DE |
| 3 | DE | in | ESP32 GPIO (direction control) |
| 4 | DI | in | ESP32 TX |
| 5 | GND | — | ground plane |
| 6 | A | bus | RS-485 A / D+ |
| 7 | B | bus | RS-485 B / D− |
| 8 | VCC | — | 3V3 |
3. Schematic
3V3 ─────┬──────────┬──────────────┬─────────────
│ │ │
═══ 100nF │ ┌─┴─┐
═══ 10µF │ │390│ Rbias+
│ │ └─┬─┘
GND │ │
┌────┴────┐ │
ESP32 │ MAX3485 │ │
┌────────────┐ │ │ │
│ GPIO16 RX │◄──────────┤1 RO A ├6────────┴──┬─────┬──── A (D+)
│ │ │ │ │ │
│ GPIO17 TX ├──────────►│4 DI │ ┌─┴─┐ ┌─┴─┐
│ │ │ │ │120│ │TVS│
│ GPIO4 DE ├─────┬────►│3 DE │ └─┬─┘ └─┬─┘
│ (= RTS) │ │ ┌─►│2 RE │ │ │
└────────────┘ │ │ │ B ├7────────┬──┴─────┴──── B (D-)
├──┘ │ │ │
┌─┴─┐ │5 GND │ ┌─┴─┐
│10k│ └────┬────┘ │390│ Rbias-
└─┬─┘ │ └─┬─┘
│ │ │
GND ─────┴──────────┴──────────────┴─────────────
4. Bill of materials
| Ref | Value | Purpose | Notes |
|---|---|---|---|
| C1 | 100 nF X7R | VCC decoupling | As close to pin 8 as physically possible, short via to GND plane |
| C2 | 1–10 µF | Bulk | Within ~10 mm |
| R1 | 10 kΩ | DE/RE pulldown | Critical — see §5 |
| R2 | 120 Ω, ≥0.25 W | Bus termination | Only at the two physical ends of the cable. Put on a jumper/DIP. |
| R3, R4 | 390 Ω | Fail-safe bias | Only at one node on the bus. Not needed with MAX3485AE. |
| D1 | SM712 (or PESD1CAN) | TVS across A–B | SM712 is purpose-built for RS-485: −7 V / +12 V asymmetric clamp |
| R5, R6 | 10 Ω fusible / PTC | Surge series-R | Optional. Between transceiver and TVS. |
| R7 | 100 Ω | Signal-ground series-R | Limits ground-loop current. See §7. |
| Rx | 33 Ω | Series on RO/DI | Optional, EMI only |
5. DE/RE pulldown — do not skip this
ESP32 GPIOs float during reset and boot. A floating DE pin can enable the RS-485
driver and jam the entire bus for every other node. The 10 kΩ pulldown forces the
transceiver into receive mode by default.
Also: pick a non-strapping GPIO for DE. Avoid GPIO 0, 2, 5, 12, 15. GPIO4 is fine.
Firmware
ESP-IDF has UART_MODE_RS485_HALF_DUPLEX, which drives DE from the UART's RTS
pin in hardware and handles turnaround timing automatically. Wire DE to whichever
pin you configure as RTS and never toggle it manually.
uart_set_mode(UART_NUM_2, UART_MODE_RS485_HALF_DUPLEX);
uart_set_pin(UART_NUM_2, TX_PIN, RX_PIN, DE_PIN, UART_PIN_NO_CHANGE);
6. Fail-safe bias math
An idle, terminated bus sits at 0 V differential — which RS-485 defines as
undefined. The receiver needs > 200 mV to hold a known state. Without bias,
an idle bus produces random RX noise and UART framing errors.
Bias resistors form a divider with the termination:
V_AB = Vcc × R_term_eff / (2·R_bias + R_term_eff)
| Termination on bus | R_term_eff | Max R_bias for 200 mV @ 3.3 V | Use |
|---|---|---|---|
| Two × 120 Ω | 60 Ω | < 465 Ω | 390 Ω |
| One × 120 Ω | 120 Ω | < 930 Ω | 680 Ω |
390 Ω works in both cases — safe default if the final bus topology is unknown.
The common module mistake
Cheap MAX3485/MAX485 breakout modules ship with 4.7 kΩ bias (SMD code 472).
That's effectively useless:
V_AB = 3.3 × 120 / (9400 + 120) ≈ 42 mV ← one terminator
V_AB = 3.3 × 60 / (9400 + 60) ≈ 21 mV ← two terminators
Both far below the 200 mV threshold. MaxLinear AN-291 documents this exact failure:
with 4.7 k bias and termination present, the drop across the termination makes the
bias resistors ineffective and leaves receiver inputs in the indeterminate region.
7. Grounding
RS-485 is differential but not isolated. All nodes must share a common ground
within ±7 V or the receivers see out-of-range common mode.
- Run a third wire (or the cable shield) as signal ground.
- Put a 100 Ω series resistor at each node to limit ground-loop current.
- For long runs, outdoor runs, or separate power domains: use an isolated
transceiver (ADM2582E, ISO3082). This eliminates an entire class of field
failures and is worth the cost.
8. Layout rules
- A and B routed as a tight differential pair.
- No stubs. Keep the tap from the trunk to the transceiver as short as possible.
- Do not split the ground plane under the pair.
- Place the transceiver close to the connector.
- Route the TVS so surge current reaches connector ground before it reaches the IC.
9. Bus topology gotchas
- Termination goes at the two physical ends of the cable, not at every node and
not "at the master." A mid-bus node gets no terminator. - Bias goes at exactly one node on the entire bus (conventionally the master).
- MAX3485 is 1 unit load → up to 32 nodes on one twisted pair. (MAX487 is
1/4 UL → 128 nodes.) Fail-safe biasing itself adds bus loading — up to ~20 UL —
which reduces the practical node count. - If using a pre-made breakout: check what's already populated. Most ship with a
120 Ω terminator soldered on (remove for mid-bus nodes) and inadequate or absent
fail-safe bias.
7. References & Standards Documents
- TIA/EIA-485-A: Electrical Characteristics of Generators and Receivers for Use in Balanced Digital Multipoint Systems — The foundational telecommunications standard defining the definitive electrical constraints, voltage ranges, and current capabilities for RS485 networks.
- Modbus Application Protocol Specification V1.1b3 — The definitive reference guide detailing Modbus data framing, function codes, memory mappings, and CRC-16 mathematics.
- Analog Devices: RS-485/RS-422 Circuit Implementation Guide (AN-960) — An authoritative industry application note outlining line termination calculations, fail-safe biasing math, and surge protection configurations.
- Texas Instruments: Top 10 RS-485 Design Tips (SLLA490) — Engineering design handbook detailing daisy-chain configuration limits, grounding problems, stub reflections, and node counting constraints.
- MAX3485 — product page & datasheet (Analog Devices)
- MAX3485AE — true fail-safe + ±20 kV ESD variant
- Maxim AN-763 — Guidelines for Proper Wiring of an RS-485 Network
- MaxLinear AN-291 — RS-485 Advanced Fail-Safe Feature (the 4.7 k bias problem, with math)
- Renesas — RS-485 Design Guide (stub length, bus loading, length vs. baud)