The Controller Area Network (CAN) bus is a robust vehicle bus standard that allows microcontrollers and devices to communicate with each other within a vehicle without a host computer. It is a message-based protocol, designed originally for multiplex electrical wiring within automobiles to save on copper, but is also used in many other contexts.
History of CAN Bus
CAN bus was originally developed by the German company Robert Bosch GmbH in the mid 1980s for in-vehicle networking for automotive applications. The motivation was to produce a cost-effective multiplex wiring system to replace the complex and expensive individual wiring harnesses found in vehicles at the time.
The first CAN controller chips were produced by Intel in 1987. Bosch published the CAN specification in 1991 as a standard titled “Bosch CAN Specification Version 2.0”. Since then, CAN has become widely adopted as a vehicle bus standard in the automotive and aerospace industries.
How CAN Bus Works
CAN bus uses a twisted pair of wires for communication, along with CAN transceivers at each node. The pair of wires forms a differential signaling bus. One wire is called CAN High while the other is called CAN Low. When the bus is idle, both lines are held at the same voltage. When data is transmitted, the CAN High line is driven to a higher voltage while the CAN Low is driven to a lower voltage, generating a differential voltage between the two lines that represents a logic 0 or 1.
CAN bus uses a carrier-sense multi-access protocol with collision detection and arbitration on message priority (CSMA/CD+AMP). This allows nodes to transmit without delay whenever the bus is free. If two nodes transmit at the same time, the higher priority message wins arbitration and continues while the lower priority message automatically backs off and tries again later.
Message priority is determined by the message ID, with lower ID values having higher priority. The ID not only determines priority, but also indicates the content of the message to receiving nodes. When a node receives a message, it looks at the ID to see if the message contains information relevant to that node.
CAN Bus Message Frame
All messages transmitted on a CAN bus are formatted according to the CAN standard frame format. A CAN frame consists of the following key components:
- Start of frame – Indicates the start of a new message.
- Arbitration field
- Message ID – 11 or 29 bit identifier that determines priority.
- Remote Transmission Request (RTR) – Dominant (0) for data frame, recessive (1) for remote request.
- Control field
- Data Length Code (DLC) – Indicates data payload length (0-8 bytes).
- Data field – 0-8 bytes of message data.
- CRC field – 15-bit (for 11-bit ID) or 17-bit (for 29-bit ID) cyclic redundancy check code for error detection.
- ACK slot – Transmitter sends recessive (1), receiver sends dominant (0) to acknowledge.
- End of frame – 7 recessive (1) bits to indicate end of frame.
- Interframe space – At least 3 recessive (1) bits between messages.
CAN Bus Bit Timing
CAN bus uses non-return-to-zero (NRZ) bit encoding where a dominant bit is 0 and a recessive bit is 1. Timing and synchronization is achieved using the following bit time segments:
- Sync Segment – A single dominant (0) bit to synchronize nodes to the start of a bit time.
- Propagation Segment – Phase buffer segment to compensate for physical delay times within the network.
- Phase Buffer Segment 1 – Phase buffer segment before the sampling point.
- Phase Buffer Segment 2 – Phase buffer segment after the sampling point.
The sampling point is at the intersection between Phase Buffer 1 and 2. This is where each node samples the bus level to determine if the bit is a dominant 0 or recessive 1.
The length of the above segments is configurable and determines the bit rate of the CAN bus. Common bit rates are 125 kbps, 250 kbps, 500 kbps and 1 Mbps. The higher the bit rate, the shorter the bit time segments.
CAN Bus Physical Layer
The physical layer defines the electrical implementation of the CAN bus on the wire. The ISO 11898-2 standard specifies a two-wire balanced signaling system commonly referred to as CAN High and CAN Low as described earlier.
CAN transceivers connect each node to the bus. Different types of transceivers are available for various physical media like a twisted wire pair, fiber optic cable, etc. Common CAN transceivers include:
- High-speed CAN transceiver for high-speed buses up to 1 Mbps.
- Low-speed/fault-tolerant CAN transceiver for low speed or medium speed buses with fault confinement.
- Single-wire CAN transceiver for single-wire networks with common return path.
- CAN transceiver with integrated galvanic isolation.
The bus lines must be properly terminated at each end with 120 ohm resistors to prevent signal reflection. stubs should be avoided when attaching nodes to the bus.
CAN Bus Topology
The CAN bus uses a logical bus topology that can be implemented in different physical configurations. The most common physical implementation is a linear bus with terminated ends. Other options include:
- Star bus where each node has a point-to-point connection to a central controller.
- Multiple terminated stubs connected to a linear bus backbone.
- Ring bus with repeater nodes to regenerate signals.
- Hybrid combinations of the above.
The logical bus topology means that regardless of the physical configuration, all nodes are able to communicate with each other as peer nodes. up to 30 nodes can be connected to a single bus segment. More nodes can be supported using bridges or gateways to connect multiple bus segments into a larger network.
CAN Bus Node Types
There are generally three types of nodes used on a CAN bus system:
- Master Nodes – Responsible for bus traffic control. Limited to one node per bus segment.
- Slave Nodes – Most nodes are slaves that only listen to frames with matching message IDs.
- CAN Bus Bridges – Connects two or more bus segments into a single larger bus.
Each slave node contains a CAN controller chip to implement the CAN physical layer and protocol. Many microcontrollers have integrated CAN controllers.
CAN Bus Arbitration and Collision Handling
CAN bus utilizes carrier sense multiple access with collision detection and arbitration to allow bus access to multiple nodes. Some key capabilities include:
- Carrier sense – All nodes listen to the bus before transmitting.
- Collision detection – Collisions detected via the bit monitoring process.
- Collision arbitration – Higher priority message wins arbitration over lower priority.
- Error detection – Node transmitting erroneous frame automatically aborts and retransmits.
- Fault confinement – Faulty nodes are automatically disconnected from the bus.
These capabilities provide reliable and robust communication between nodes and help ensure that the highest priority messages meet their latency requirements on the bus.
CAN Bus Message Priorities
As mentioned earlier, CAN bus arbitration is based on message priority. Message priority is determined by the message ID. There are four different formats for the message ID:
- 11-bit ID – Standard CAN – 2048 distinct message IDs from 0 to 2047.
- 29-bit ID – Extended CAN – Over 500 million distinct message IDs.
- 32-bit ID – Flexible Data-Rate Format A – Uses 29-bit ID with substitute remote request.
- 32-bit ID – Flexible Data-Rate Format B – Uses 11-bit ID with FD control bit.
Lower numeric ID values have higher priority. 0 is the highest priority. By convention, IDs under 0x100 are reserved for time critical messages like safety and control data.
CAN Bus Data Frames and Remote Frames
There are two types of frames that nodes can transmit on a CAN bus:
- Data frame – Contains a message ID and up to 8 bytes of data.
- Remote frame – Contains an ID and the remote transmission request (RTR) bit set to dominant, but no data. Used to request a data frame from another node.
Data exchange on a CAN bus predominantly uses a producer-consumer model. Data producer nodes send out data frames containing sensor measurements or status information. Consumer nodes listen for the message IDs they need and process the received data frames.
Remote frames are mainly used by consumer nodes to request additional data from producers. However, they can also be used by producers to request confirmation that transmitted data was received.
CAN Bus Error Handling
CAN bus employs advanced error detection and handling capabilities to maintain data integrity on the bus. Here are some key mechanisms:
- CRC check – Cyclic redundancy check detects errors in transmitted frames.
- ACK check – transmitting node checks for ACK bit to confirm reception.
- Bit monitoring – Any node can detect errors by monitoring bus levels.
- Error frames – Transmitting node sends error frame on detecting any error.
- Fault confinement – Faulty nodes are automatically disconnected.
These mechanisms allow CAN bus networks to operate reliably even in electrically noisy environments like inside a vehicle. Faulty nodes are isolated to prevent them from impacting the rest of the bus.
CAN Bus Speed and Message Latency
Different CAN bus implementations operate at different bus speeds depending on the application requirements. Higher bus speeds allow higher data throughput and lower message latency. Some common bus speeds include:
- 33.3 kbps – Low speed fault tolerant CAN
- 83.3 kbps – Low speed CAN
- 125 kbps – Medium speed CAN
- 250 kbps – High speed CAN
- 500 kbps – Very high speed CAN
- 1 Mbps – Ultra high speed CAN
For a 500 kbps bus speed and 8 byte data payload:
- Total bit count is 129 (including stuff bits)
- Frame takes 129 x 2 microseconds = 258 microseconds to transmit.
- Which allows approximately 4000 frames per second.
250 kbps and 125 kbps buses take 2x and 4x longer respectively. High bus speeds are mandatory for control systems and other uses requiring low latency.
CAN Bus Applications
Some of the common applications and uses of CAN bus in various industries are:
- Automotive – Engine control, telematics, infotainment, body control, etc.
- Aerospace – Communication between avionics systems.
- Industrial Automation – Connecting industrial controls and smart devices.
- Marine – Communication bus for equipment aboard ships and boats.
- Medical – Connecting medical instruments and actuators.
- Test and measurement – Data acquisition from sensors and test equipment.
CAN bus continues to find new applications due to its versatility, noise immunity, and multicast properties that allow multiple nodes to efficiently share data with low latency.
Some higher layer protocols that run on top of CAN include:
- J1939 – Heavy duty vehicle network.
- CANopen – Embedded device communication used in industrial automation, medical, etc.
- DeviceNet – Industrial device network focused on connections between sensors, actuators, controllers, etc.
In summary, the Controller Area Network or CAN bus is a robust serial communication protocol and standard that enables real-time data exchange between nodes in mission-critical distributed embedded systems. Its noise immunity, error detection and handling mechanisms, collision arbitration, prioritized messaging, and multicast capabilities make it ideal for applications like in-vehicle networks as well as industrial control systems.