1
\$\begingroup\$

I've worked with CAN bus recently and started to wonder what would happen if multiple devices on a network suddenly happen to broadcast at the same time.

I mean every device on the CAN-bus network receives each other's messages. But since they are on the same bus, wouldn't there be a conflict resulting in some devices not receiving some of the other's messages? I see it as a one-way street where you have two cars trying to go each other's opposite direction resulting in a crash and not reaching their destination.

I couldn't find anything about this on the Internet....plus this question probably relates to I²C as well or any other similar communication protocols.

\$\endgroup\$
4
  • 7
    \$\begingroup\$ Well, you didn't look very hard in your search. The Wikipedia article tells you exactly how this is handled. \$\endgroup\$
    – Finbarr
    Dec 28, 2017 at 9:39
  • \$\begingroup\$ Study CAN bus arbitration. It does not "crash" because CAN is CSMA/CA instead of CSMA/CD. This is the very basics you need to understand, before you can understand anything else about CAN bus hardware and protocols. \$\endgroup\$
    – Lundin
    Jan 8, 2018 at 15:00
  • \$\begingroup\$ I'd recommend reading the first chapters of Controller Area Network. \$\endgroup\$
    – Lundin
    Jan 8, 2018 at 15:09
  • \$\begingroup\$ This is the defining aspect of CAN. It's one of the first things you run into when reading about it. \$\endgroup\$
    – DKNguyen
    Feb 19, 2019 at 5:49

1 Answer 1

1
\$\begingroup\$

As you stated, every node receives the others' messages. This allows the nodes to prevent any conflicts on the bus by listening the bus. Each node listens the bus before transmitting a message. If the bus is not busy then the node transmits its message.

There's also a priority mechanism to avoid conflicts: If a message has a higher priority (i.e. lower ID) then it gets the bus access. An example:

Let's assume there are two transmitters trying to transmit a message. One having an ID of 0x7FA and the other 0x7FF. They started to transmit right at the same time by transmitting the SOF (Start of frame) bit.

A: ¯¯¯¯¯¯¯¯¯|___|¯ SOF

B: ¯¯¯¯¯¯¯¯¯|___|¯ SOF

There's no conflict here. Then they send the ID bit-by-bit but MSB first.

A: ¯¯¯¯¯¯¯¯¯|___|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|___|¯¯¯|___| SOF 1 1 1 1 1 1 1 1 0 1 0 | 7 | F | A | | | conflict here | B: ¯¯¯¯¯¯¯¯¯|___|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯| SOF 1 1 1 1 1 1 1 1 1 1 1 | 7 | F | F |

The conflict occurs when the 9th bit (i.e. 3rd bit of the ID) is sent. The 2nd device loses arbitration (because it has lower priority due to higher ID) and leaves out the bus thus the 1st device wins and continues transmitting its message.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, I just happen to have read it on the wiki page as Finbarr pointed out in the other comments....but very well explained. \$\endgroup\$
    – Flint
    Dec 28, 2017 at 10:13
  • 1
    \$\begingroup\$ It's worth adding that the bus is only actively driven when sending a zero bit. Ones are transmitted by allowing the termination resistor to pull the lines together, which is why there is no electrical issue when one device tries to send a zero at the same time as another device sends a one. \$\endgroup\$
    – Finbarr
    Dec 28, 2017 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.