Controller Area Network (CAN) Link Layer

The CAN architecture layers a link layer protocol on the CAN physical layer. This is responsible for transmission of CAN frames.

A Producer-Consumer model

Many CAN systems use a Producer-Consumer model. For people who are used to the idea of sending specific messages from A to B – a source-destination model, the producer-consumer is a very different concept, although this is widely used for industrial control systems.

Imagine changing a switch on a control panel (or triggering a sensor). This creates an Event (a message). A CAN frame is then sent on to the bus containing this message. This frame contains no source address, no destination address, no information, just an Event number and perhaps some status data. The node sending an event is called a Producer.

Nodes capable of processing an event are called Consumers. Every consumer connected to the bus receives all events. What the consumer does when it sees an event will depend on the configuration information setup at the specific consumer. In effect, a consumer has to be taught what to do with any event that it wishes to act upon and will ignore any other events that are not relevant. here is no limit to the number of β€œconsumers” providing they are a Receive Only node.

This is an extremely powerful and very flexible arrangement. Producers can send many events. More than one consumer can be configured to act on a specific event and can recat in the same or in different ways. Consumers can also act in the same way for more than one event. Using a Producer-Consumer model, effectively transfers some of the decision making from the producer to the consumer.

CAN Frame Format

The CAN Frame format is structured like this:

Start of Frame (1b) = 0
Message ID (11b for CAN 2.0A)
Control fields (3b)
Data Length (4b)
Data (0-64b)
CRC (15b)
ACK fields (3b)
End of Frame Delimiter (7b)

A Cyclic Redundancy Field (CRC-15) field is included in each frame . CAN provides sophisticated error-detection and error handling mechanisms such as CRC check, and high immunity against electromagnetic interference. Erroneous messages are automatically retransmitted.

All nodes receive all the frames that are sent on the bus. They can be configured to filter based on a set of message IDs. Nodes discard any frames that do not match one of the configured filters.

Nodes discard frames with any formatting errors and/or CRC errors. When calculating the Frame CRC, the message is regarded as a binary polynomial. This is then divided using modulo-2 arithmetic with a CRC generator polynomial, following the form: π‘₯15 +π‘₯14 +π‘₯10 +π‘₯8 +π‘₯7 +π‘₯4 +π‘₯3 +1. This generates a CRC field that can be used to veirfy the integrity of each received frame.

CAN specifies 4 types of frames:

The original CAN specifications (Versions 1.0, 1.2 and 2.0A) specified an 11 bit message identifier, CAN 2.0B supports both 11 and 29 bit formats. This is known as Standard CAN.

Two variants are common:

CAN Medium Access

Access to the bus is using a half-duplex with a distributed architecture. Bus nodes do not have a specific address. Instead, the address information is contained in the identifiers of the messages that are transmitted. Hence each message ID indicates the type of content and the priority. The lack of addresses allows the number of nodes to be changed dynamically without disturbing the communication of existing nodes - useful when nodes need to be replaced or new nodes added to an existing bus.

When a node has no data to send (or between frames), a node sends at least 3 recessive bits (1-value), called the Intermission. This time allows nodes to perform internal processing before the start of the next message.

A "Data Frame" is generated by a CAN node when a node wishes to transmit data. Each frame carry up to 8 data bytes. The small size results in a low latency between transmission request and start of transmission.

Access to the bus access is handled via the Carrier Sense Multiple Access/Collision Detection with Non-Destructive Arbitration, which allows any node to start transmission of a message after an Intermission. It requires any sending node to monitor the bus to see if the transmission is successful. Each message starts with the message ID. Note the first bit where a 0 (driven bus) is forced onto a 1 (floating bus) signal, recessive bit. This indicates the place where arbitration takes place. A dominant bit with a 0 level always wins. This means that during the transmission of the message ID the lowest numbered message always wins, other nodes stop sending and retransmit later.


See also:

Prof. Gorry Fairhurst, School of Engineering, University of Aberdeen, Scotland (2024).