01-12-2020 | | By Sam Brown
The CAN bus is an essential network for vehicles that allows ECUs to communicate with each other. As an engineer, it is always nice to step back and appreciate the genius of such systems, so in this article, we will understand how CAN bus arbitration works.
Controller Area Network, or CAN for short, is a network that is mostly found in vehicular systems that allow for Electronic Control Units (ECUs), to communicate with each other. What makes CAN a unique bus is that there are no network controllers, bus managers, or a central control system, but instead all devices connect to the same physical bus.
CAN has some similarities to USB with the first being that the CAN bus has only two wires for data transmission. These wires carry differential signals which indicate either a 0 or a 1, and the use of a differential signal allows for a robust network which is resistant to common-mode noise and interference. However, unlike USB, CAN has two distinct polarities; CAN High and CAN Low. When the two wires are at the same voltage, then a 1 bit is transmitted, and when they are different, a 0 is transmitted.
Logic 1’s on the bus are also referred to as recessive while 0’s are referred to as dominant. This is important because it refers to the transceivers driving circuitry when interacting with a bus. If a device wants to put a 0 on the bus, it needs to force the lines to their appropriate levels, thus making that device dominant on the whole bus for all connected devices. If the device wants to put a 1 on the bus, then its transceiver circuitry leaves the bus alone.
CAN frame and priority
Being a bus designed for vehicular applications, messages on the bus must be robust and free from error. With so many ECUs in a vehicle, it is also important that certain devices have priority over others (for example, an airbag safety system is far more important than the air conditioning current temperature). Therefore, devices on the bus need to be able to organise themselves so that the device with the highest priority can always send its data packet.
CAN messages, also known as frames, are rather simple consisting of a start bit, arbitration field, message information, data, CRC, some additional (but not entirely important ACK bits), and the end frame. The start bit is a 0, and thus causes the two lines on the CAN bus to take different voltages. The next field is the arbitration number (11-bits), and the device with the lowest number is given the bus. The control field indicates the size of the message, and the data field is the data the ECU is sending (up to 8 bytes). After this is the CRC which provides error correction, and after this is the end of the frame to indicate to all connected devices that the frame is complete.
At this point, most, if not all engineers working with CAN on microcontrollers and other ECUs do not need to worry about how the bus is actually implemented on the hardware level. Instead, the CAN detail of the device need to be coded in, and the bus can be used like any other communication system where data bytes stream in, and bytes stream out. However, when researching CAN, I wondered how does a device gain arbitration with no central controller and only two wires? After understanding the hardware layer involved, the method is entirely ingenious.
The first and most important rule that must be followed for this to work is that all CAN devices on the same bus must operate at the same frequency. This means that when all connected devices read and write to the bus, they operate in unison on the same bits at the same time. Therefore, if two devices want control of the bus, they both start the transmission of their start frames at the same time. The second rule is that all devices monitor the bus and compare it to what they are trying to send.
Device A is a safety control system and has a low arbitration field value of binary 1101, while Device B is an entertainment system with an arbitration value of 1110. When either device sends a 1, their circuitry will relax and not drive the bus (recessive), and if either device wants to send a 0, their circuitry will drive the bus (dominant).
Both devices send their frame start bit, which is a 0. Therefore both circuits drive the bus to a 0. As far as each device is concerned, they are controlling the bus.
Both devices send the first bit of their arbitration field (most significant bit first), and both are 1. Neither device drives the bus, and both devices monitor the bus as being 1, so both are content that they have the bus so far. The same happens when both devices send their second arbitration bit as they are the same as each other.
However, when both devices send their third arbitration bit, something remarkable happens. Device A, who has the lowest value, sends a 0 on the bus by driving the bus to its differential state. Device B, however, transmits a 1 by doing nothing. When Device B looks at the bus, it sees that, despite leaving the bus alone, the signals are different. It is at this moment that Device B recognises that another device has a lower number than itself, therefore having priority over it.
It is very easy for engineers to overlook the underlying hardware of their systems, especially when a lot of effort goes into hiding how it works. While CAN is not entirely ideal for large data packets, its arbitration system shows how just two wires, and some clever circuitry, can be used to create a very clever system that allows for devices to recognise their place in a system without any need for a centralised controller. It also allows for any device to read any other device so that systems can work independently to a centralised computer.
The use of transceivers that both monitor and drive differential signals is a remarkable piece of engineering, and can be easily deployed in discrete circuity without the need for a CPU. A bus that is robust, reliable, and requires only two wires!