controller area network bus the protocol

Posted by

Introduction to Controller Area Network (CAN) Bus

The Controller Area Network (CAN) bus is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other’s applications without a host computer. It is a message-based protocol, designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other contexts.

History of CAN Bus

CAN bus was developed by Bosch in 1986 for automotive applications. It was designed to be a reliable, efficient, and cost-effective communication protocol for connecting electronic control units (ECUs) in vehicles. Since then, CAN bus has become the de facto standard for in-vehicle communication and has been adopted in various other industries, such as industrial automation, medical equipment, and aerospace.

Key Features of CAN Bus

  1. Multi-master architecture: All nodes on the CAN bus have equal access to the bus and can initiate communication.
  2. Message-based communication: Data is transmitted in the form of messages, which include an identifier, data length code, and up to 8 bytes of data.
  3. Priority-based arbitration: When multiple nodes attempt to transmit simultaneously, the message with the highest priority (lowest ID) wins arbitration and is transmitted first.
  4. Error detection and handling: CAN bus includes sophisticated error detection and handling mechanisms to ensure data integrity and system reliability.
  5. Flexible data rate: CAN bus supports data rates up to 1 Mbps, depending on the network length and transceiver characteristics.

CAN Bus Protocol Stack

The CAN bus protocol stack consists of several layers, each responsible for specific functions. The layers are:

  1. Physical Layer: Defines the physical characteristics of the bus, such as the type of cable, connectors, and signal levels.
  2. Data Link Layer: Responsible for message framing, arbitration, acknowledgment, and error detection.
  3. Application Layer: Defines the application-specific protocols and message formats used by the higher-level software.

Physical Layer

The physical layer of the CAN bus protocol defines the electrical and mechanical characteristics of the bus. Some key aspects of the physical layer include:

  • Differential signaling: CAN bus uses a two-wire differential signaling scheme, with CAN_H and CAN_L lines.
  • Termination resistors: A 120 Ω termination resistor is required at each end of the bus to prevent signal reflections.
  • Transceiver characteristics: CAN transceivers must meet specific electrical characteristics, such as driver output voltage, receiver input thresholds, and rise/fall times.

Data Link Layer

The data link layer is the core of the CAN bus protocol and is responsible for message framing, arbitration, acknowledgment, and error detection. The data link layer is divided into two sublayers:

  1. Logical Link Control (LLC): Responsible for message filtering and recovery management.
  2. Medium Access Control (MAC): Responsible for message framing, arbitration, acknowledgment, and error detection.

Message Frame Format

CAN bus messages are transmitted in frames, which consist of several fields:

Field Description
Start of Frame (SOF) Single dominant bit indicating the start of a frame
Arbitration Field 11-bit (standard) or 29-bit (extended) identifier and RTR bit
Control Field 6-bit field containing the Data Length Code (DLC)
Data Field 0 to 8 bytes of data
CRC Field 15-bit Cyclic Redundancy Check (CRC) for error detection
ACK Field 2-bit field for acknowledgment (ACK slot and ACK delimiter)
End of Frame (EOF) 7-bit field indicating the end of the frame
Intermission (INT) 3-bit field separating consecutive messages

Arbitration and Priority

CAN bus uses a priority-based arbitration scheme to determine which message is transmitted when multiple nodes attempt to transmit simultaneously. The arbitration process works as follows:

  1. All nodes start transmitting their message identifiers simultaneously.
  2. If a node transmits a recessive bit (logical 1) while another node transmits a dominant bit (logical 0), the node transmitting the recessive bit loses arbitration and stops transmitting.
  3. The node that successfully transmits all identifier bits without losing arbitration wins and continues transmitting its message.

This arbitration scheme ensures that the message with the lowest identifier (highest priority) is always transmitted first, making CAN bus deterministic and real-time capable.

Error Detection and Handling

CAN bus includes several error detection and handling mechanisms to ensure data integrity and system reliability:

  1. Bit Stuffing: After five consecutive bits of the same polarity, a stuff bit of the opposite polarity is inserted to maintain synchronization.
  2. Frame Check: Each frame includes a 15-bit CRC to detect transmission errors.
  3. Acknowledgment: All nodes receiving a valid message must acknowledge it by overwriting the recessive ACK slot with a dominant bit.
  4. Error Signaling: If a node detects an error, it transmits an error frame, which consists of six consecutive dominant bits, violating the bit-stuffing rule and forcing other nodes to detect the error.

When an error is detected, the transmitting node automatically retransmits the message. If a node detects too many errors, it can enter a bus-off state to prevent faulty nodes from disturbing the network.

Application Layer

The application layer of the CAN bus protocol defines the application-specific protocols and message formats used by the higher-level software. Some common application layer protocols include:

  • CANopen: A standardized application layer protocol for embedded systems, widely used in industrial automation and motion control applications.
  • DeviceNet: An application layer protocol developed by Allen-Bradley (now Rockwell Automation) for industrial automation applications.
  • J1939: A vehicle bus standard used in heavy-duty vehicles, such as trucks and buses, for communication between the engine, transmission, brakes, and other subsystems.

Application layer protocols define the specific message formats, data types, and communication services used by the application software.

CAN Bus Physical Layer Implementation

CAN Bus Wiring

CAN bus networks typically use a twisted pair cable with a characteristic impedance of 120 Ω. The two wires, CAN_H and CAN_L, carry differential signals, which helps to reduce the impact of electromagnetic interference (EMI) on the network.

120 Ω termination resistors are required at each end of the bus to prevent signal reflections and ensure proper signal integrity. In some cases, split termination (two 60 Ω resistors in series) or switchable termination may be used to accommodate network changes or to conserve power.

CAN Transceivers

CAN transceivers are responsible for converting the digital signals from the CAN controller to the differential signals on the bus, and vice versa. They also provide protection against electrical faults and transients.

Some common CAN transceiver features include:

  • Driver output voltage: CAN transceivers typically have a driver output voltage of 2.5 V to 5 V, depending on the supply voltage and the specific transceiver.
  • Receiver input thresholds: The receiver input thresholds determine the minimum differential voltage required to detect a valid signal. Typical thresholds are around 0.9 V for a dominant bit and 0.5 V for a recessive bit.
  • Rise and fall times: CAN transceivers must meet specific rise and fall time requirements to ensure proper signal integrity and to minimize electromagnetic emissions.
  • Fault protection: Many CAN transceivers include features such as thermal shutdown, short-circuit protection, and electrostatic discharge (ESD) protection to enhance system reliability.

CAN Bus Network Topology

CAN bus networks can be implemented using various topologies, depending on the application requirements and the physical layout of the system. The most common topologies are:

  1. Linear topology: Nodes are connected in a single line, with termination resistors at each end of the bus. This is the simplest and most common topology for CAN bus networks.
  2. Star topology: Nodes are connected to a central hub, which acts as a repeater. This topology can be useful for connecting multiple linear segments or for isolating faulty nodes.
  3. Hybrid topology: A combination of linear and star topologies, where multiple linear segments are connected through a central hub. This topology provides flexibility and can help to overcome the limitations of long bus lengths.

When designing a CAN bus network, it is essential to consider factors such as the number of nodes, the total bus length, the data rate, and the environmental conditions to ensure reliable communication.

CAN Bus Data Link Layer Implementation

Message Framing

CAN bus messages are transmitted in frames, which consist of several fields. The two main frame formats are:

  1. Standard Frame Format (CAN 2.0A):
  2. 11-bit identifier
  3. Up to 8 bytes of data
  4. Maximum data rate of 1 Mbps

  5. Extended Frame Format (CAN 2.0B):

  6. 29-bit identifier
  7. Up to 8 bytes of data
  8. Maximum data rate of 1 Mbps

The extended frame format is backward compatible with the standard frame format, allowing devices using both formats to coexist on the same network.

Bit Timing and Synchronization

Proper bit timing and synchronization are crucial for reliable communication on the CAN bus. The CAN controller at each node must be configured with the correct bit timing parameters to ensure that all nodes sample the bus at the same time.

The bit timing parameters include:

  • Nominal Bit Rate: The number of bits per second transmitted on the bus.
  • Time Quantum: The smallest time unit on the CAN bus, derived from the oscillator frequency and the baud rate prescaler.
  • Synchronization Segment: A fixed portion of the bit time used for synchronization.
  • Propagation Segment: Compensates for the physical delay times within the network.
  • Phase Segments (Phase Segment 1 and Phase Segment 2): Used to compensate for edge phase errors and to resynchronize the nodes.

The CAN controller at each node continuously resynchronizes its bit timing to the bus to maintain synchronization. This is done by adjusting the sample point within the bit time based on the observed edge transitions on the bus.

Error Detection and Management

CAN bus includes several error detection and management mechanisms to ensure data integrity and system reliability. These mechanisms include:

  1. Cyclic Redundancy Check (CRC): Each frame includes a 15-bit CRC to detect transmission errors. The transmitting node calculates the CRC based on the frame data, and the receiving nodes verify the CRC to detect any errors.

  2. Stuff Rule Violation: After five consecutive bits of the same polarity, a stuff bit of the opposite polarity is inserted to maintain synchronization. If a receiving node detects a violation of this rule, it signals an error.

  3. Frame Check: Receiving nodes check the format of each frame to ensure that it complies with the CAN specification. If a node detects an invalid frame format, it signals an error.

  4. Acknowledgment (ACK) Error: All nodes receiving a valid message must acknowledge it by overwriting the recessive ACK slot with a dominant bit. If the transmitting node does not detect a dominant bit in the ACK slot, it signals an ACK error.

When a node detects an error, it transmits an error frame, which consists of six consecutive dominant bits, violating the bit-stuffing rule and forcing other nodes to detect the error. The transmitting node then automatically retransmits the message.

CAN nodes maintain error counters to keep track of the number of errors they detect and transmit. If a node detects too many errors, it can enter a bus-off state, where it disconnects itself from the bus to prevent faulty nodes from disturbing the network.

CAN Bus Application Layer Protocols

The CAN bus application layer defines the application-specific protocols and message formats used by the higher-level software. Some common application layer protocols include:

CANopen

CANopen is a standardized application layer protocol for embedded systems, widely used in industrial automation and motion control applications. It provides a set of communication services and device profiles to ensure interoperability between devices from different manufacturers.

Key features of CANopen include:

  • Object Dictionary: A structured collection of all the data items and configuration parameters used by a CANopen device.
  • Process Data Objects (PDOs): Used for real-time data exchange between devices, mapped to specific CAN message identifiers.
  • Service Data Objects (SDOs): Used for non-real-time data exchange, such as device configuration and parameter access.
  • Network Management (NMT): Provides services for network initialization, node monitoring, and error control.
  • Standardized Device Profiles: Define the functionality and communication behavior of specific device types, such as I/O modules, drives, and encoders.

DeviceNet

DeviceNet is an application layer protocol developed by Allen-Bradley (now Rockwell Automation) for industrial automation applications. It is based on the CAN bus and provides a set of communication services and device profiles for connecting industrial devices, such as sensors, actuators, and controllers.

Key features of DeviceNet include:

  • Predefined Connection Sets: Define the communication behavior and data format for specific device types, such as discrete I/O, analog I/O, and safety devices.
  • Explicit Messaging: Used for non-real-time data exchange, such as device configuration and diagnostic information.
  • I/O Messaging: Used for real-time data exchange between devices, mapped to specific CAN message identifiers.
  • Device Profiles: Define the functionality and communication behavior of specific device types, ensuring interoperability between devices from different manufacturers.

J1939

J1939 is a vehicle bus standard used in heavy-duty vehicles, such as trucks and buses, for communication between the engine, transmission, brakes, and other subsystems. It is based on the CAN bus and defines a set of application layer protocols and message formats for vehicle control and monitoring.

Key features of J1939 include:

  • Parameter Groups: Define the data format and scaling for specific vehicle parameters, such as engine speed, coolant temperature, and fuel level.
  • Suspect Parameter Numbers (SPNs): Unique identifiers for each vehicle parameter, used for diagnostic and troubleshooting purposes.
  • Parameter Group Numbers (PGNs): Define the message format and priority for specific groups of parameters, such as engine control, transmission control, and vehicle navigation.
  • Network Management: Provides services for network initialization, node addressing, and error control.
  • Diagnostics: Defines a set of diagnostic messages and protocols for identifying and troubleshooting vehicle faults.

J1939 has been adopted by various industry groups and has spawned several related standards, such as J1587 (for older vehicles) and ISO 11783 (for agricultural and forestry equipment).

Frequently Asked Questions (FAQ)

  1. What is the maximum data rate supported by CAN bus?
    The maximum data rate supported by CAN bus is 1 Mbps, but the actual data rate depends on the network length and transceiver characteristics. Longer networks may require lower data rates to ensure reliable communication.

  2. How many nodes can be connected to a CAN bus network?
    Theoretically, CAN bus supports up to 2^11 (2,048) nodes for standard frame format and 2^29 (536,870,912) nodes for extended frame format. However, in practice, the number of nodes is limited by factors such as bus length, data rate, and transceiver characteristics. Typical CAN bus networks have fewer than 100 nodes.

  3. What is the difference between standard and extended frame formats in CAN bus?
    The standard frame format (CAN 2.0A) uses an 11-bit identifier and supports up to 2,048 unique message identifiers. The extended frame format (CAN 2.0B) uses a 29-bit identifier and supports up to 536,870,912 unique message identifiers. Both formats support up to 8 bytes of data per message.

  4. How does CAN bus handle message collisions?
    CAN bus uses a priority-based arbitration scheme to handle message collisions. When multiple nodes attempt to transmit simultaneously, the message with the lowest identifier (highest priority) wins arbitration and is transmitted first. The other nodes automatically back off and retry transmission later.

  5. What are the main advantages of using CAN bus in automotive and industrial applications?
    CAN bus offers several advantages, including:

  6. Robust error detection and handling mechanisms, ensuring high data integrity and system reliability.
  7. Priority-based arbitration, enabling deterministic and real-time communication.
  8. Flexibility in network topology and node count, supporting a wide range of applications.
  9. Reduced wiring complexity and cost compared to traditional point-to-point wiring.
  10. Availability of standardized application layer protocols, promoting interoperability between devices from different manufacturers.

Conclusion

The Controller Area Network (CAN) bus is a robust and reliable communication protocol widely used in automotive and industrial applications. Its multi-master architecture, message-based communication, and priority-based arbitration make it well-suited for real-time, distributed control systems.

The CAN bus protocol stack, consisting of the physical layer, data link layer, and application layer, provides a comprehensive framework for implementing CAN-based networks. The physical layer defines the electrical

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

Tag Cloud

There’s no content to show here yet.