RS485 Connection: Serial Interface Explained

Posted by

Introduction to RS485 Serial Interface

RS485, also known as TIA-485-A, EIA-485 or RS-485, is a standard defining the electrical characteristics of drivers and receivers for use in serial communications systems. It is widely used for industrial automation, building automation, and other applications requiring robust, long-distance serial data transmission.

RS485 enables the configuration of inexpensive local networks and multidrop communications links. It offers data transmission speeds of up to 35 Mbit/s and a maximum cable length of up to 1200 meters. RS485 uses differential signaling, which makes it resistant to electromagnetic interference and suitable for use in noisy environments.

Key Features of RS485

  • Differential signaling for noise immunity
  • Supports up to 32 devices on a single bus
  • Half-duplex communication
  • Multidrop capability
  • Data rates up to 35 Mbit/s
  • Cable lengths up to 1200 meters
  • Wide common-mode range

RS485 vs Other Serial Interfaces

RS485 is one of several serial interface standards commonly used in industrial applications. Here’s how it compares to some other popular standards:

RS485 vs RS232

RS232 is another widely used serial communication standard. However, it differs from RS485 in several key ways:

Feature RS485 RS232
Communication Half-duplex Full-duplex
Max Devices 32 1 transmitter, 1 receiver
Max Distance 1200 meters 15 meters
Max Speed 35 Mbit/s 20 kbit/s
Signaling Differential Single-ended

RS232 is better suited for short-distance, point-to-point communication, while RS485 excels at longer distances and multi-device networks.

RS485 vs RS422

RS422 is another differential signaling standard that is similar to RS485 in many ways. The main differences are:

Feature RS485 RS422
Communication Half-duplex Full-duplex
Max Devices 32 10
Signaling Differential Differential

RS422 supports full-duplex communication, but is limited to 10 devices per bus, while RS485 is half-duplex but supports up to 32 devices.

RS485 vs Modbus

Modbus is a communication protocol that can be used with various physical interfaces, including RS485. So RS485 and Modbus are not directly comparable – RS485 defines the electrical characteristics of the physical layer, while Modbus defines the data protocol.

Modbus RTU is a common implementation of Modbus that uses RS485 as the physical layer. It is widely used in industrial applications for communication between devices such as PLCs, sensors, and actuators.

RS485 Electrical Characteristics

RS485 uses differential signaling, meaning it transmits data using two complementary signals on a twisted pair cable. The two signals are labeled A and B, or sometimes D+ and D-.

Differential Signaling

In differential signaling, the actual data is represented by the difference in voltage between the A and B lines. If A is more positive than B, that represents a logic high (1), while if B is more positive than A, that represents a logic low (0).

This differential signaling provides excellent noise immunity, because any electromagnetic interference will affect both lines equally, and the receiver only looks at the difference between the two.

Termination Resistors

To prevent reflections and ensure signal integrity, RS485 networks should be properly terminated with resistors at each end of the main bus. The termination resistor value should match the characteristic impedance of the cable, which is typically 120 ohms.

Biasing Resistors

In addition to termination resistors, RS485 networks often use biasing resistors to ensure a known state on the bus when all devices are in receive mode. The bias resistors pull one line high and the other low, so the bus is never floating.

A typical biasing arrangement uses a 680 ohm resistor from the A line to +5V, and another 680 ohm resistor from the B line to ground. A 120 ohm termination resistor is placed between A and B at each end of the bus.

RS485 Network Topology and Wiring

RS485 networks typically use a bus topology, with all devices connected in parallel to a single twisted pair cable. The cable should be terminated at each end with a 120 ohm resistor.

Daisy Chain Wiring

In a daisy chain configuration, each device has two connectors, one for the incoming cable and one for the outgoing cable to the next device. The devices are connected one after another in a chain.

Stub Lines

For devices that can’t be directly daisy chained, short stub lines can be used to connect them to the main bus. However, stub lines should be kept as short as possible to minimize reflections. A general rule of thumb is to keep stub lines under 1/10 of the main bus length.

Cable Type

RS485 networks should use twisted pair cable to minimize electromagnetic interference. For best results, use shielded twisted pair (STP) cable, with the shield grounded at one end.

The cable should have a characteristic impedance of 120 ohms to match the termination resistors. 24 AWG cable is commonly used for distances up to 1000 meters, while thicker 22 AWG cable can be used for even longer runs.

RS485 Communication Protocol

RS485 defines the electrical characteristics of the network, but not the communication protocol. Various protocols can be used on top of RS485, such as Modbus RTU, Profibus, BACnet MS/TP, etc.

However, there are some general principles that apply to most RS485 communication:

Half-Duplex Operation

RS485 is a half-duplex interface, meaning devices can transmit or receive, but not both at the same time. Care must be taken in the communication protocol to ensure that only one device is transmitting at a time to avoid collisions.

Address-Based Communication

In a typical RS485 network, each device is assigned a unique address. The communication protocol uses these addresses to specify the intended recipient of each message. All other devices ignore messages not addressed to them.

Master-Slave Architecture

Many RS485 protocols use a master-slave architecture, where one device (the master) controls the communication, and the other devices (the slaves) respond only when queried by the master.

In Modbus RTU, for example, the master sends a query to a specific slave address, and only that slave responds. The master must wait for the slave’s response before sending another query.

Timing Considerations

Because RS485 is half-duplex, devices need to switch between transmit and receive modes. This switching takes a certain amount of time, which needs to be accounted for in the communication protocol.

After a device finishes transmitting, it must wait a certain amount of time before another device can start transmitting. This is often referred to as the turnaround delay.

Implementing an RS485 Interface

To implement an RS485 interface, you need an RS485 transceiver IC, which converts between the single-ended logic levels used by the UART or microcontroller and the differential signals used on the RS485 bus.

Popular RS485 transceiver ICs include:

  • MAX485
  • SN75176
  • SP3485

These ICs typically have four pins for the RS485 side (A, B, and possibly RO and DI for receive and transmit enable), and four pins for the logic side (RO, DI, RE, DE).

Schematic Example

Here’s a typical schematic for connecting a MAX485 to a microcontroller UART:

        VCC
         |
        +-+
        |
        |    +------+
        +----+      |
             | MAX485|
RXD  <-------+ RO    |        A  <----> RS485 A
             |       |        B  <----> RS485 B 
TXD  ------->+ DI    |       
             |       |        
RTS  ------->+ DE    |
        +----+ RE    |
        |    +------+
        |
       ===
        |
       GND

In this configuration, the microcontroller’s UART RXD and TXD pins connect to the MAX485’s RO and DI pins respectively. The RTS (request to send) pin controls the MAX485’s transmit enable (DE) and receive enable (RE) pins.

When RTS is low, the MAX485 is in receive mode (RE low, DE high). When RTS is high, the MAX485 is in transmit mode (RE high, DE low).

Software Considerations

On the software side, you need to implement the specific communication protocol you’re using (Modbus RTU, for example). This involves constructing the appropriate data frames, computing checksums, and handling the master-slave query-response sequence.

You also need to manage the RTS pin to control the RS485 transceiver’s direction. The general sequence is:

  1. Set RTS high to enable transmit mode
  2. Send data frame over UART
  3. Wait for transmission to complete
  4. Set RTS low to enable receive mode
  5. Wait for response (if expecting one)

The exact timing of when to switch RTS depends on the specific transceiver IC and the communication speed. Refer to the IC’s datasheet for timing specifications.

FAQs

1. What is the maximum cable length for RS485?

The maximum cable length for RS485 is 1200 meters, although in practice, the maximum achievable length depends on the data rate, cable quality, and environment.

2. How many devices can be connected to an RS485 network?

RS485 supports up to 32 devices on a single bus. With repeaters, the number can be extended even further.

3. What happens if you don’t terminate an RS485 network?

Without proper termination, signals can reflect back from the end of the cable, causing distortion and errors. Always terminate RS485 networks with 120 ohm resistors at each end of the main bus.

4. Can you use CAT5 cable for RS485?

Yes, CAT5 cable can be used for RS485. Use one twisted pair for the A and B signals, and another pair for ground. The characteristic impedance of CAT5 is close enough to 120 ohms to work well for RS485.

5. What is the difference between 2-wire and 4-wire RS485?

2-wire RS485 uses a single twisted pair for both transmit and receive (half duplex), while 4-wire RS485 uses separate twisted pairs for transmit and receive (full duplex). 2-wire is more common and is sufficient for most applications.

Conclusion

RS485 is a robust, widely-used standard for serial communication in industrial settings. Its differential signaling and multidrop capability make it ideal for long-distance, multi-device networks in noisy environments.

When implementing RS485, pay attention to proper termination, biasing, and wiring practices. Choose a suitable communication protocol and manage the half-duplex nature of RS485 in your software.

With a solid understanding of RS485’s principles and careful implementation, you can create reliable, high-performance serial communication networks for a variety of applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

Tag Cloud

There’s no content to show here yet.