UNIT 10 · LESSON 5 OF 6

Differential and Multinode Networks

How do industrial and automotive systems run many devices over long, noisy cables?

INTERACTIVEWhy long links use two wires per signal
A single-ended and a differential signal with the same common-mode noisesingle-endedA and BA − B101101?01?1011010010sent 1011010010: single-ended 2 bits wrong or undefined; differential all correctThe noise is common to both wires, so the difference is untouched.
A single-ended and a differential signal with the same common-mode noisesingle-endedA and BA − B101101?01?1011010010sent 1011010010: single-ended 2 bits wrong orundefined; differential all correctThe noise is common to both wires, so the differenceis untouched.

Try this

Single-ended errors 2; differential errors 0.

A single-ended receiver compares one wire with its own ground, so noise picked up along the cable and any difference between the two ends’ grounds add straight to the signal. A differential pair drives two wires in opposite directions and the receiver looks only at the difference: noise that appears equally on both wires cancels. Thresholds are illustrative: 0.8 V/2.0 V for the single-ended input, ±0.2 V for the differential receiver, whose common-mode range is assumed to cover the noise.

What you will be able to do
  • Explain why ground differences and picked-up noise corrupt single-ended signals over long cables, and how a differential receiver rejects them.
  • Explain why a long bus needs termination at both ends and nowhere else.
  • Control an RS-485 driver enable correctly, including the timing at the end of a transmission.
  • Predict the winner of CAN arbitration from the identifiers, and explain why identifiers must be unique.
  • Describe CAN’s error states and what bus-off means for a node.
Before you start
  • Voltage, current and ground (unit 1, lesson 1).
  • The UART, its FIFOs and the BUSY flag (lesson 2).
Steps in this lesson
  1. Why single-ended links fail over distance
  2. Differential signalling
  3. Termination
  4. RS-485: a multipoint UART
  5. CAN: arbitration without collisions
  6. Staying in step, and staying out of the way
  7. Worked example: the RS-485 turnaround bug
  8. Common misconceptions

The puzzle

A UART link to a sensor 30 m away works in the lab and fails on the factory floor whenever a motor starts. A second sensor on the same cable would be convenient, but a UART is strictly point to point. How do industrial and automotive systems run many devices over long, noisy cables?

STEP 2

Differential signalling

A differential driver sends each bit on a pair of wires, one going up while the other goes down. The receiver measures only the difference between them. Noise coupled onto a tightly twisted pair appears almost equally on both wires (common mode) and cancels in the difference; a ground shift also moves both wires together. The receiver’s common-mode range, from its datasheet, bounds how far both wires may move together.

↑ This step uses the figure at the top of the page.

STEP 3

Termination

On a long cable, an edge travels as a wave. At an unterminated end it reflects and returns, ringing across the following bits. A resistor at each end of the bus equal to the cable’s characteristic impedance (typically about 120 Ω for the twisted pairs used by RS-485 and CAN) absorbs the wave. Terminate the two physical ends only: termination in the middle loads the bus, and stubs to each node should be short.

STEP 4

RS-485: a multipoint UART

RS-485 defines differential drivers and receivers for multipoint links; the data is usually ordinary UART frames. On a two-wire (half-duplex) bus only one node may drive at a time, so each transceiver has a driver enable, typically on a GPIO or the UART’s RTS pin. The sequence for sending is:

  1. enable the driver (some transceivers need a short delay before the first bit);
  2. send the frame;
  3. wait until the last stop bit has left the shift register;
  4. disable the driver, so the reply is not blocked.

Linux exposes exactly these controls: RTS level on send and after send, and delays before and after. A protocol above RS-485, such as Modbus RTU (lesson 6), provides the addressing; the bus itself has none.

STEP 5

CAN: arbitration without collisions

CAN is a differential multi-controller bus in which any node may start sending when the bus is idle. A 0 is dominant and a 1 recessive: if any node drives 0, the bus reads 0. After a start-of-frame bit, frames send an 11-bit (or 29-bit) identifier, most significant bit first (a few control bits after it also take part in arbitration), and every node listens while it sends. A node that sends recessive but reads dominant has lost arbitration: it stops and retries after the frame. The frame with the lowest identifier continues without damage or delay.

INTERACTIVECAN arbitration: the lowest identifier wins
Bit-by-bit CAN arbitration between three nodes109876543210A 0x1230010010001B 0x12000100100000C 0x30101bus00100100000B wins with the lowest identifier and its frame continues undamaged; A backs off atbit 1, C backs off at bit 9.
Bit-by-bit CAN arbitration between three nodes109876543210A 0x1230010010001B 0x12000100100000C 0x30101bus00100100000B wins with the lowest identifier and its framecontinues undamaged; A backs off at bit 1, C backsoff at bit 9.
Node A identifier
Node B identifier
Node C identifier
B wins.

On a CAN bus a 0 is dominant and a 1 recessive: if any node sends 0, the bus reads 0. Nodes that start a frame at the same time send their identifiers bit by bit, most significant first, and each listens to the bus. A node that sends a recessive 1 but reads a dominant 0 has lost; it stops and retries after the frame. The frame with the lowest identifier continues undamaged, so identifiers set priority and must be unique on the bus.

Identifiers are therefore priorities, not addresses: every node receives every frame and filters the identifiers it wants. Two nodes must never send the same identifier, because both would win arbitration and then collide in the data. A classic CAN frame carries up to 8 data bytes (CAN FD up to 64).

STEP 6

Staying in step, and staying out of the way

CAN has no clock wire; nodes resynchronise on edges, and after five equal bits the sender stuffs an opposite bit (lesson 1). Every node counts errors. A node whose error counters exceed 127 becomes error passive and may no longer destroy other frames with active error flags; if its transmit errors keep rising, it goes bus-off and stops driving the bus entirely. It may rejoin only after seeing 128 occurrences of 11 recessive bits, and many controllers wait for software to request that recovery. A single faulty node cannot hold the whole network hostage.

STEP 7

Worked example: the RS-485 turnaround bug

A node at 115 200 baud sends an 8-byte request and disables its driver as soon as the transmit FIFO reports empty. The request arrives with its last byte corrupted. The FIFO was empty, but the last byte was still in the shift register, a full frame of

tframe=10 bits115 200 bit/s≈86.8 μst_{\text{frame}} = \frac{10\ \text{bits}}{115\,200\ \text{bit/s}} \approx 86.8\ \mu\text{s}

and the driver was switched off while it was going out. Waiting for the UART’s BUSY flag to clear (the pico-sdk’s uart_tx_wait_blocking()) before disabling the driver fixes it. Waiting much longer causes the opposite failure: the device’s reply starts while this node is still driving the bus.

MYTHS AND FACTS

Common misconceptions

Twisting the wires is optional

Twisting makes the coupled noise equal on both wires; without it the difference picks up noise too.

More termination is safer

Exactly two resistors, at the two ends; extra ones load the drivers.

The CAN identifier is the node address

It names the message and sets its priority; any node may receive it.

A differential link needs no ground

The receiver still needs both wires within its common-mode range, which usually means a ground or reference connection.

Check yourself

Answer in your head, then open the card.

Nodes with identifiers 0x120, 0x123 and 0x301 start sending at once. Which wins, and when does each loser back off?

0x120 wins. 0x301 backs off at bit 9 (it sends 1 while the others send 0); 0x123 backs off at bit 1, where it sends 1 and 0x120 sends 0.

Why must an RS-485 driver be disabled promptly after the last stop bit?

On a half-duplex bus the other node may reply immediately; a driver still enabled would fight its reply.

A 50 m RS-485 bus has termination resistors at both ends and a third one at a node in the middle. What happens?

The three resistors load the drivers more heavily and reduce the differential voltage; the middle one also causes a reflection. Remove it.

A CAN node with a faulty transceiver keeps corrupting frames. What happens to it and to the rest of the network?

Its error counters rise: above 127 it becomes error passive, and with further transmit errors it goes bus-off and stops driving the bus. The other nodes carry on.

Sources (4)
  1. Linux kernel, Documentation/driver-api/serial/serial-rs485.rst — RS-485 “a standard defining the electrical characteristics of drivers and receivers for use in balanced digital multipoint systems … used effectively over long distances and in electrically noisy environments”; half-duplex direction control via RTS: SER_RS485_RTS_ON_SEND, SER_RS485_RTS_AFTER_SEND, delay_rts_before_send, delay_rts_after_send, SER_RS485_RX_DURING_TX
  2. Zephyr Project, doc/hardware/peripherals/can/controller.rst — 11-bit or 29-bit identifiers; “write collisions are allowed. They resolve by the fact that dominant bits override recessive bits … This effectively gives lower number identifiers priority”; sample point recommended at 87.5 %; error counters: above 127 “error-passive”, then bus-off, where a node may not send dominant bits and “may recover after receiving 128 occurrences of 11 concurrent recessive bits”
  3. Linux kernel, include/uapi/linux/can.h and Documentation/networking/can.rst — CAN_SFF_MASK 0x7FF (11-bit), CAN_EFF_MASK 0x1FFFFFFF (29-bit), CAN_MAX_DLEN 8, CANFD_MAX_DLEN 64; can.rst: CAN is “a broadcast-only(!) medium that has no MAC-layer addressing … the CAN-IDs have to be chosen uniquely on the bus”
  4. Raspberry Pi Ltd, pico-sdk 1.5.1, hardware_uart/uart.h and rp2040/hardware_regs/uart.h — uart_tx_wait_blocking() loops while UARTFR BUSY is set; BUSY “remains set until the complete byte, including all the stop bits, has been sent from the shift register”