CAN bus/How the bus decides/03. Dominant wins
How the bus decides · 03 of 9

Dominant wins

Every CAN message starts with an identifier, and when two boards start at the same instant the identifiers decide who goes first. Each board reads the bus while it sends; the first to send a 1 and read back a 0 stops and listens. The lower identifier always wins, and its message goes out whole.

Identifiers, not addresses

A CAN message carries an identifier, 11 bits in the standard format, so from 0x000 to 0x7FF. It says what the message is (a temperature, a switch, a motor speed), not who it is for. Every board receives every message and keeps the ones it wants.

When two start at once

Both boards send their identifier bit by bit, highest bit first, and read the bus back as they go. While their bits agree, nothing happens. At the first bit where one sends 1 and the other 0, the bus shows 0, because 0 is dominant. The board that sent 1 reads back a 0 it did not send, stops sending, and becomes a listener.

The lower identifier wins
arbitrating
Board B's identifier
Board A
0x100
Board B
0x0F0
Decided at bit
8
Press Send both. Both boards start together. Watch for the first bit where they differ.

The winner never noticed. Its message carries on without a single bit disturbed, and the loser tries again as soon as the bus is free.

What it means for your sketch

  • Lower identifier, higher priority. 0x010 beats 0x100 every time.
  • One identifier per kind of message, per board. Two boards sending the same identifier both win arbitration and then collide in the data.
  • Nothing to write. Arbitration happens in the CAN controller. The sketch queues a message and the controller sends it when the bus lets it.

When it does not work

Can two boards use the same identifier?

Not if both might send it. Two boards sending the same identifier at the same moment both win arbitration and then collide in the data, which shows up as errors. Give each kind of message, from each board, an identifier of its own.

My low-priority messages hardly ever get through.

On a busy bus the lowest identifiers always win, so a high identifier waits whenever anything else wants the bus. Send the frequent messages less often, or give the one that matters a lower identifier.

Does the identifier say which board a message is for?

No. It says what the message is, and every board receives every message. A board that only cares about some identifiers sets its controller's acceptance filter, so the rest never reach the sketch.

Where this goes next

Why a board on its own can never finish sending.

Every message is acknowledged

Edit this page — content/books/can-bus/dominant-wins.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

CAN Bus

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum