Learn / Communication / RS-485 and CAN

RS-485, Modbus and CAN

ReviewedAdvanced ProAbout 6 min
NRF24
In short

RS-485, Modbus and CAN: the short answer

UART and I2C work over centimetres to a metre. Factories, vehicles and farms need links of tens or hundreds of metres in electrically noisy places.

Level
Advanced
Time
About 6 min
Topic
Communication
You will learn to

Wire reliable long-distance buses with RS-485 and CAN, including termination and addressing.

Before this: SPI, UART & Interface Trade-offs, Serial Communication Basics

UART and I2C work over centimetres to a metre. Factories, vehicles and farms need links of tens or hundreds of metres in electrically noisy places. RS-485 and CAN solve this with differential signalling: two wires carry opposite signals, and the receiver looks only at the difference, so noise that hits both wires equally cancels out. Use twisted-pair cable for the two signal wires.

RS-485 can run up to about 1,200 m at low speeds with up to 32 standard devices on one pair of wires. It is usually half-duplex: a MAX485 module has DE and RE pins that switch it between sending and receiving, controlled from a GPIO (or use an auto-direction module). On top of RS-485, most industrial sensors and energy meters speak Modbus RTU: a master sends a request with the device address, function code and register number, and the device replies. Many soil, weather and energy sensors sold in India are RS-485 Modbus.

CAN is the bus inside cars and machines. Every message has an ID, and when two devices send at once the lower ID wins without corrupting anything, so it is excellent for many devices sharing one bus. An ESP32 has a built-in CAN controller (called TWAI) and only needs a 3.3 V transceiver. An Arduino needs an MCP2515 controller with a transceiver such as the TJA1050. Both buses need a 120 Ω termination resistor at each physical end of the cable, and nowhere else. With power off, you should measure about 60 Ω between the two bus wires.

Differential signalling in the field

RS-485 and CAN send each bit as the difference between two wires, so noise that hits both equally cancels at the receiver. That is why they work over long cables and in electrically noisy places, with RS-485 reaching about a kilometre at low speed and CAN a few hundred metres at moderate speed.

Use twisted-pair cable, run as a line with short stubs rather than a star, and place a termination resistor of about 120 Ω at each of the two far ends and nowhere else.

Protocols on top

RS-485 is only the electrical layer. Modbus RTU is a common protocol over it, in which one master asks each slave by address for registers. Set the same baud rate, parity and addresses on every device, and add a short gap between messages. A direction pin switches the transceiver between sending and receiving, and must be turned off promptly after sending.

CAN has built-in arbitration, error checking and message priority, and its frames are identified by an ID instead of a destination address.

Grounding and protection

Devices on a long bus can sit at different ground potentials, so use isolated transceivers or a ground reference wire, and add surge protection where cables leave the building. Add fail-safe biasing resistors on RS-485 so the idle bus has a defined level.

Common mistakes
  • Terminating in the middle of the bus or at every device.
  • Leaving the RS-485 transmitter on after the message ends.
  • Ignoring ground differences between distant devices.
Advanced lesson · Pro plan

Practise this lesson with Pro

The explanation above is free for everyone. The practice for Advanced lessons in every domain are part of the Pro plan at ₹999 a month.

With Pro you also get: a worked example, a hands-on task, a 3-question check.

Common questions

What will I learn in "RS-485, Modbus and CAN"?

Wire reliable long-distance buses with RS-485 and CAN, including termination and addressing.