1. Please check out this comprehensive RS-485 beginner’s guide!2. From beginner to advanced applications! Say goodbye to using RS-485 without understanding it!
3. What projects to test with RS-485, and how to test them?
RS-485, like RS-232, is a serial communication standard. The current standard name is TIA485/EIA-485-A, but people commonly refer to it as the RS-485 standard. RS-485 is often used in industries such as automation, automotive, and building management.
The RS-485 bus compensates for the short communication distance and low speed of RS-232. RS-485 can achieve speeds of up to 10Mbit/s, with a theoretical communication distance of up to 1200 meters. Unlike RS-232’s single-ended transmission, RS-485 uses differential transmission with a pair of twisted wires, one wire defined as A and the other as B.
Twisted Pair
▉ RS-485 Physical Layer
The physical layer of RS-485 is responsible for transmitting raw data between devices and the physical transmission medium. It handles the conversion of electrical signals to digital data while defining voltage, timing, data rate, etc.
① Differential Signal
Long-distance wiring can lead to signal attenuation and greater susceptibility to noise and interference, which manifests as voltage amplitude variations on wires A and B. However, the advantage of using differential lines is that the differential measurement can ignore interference, thus still outputting a normal signal. The ability of this differential receiver to ignore the same voltage on both signal lines is known as common-mode rejection.
The standard specifies that for logic 1: +2V to +6V; logic 0: -6V to -2V.
RS-485 does not require a specific bus voltage; it only looks at the minimum differential voltage. Over longer cable lengths, the voltage received by the receiver can drop to +/- 200 mV, which is still completely acceptable for RS-485, making it one of its advantages.
Many transceivers meet or even exceed TIA/EIA-485A specifications, and in practical use, the device’s SPEC parameters take precedence. For example, the negative input threshold of a certain transceiver is at least -200mV.
② Signal Definition
Many RS-485 converters are now compatible with RS-422, so many converters display signals as T/R+ and T/R-, corresponding to RS-485’s A+ and B-.
For DB9 female connectors, RS-485 has the following wiring definition, with Pins 6-9 being N/A (not connected).
DB9 | Output Signal | RS-422 Full Duplex Wiring | RS-485 Half Duplex Wiring |
1 | T/R+ | Transmit (A+) | RS-485 (A+) |
2 | T/R- | Transmit (B-) | RS-485 (B-) |
3 | RXD+ | Receive (A+) | Empty |
4 | RXD- | Receive (B-) | Empty |
5 | GND | Ground | Ground |
③ Topology Structure
RS-485 can be wired in two-wire or four-wire configurations. The four-wire configuration can only achieve point-to-point communication and is rarely used. The two-wire configuration is more common and uses a bus topology, allowing up to 32 nodes on the same bus.
RS-485 operates in a master-slave mode similar to I2C, supporting point-to-point single slave mode and multi-slave mode, but not multi-master mode.
▉ RS-485 Transceiver
RS-485 uses differential transmission. If a microcontroller controls an RS-485 interface device, a transceiver is needed, similar to the CAN bus. Below is a diagram of an MCU controlling an RS-485.
The transceiver consists of a receiver (upper part) and a transmitter (lower part). Here’s a brief explanation of the transceiver’s principles to help understand how the MCU communicates with 485 devices.
Internal Structure of RS-485 Transceiver
Where:
-
A and B are the bus;
-
R is the receiver input;
-
RE is the receiver enable signal;
-
DE is the transmitter enable signal;
-
D is the transmitter output;
For the enable signals, the ones with a line above the letter are active low (e.g., RE in the above figure), while those without are active high (e.g., DE).
For the transmitter, the following truth table applies:
1. When the driver enable pin DE is high, the differential outputs A and B follow the logic state of the data input D. A high at D causes A to go high and B to go low. In this case, the differential output voltage defined as VOD=VA-VB is positive. When D is low, the output state reverses, with B going high and A going low, making VOD negative.
2. When DE is low, both outputs become high impedance. In this case, they are independent of the logic state at D.
Transmitter Truth Table
For the receiver, the following truth table applies:
1. When the receiver enable pin RE is low, the receiver is activated. When the differential input voltage defined as VID=VA–VB is positive and exceeds the positive input threshold VIT+, the receiver output R goes high. If VID is negative and below the negative input threshold VIT-, the receiver output R goes low. If VID is between VIT+ and VIT-, the output is uncertain.
2. When RE is high or floating, the receiver output is high impedance, regardless of the magnitude and polarity of VID.
Receiver Truth Table
▉ RS-485 Data Link
The previous section discussed the working principles of RS-485 transceivers. Below is a simple description of the RS-485 data link, starting with an easy-to-understand UART protocol frame format.
Both the master sending to the slave and the slave sending to the master will utilize lines A and B, so RS-485 is commonly used in half-duplex mode.
The master’s GPIO will control the DE pin of the RS-485 transceiver, setting it to send mode. A byte is sent from the UART TXD line to the RS-485 transceiver’s data (D or DI) line, which will convert the single-ended UART bit stream into a differential bit stream on lines A and B. After the data leaves the transceiver, the master immediately switches the transceiver mode to receive.
The slave operates similarly; it controls the /RE pin of the RS-485 transceiver to set it to receive mode, receiving the bit stream sent by the master, converting it to a single-ended signal through the slave’s UART RXD line. When the slave is ready to respond, it sends back in the same way the master did, while the master becomes the receiver.
▉ Converting RS-232 and RS-485
RS-232 and RS-485 can be converted; one method is to convert RS-232 to TTL, and then from TTL to RS-485. There are also chips available that support direct conversion from RS-232 to RS-485, with many modules available online.
RS-232 and RS-485 Conversion Module
▉ Differences Between RS-485 and CAN
Although RS-485 does not have a standard data protocol format, it shares similarities with CAN bus in many aspects, such as A&B and CANH&CANL both being differential signals, both requiring transceivers, and both needing 120-ohm termination resistors, etc.
Bus Characteristics | CAN Bus | RS-485 Bus |
Hardware Cost | Somewhat higher | Low |
Bus Utilization | Automatic arbitration with priority, high utilization | Polling, low utilization |
Data Transmission Rate | High | Low |
Error Detection Mechanism | Controller has a checksum mechanism to ensure correct lower-level data transmission | Only physical layer specifications, no data link layer regulations |
Single Node Failure Impact | No impact on the bus | Bus paralysis |
Development Cost | Software development is flexible, low time cost | Higher development difficulty |
System Cost | Lower | Higher |
▉ Common RS-485 Circuits
A commonly found RS-485 circuit online has two points to note:
1. The enable signals RE and DE can be controlled by a single GPIO to save resources. When GPIO25 outputs high, RE=DE=0V, entering receive mode; when GPIO25 outputs low, RE=DE=3.3V, entering send mode.
2. In some circuits, pull-up resistors may be added on A and pull-down on B. The main reason is that the RS-485 bus has an idle state where the level is not fixed, fluctuating between -200mV and +200mV. If the transceiver outputs a low level during this idle state, it may be interpreted as a start bit by the UART, leading to communication errors. The resistor values for Ru and Rd will not be discussed in detail here, but I will write a detailed article on it later.
Regarding the second point, please note:
① Adding a pull-up on A and a pull-down on B may cause communication errors if connected incorrectly.
② Some transceivers have integrated pull-up and pull-down resistors, so external ones are not needed.
This concludes today’s article. I hope it has been helpful to you. See you next time.
Disclaimer:
This account maintains neutrality regarding the statements and views of all original and reprinted articles. The articles pushed are for readers’ learning and exchange purposes only. The copyright of articles, images, etc., belongs to the original authors. If there is any infringement, please contact us for removal.
Disclaimer:
—— The End ——
Recommended Reading
How Should Buck Power Supplies Be Tested?
Indeed, Operational Amplifiers Are the Essence of Analog Electronics!!! YYDS
A Collection of Overvoltage and Overcurrent Protection Solutions Essential for Hardware Engineers
Share 💬 Like 👍 Read ❤️
Support quality content with a “three-step” action!