這是一張有關標題為 Characteristics and Key Points of Controller Area Network (CAN bus) 的圖片

Characteristics and Key Points of Controller Area Network (CAN bus)

A detailed explanation of the CAN communication protocol, architecture, and principles.

What is Controller Area Network?

The Controller Area Network (CAN) is a data transmission protocol used in the automotive field, allowing multiple devices within a network to communicate with each other, providing real-time reliable data transmission. CAN was introduced by Bosch in 1983 and was standardized by the International Organization for Standardization (ISO) in 1993.

The current versions of CAN are:

  1. CAN 2.0 (1991), also known as Classical-CAN, is the original version with a maximum data rate of 1 Mbps and a maximum payload size of 8 bytes.
  2. CAN FD (2012), provides a higher transmission rate, with FD standing for Flexible Data Rate. It has a maximum data rate of 8 Mbps and a maximum payload size of 64 bytes.
  3. CAN XL (2022), offers even higher data rates and larger payload capacities than CAN FD, along with enhanced transmission security. XL stands for Extra Large. It has a maximum data rate of 10 Mbps and a maximum payload size of 2048 bytes.

CAN significantly simplifies communication between electronic control units (ECUs) or different devices, which traditionally required point-to-point communication using UART. By using CAN, the complexity of wiring is greatly reduced, enabling multiple devices to communicate efficiently on a single network, thereby simplifying wiring and enhancing system reliability and efficiency.

Using CAN significantly simplifies wiring and enhances reliability.

Using CAN significantly simplifies wiring and enhances reliability.

Nowadays, CAN communication is widely used in the automotive industry due to its characteristics:

  1. Low Cost and Lightweight Network: The communication uses a linear bus architecture, reducing implementation costs while keeping the network lightweight.
  2. Direct Communication Among Multiple Devices: Allows multiple devices on the network to communicate directly without requiring a central host controller, enhancing system flexibility.
  3. Reliable Real-time Performance: Provides real-time data transmission, making it particularly suitable for vehicle control systems.
  4. Interference Resistance: Utilizes differential signaling (CAN-High / CAN-Low) to improve resistance to electromagnetic interference, ensuring stable communication in noisy environments.
  5. Low Power Consumption and Network Wakeup Support: Features low power consumption and supports network wakeup functionality.
  6. Simple Architecture: Compared to Ethernet, CAN’s architecture is simpler, making system design and maintenance easier.

However, CAN has limitations in terms of transmission speed and the number of nodes, making it unsuitable for transmitting large amounts of data such as images and videos. Additionally, the CAN protocol does not implement encryption, so security measures must be implemented separately when needed.

The main types of data transmitted via CAN include:

  • Control commands
  • Sensor data (e.g., vehicle speed, steering angle, temperature, gear position)
  • Diagnostic messages
  • Firmware updates
  • Real-time events

Key Points of CAN

  1. Communication is achieved using CAN_H(igh) and CAN_L(ow). When the distance is short enough, grounding (GND) is generally not required.

    However, in long-distance transmissions, ground offset can occur, which increases the $V_{cm}$ at certain nodes. If this exceeds the $V_{cm}$ tolerance of the CAN IC, decoding will fail.

    To ensure reliable connections, it is recommended to use a common grounding point to avoid decoding failures.

  2. $CAN_H$ and $CAN_L$ are differential signals.

  3. CAN uses differential signals for communication. During this process, noise, known as common-mode signal, can be encountered.

    The voltage can be represented as $V_d$ for differential signals and $V_{cm}$ for common-mode signals.

    $V_{cm}$ is present simultaneously in both $CAN_H$ and $CAN_L$. The differential amplification (subtraction) within the CAN IC can eliminate common-mode noise.

    $V_{cm} = \frac{V_{CANH} + V_{CANL}}{2}$

    $V_{d} = (V_{CANH} + V_{cm}) - (V_{CANL} + V_{cm}) = V_{CANH} - V_{CANL}$

  4. According to the datasheet, for a 5 V CAN system, the default output level is 0.5 $V_{cc}$ = 2.5 V (relative to ground for both $CAN_H$ and $CAN_L$).

    • Recessive represents a bit value of 1: $V_{CANH}$ = $V_{CANL}$ = 2.5 V, and $V_{d}$ is 0 V.
    • Dominant represents a bit value of 0: $V_{CANH}$ = 3.5 V, $V_{CANL}$ = 1.5 V, and $V_{d}$ is 2 V.
    • For more detailed voltage information, refer to the datasheet.
  5. CAN transmission uses an arbitration mechanism where dominant signals have higher priority over recessive signals. Therefore, the smaller the CAN ID, the higher its priority. However, if the system is improperly designed, low-priority CAN IDs may face difficulties in transmission.

    Dominant signals have higher priority because the CAN transceiver’s circuitry is implemented using wired-AND logic. For more details on the architecture, refer to the datasheet of the CAN transceiver IC.

  6. When node A sends a dominant signal (0) and node B sends a recessive signal (1), node B will detect a collision and stop transmitting, switching to receiving mode. The Carrier Sense Multiple Access with Collision Avoidance (CSMA/CA) mechanism will automatically retransmit when the network is idle, avoiding collisions.

  7. If you do not know which line is $CAN_H$ or $CAN_L$, you can use a multimeter to measure the average voltage or an oscilloscope for evaluation. The average voltage of $CAN_H$ will be higher than 2.5 V, while $CAN_L$ will be lower than 2.5 V ($V_{cc}$ = 5 V).

  8. Each CAN transmission is called a frame, and a frame mainly includes the target ID, length, and data content. For more details, refer to the Frame Format.

  9. The CAN network consists of:

    • Microprocessor (MCU): Responsible for data processing and application layer logic. It includes an integrated CAN controller, allowing the MCU to directly handle CAN communication. When necessary, the MCU relies on functions provided by the CAN controller to implement higher-level protocols.
    • CAN Controller: Handles the formatting of data packets, arbitration, error detection, and other tasks related to the CAN protocol.
    • CAN Transceiver: An independent IC responsible for converting the TTL voltage levels of the MCU into differential signals on the CAN network, and vice versa for the MCU to receive. It converts the MCU’s TX and RX to the $CAN_H$ and $CAN_L$ differential signals.
    • CAN Network: Composed of two differential signal lines, $CAN_H$ and $CAN_L$, used for data transmission.
  10. The CAN network endpoints have termination resistors (120 Ohms) to reduce reflection waves on the transmission line. Refer to: Design and Considerations of Termination Resistors.

    • Using a multimeter to measure $CAN_H$ and $CAN_L$ in the CAN network, the equivalent network resistance should be around 60 Ohms (approximately 55 Ohms to 65 Ohms).
    • If it measures 0 Ohms to 5 Ohms, $CAN_H$ and $CAN_L$ may be short-circuited.
    • If it measures 30 Ohms to 50 Ohms, there may be extra termination resistors or incorrect resistor values in the network.
    • If it measures 110 Ohms to 140 Ohms, one termination resistor may be missing from the network (normally two termination resistors in parallel equal 60 Ohms).
    • If it measures 1 kOhms to 10 kOhms, two termination resistors may be missing from the network.
    • If it measures more than 10 MOhms, the CAN physical line is disconnected.
  11. There is a probability of packet loss in CAN communication, and it is recommended that the overall load does not exceed 60-70% (rule of thumb).

  12. The maximum data rate for CAN 2.0 is 1 Mbps, while CAN FD can achieve data transfer rates up to 8 Mbps.

  13. Transmission rates are categorized into two types: nominal bit rate (NBR) and data bit rate (DBR).

    In CAN 2.0, the arbitration phase and data phase share the same rate, so there is no distinction between the rates. Commonly mentioned speeds like 500 kbps or 1 Mbps refer to the overall CAN communication speed.

    In CAN FD, both NBR and DBR are defined. The arbitration phase can use 500 kbps or 1 Mbps NBR to maintain compatibility with traditional CAN. In the data phase, DBR can reach up to 5 Mbps for data transmission.

  14. The CAN FD controller is backward compatible with CAN 2.0 packets.

    However, the CAN 2.0 controller cannot process CAN FD packets. The reason lies in the differences in the headers of the two types of packets. When a CAN 2.0 controller receives a CAN FD packet, it will respond with an error frame because certain bit configurations in the CAN FD packet do not conform to the CAN 2.0 standard.

    Even if the arbitration bit rate (nominal bit rate, NBR) and the data bit rate (data bit rate, DBR) of CAN FD are both set to 500 kbps, the CAN 2.0 receiver still cannot decode CAN FD packets.

Glossary of CAN Terms

TermDescription
Standard CANCAN 2.0 standard format, also known as CAN 2.0A, uses 11 bits to represent the ID.
Extended CANCAN 2.0 extended format, also known as CAN 2.0B, uses 29 bits to represent the ID.
CAN FDFlexible Data-Rate CAN, can use 11 or 29 bits for the ID and supports up to 64 bytes of data length. It features higher data transfer rates, reducing CAN load by transmitting more data in a single frame.
CAN XLThird-generation CAN protocol, with a longer data length (2048 bytes) than CAN FD.
FlexCANAn IP module by NXP, implementing both CAN FD and CAN 2.0B protocols, compliant with ISO 11898-1 standard.
MCANAn IP module by TI, implementing CAN FD and compliant with ISO 11898-1 standard.
MCMCANA module by Infineon, replacing their MultiCAN. Supports both traditional CAN and CAN FD.
VectorA German company providing solutions for automotive and embedded systems.
CANoeA tool by Vector for CAN software development and testing. It can generate signals and simulate communication behavior. The simplified version is CANalyzer.
CANapeA tool by Vector used for measuring, calibration, and diagnostics of electronic control units (ECUs) and advanced driver-assistance systems (ADAS).
Peak-System (PCAN)A German company providing solutions for automotive and embedded systems.
XCPUniversal measurement and calibration protocol, allowing external devices (like calibration tools or measurement instruments) to communicate with embedded systems for parameter adjustment, performance evaluation, and fault diagnosis.
UDSUnified Diagnostic Services, a communication protocol used in vehicle diagnostic systems for communication and information exchange. It defines standard services and diagnostic protocols to ensure effective communication between diagnostic tools and vehicle control units (ECUs).
OBD-IIA standard protocol allowing external electronic devices to access the vehicle’s internal computer systems for diagnostics and emissions testing. Typically seen as a 16-pin (2x8) SAE J1962 female connector in vehicles.
.dbcCANdb database file, developed by Vector, an industry standard widely used in CAN-related software. Describes details such as IDs, names, and lengths on the CAN network.
CiACAN in Automation (CiA) is an international users’ and manufacturers’ organization that develops and supports higher-layer protocols based on CAN and their international standardization, addressing areas not covered by the CAN protocol itself.
CANopenA high-level communication protocol based on CAN, suitable for embedded applications. It extends CAN’s capabilities, supports larger data packets, and provides rich communication features for complex machine automation applications. Developed and maintained by the CiA.
AUTOSARAUTomotive Open System ARchitecture (AUTOSAR) is a global open standard aimed at developing software architecture for automotive electronic systems. It is created by automotive manufacturers, suppliers, and software companies to provide a scalable and reusable software platform to address the increasing complexity of automotive electronic systems.
DeviceNetA high-level communication protocol based on CAN, primarily used in factory automation for communication between controllers (PLCs) and industrial I/O devices (like limit switches, sensors, drives, displays, and operator interfaces). Maintained by the Open DeviceNet Vendor Association (ODVA).
SAE J1939A high-level communication protocol based on CAN, primarily for vehicle applications. It allows extensive data exchange within vehicle systems, supports messages of unlimited length, and supports master/slave architecture, suitable for complex vehicle communication needs. A standard set by the Society of Automotive Engineers (SAE).
CanKingdomA high-level communication protocol based on CAN, specialized for distributed control systems in industrial and embedded applications. Designed to provide a flexible and efficient communication architecture for higher-level collaboration and management in systems using the CAN protocol.
recessive bitThe logical bit 1 in CAN signaling.
dominant bitThe logical bit 0 in CAN signaling.

Data Frame Format

A complete CAN frame

  • Start of Frame (SOF): This flag indicates the beginning of a data frame. Before a CAN node starts, it checks for 11 consecutive bits of ‘1’ to ensure the entire network is idle.

  • Arbitration Field (12 or 32 bits)

    • Base ID: 11 bits
    • Remote Transmission Request (RTR): Rarely used in practical applications.
    • Extended CAN: Adds the Substitute Remote Request (SRR), IDE flag, and Extended ID (18 bits).
  • Control Field (6 bits)

    • Identifier Extension (IDE) Flag: ‘0’ for CAN 2.0A.
    • Reserved Bit (r0): Default to ‘0’.
    • Data Length Code (DLC): Uses 4 bits to indicate the length of the subsequent data.
  • Data Field: Uses 1 to 8 bytes to convey data.

  • CRC Field (16 bits): Includes a 15-bit CRC sequence and CRC delimiter.

  • Acknowledgement Field (2 bits): Contains ACK slot and ACK delimiter. If the CRC matches, the ACK slot is set to ‘0’. The ACK delimiter is always ‘1’.

  • End of Frame (EOF, 7 bits): Marks the end of the frame with 7 bits of ‘1’.

  • Interframe Space (IFS): Fixed at 3 bits of ‘1’ to ensure enough time between adjacent frames for error handling and synchronization.

  1. Each message frame ends with 11 bits of ‘1’, including ACK delimiter, EOF, and IFS. Nodes check for these 11 bits at the new SOF to determine if the network is idle. The SOF flag helps synchronize nodes.
  2. From SOF to CRC, only up to 5 consecutive identical bits are allowed. If there are 5 consecutive bits of ‘0’ or ‘1’, a stuff bit of the opposite value is inserted for signal synchronization and reliability.

Features and Differences of CAN FD

CAN FD is an improvement over CAN 2.0, focusing on:

  1. Transmitting more data per frame to reduce CAN bus load.
  2. Higher data rates.
  3. The CAN FD controller is backward compatible with the CAN 2.0 standard. However, the CAN 2.0 controller cannot process CAN FD packets.
  4. Support for 11 and 29-bit IDs.
  5. Removal of the remote frame, replacing RTR with Remote Request Substitution bit (RRS), always set to ‘0’.
  6. Renaming the r0 bit to FD frame (FDF), fixed at ‘1’.
  7. Using the Bit Rate Switch (BRS) flag to determine whether data is transmitted at a higher data rate (DBR). If BRS is ‘0’, the bit rate (NBR) is the same as CAN 2.0.
  8. Error Status Indicator (ESI), ‘0’ for normal operation, ‘1’ for error passive mode.
  9. Stuff bit count (SBC) uses three Gray codes and one parity bit for enhanced communication reliability.

Differences between CAN 2.0 and CAN FD

The image above shows that with the same data, if BRS is off, the bit rate follows NBR as in CAN 2.0. With BRS on, data can be transmitted at up to 8 Mbps. The DBR used in the example is 4 and 10 times the NBR.

Bit Timing

Bit timing ensures correct synchronization and communication on the CAN network. It involves configuring time parameters to ensure all nodes can transmit and receive data correctly.

Bit timing related formulas

Bit Structure

Structure of a bit

For a configured CAN rate, such as 500 kbps NBR, it means transmitting 500,000 bits per second. The reciprocal of the transmission rate gives the bit time, referred to as Tb or Tnbt.

A bit time is divided into four segments:

  1. Synchronization Segment (SYNC_SEG)
  2. Propagation Time Segment (PROP_SEG)
  3. Phase Buffer Segment 1 (PHASE_SEG1)
  4. Phase Buffer Segment 2 (PHASE_SEG2)

At a transmission rate of 500 kbps (NBR), Tb equals 2 microseconds (Formula 1). The sum of these four segments equals one Tb (Formula 2).

The propagation time segment must consider Node A’s processing time, transmission time, and Node B’s processing time.

Therefore, the propagation time segment must be at least: twice the physical transmission delay plus Node A’s processing time plus Node B’s processing time.

When Node A transmits SOF, it ensures that the CAN arbitration priority mechanism is satisfied.

Time Quantum (Tq)

Tq is the smallest time unit used in CAN bit timing and can be used to evaluate the basic unit of CAN bit timing. It is typically measured in nanoseconds.

Bit time is divided into four segments, with each segment’s length represented using the smallest time unit (Time Quantum, Tq).

For a device with an 80 MHz clock, Tq = 1 / 80 MHz = 12.5 ns.

If the CAN FD data bit rate (DBR) needs to be set to 5000 kbps:

Configure Tsync_seg = 1 (fixed), Tseg1 = 13, and Tseg2 = 2. The total Tq is 16 units.

12.5 ns × 16 = 0.2 µs, which means one bit is 0.2 µs. The reciprocal of this value gives a data rate of 5000 kbps.

Baud Rate Prescaler (BRP)

Devices have different internal clocks, and the BRP within the device can be used to divide the clock frequency to adjust Tq.

For example, if the device clock is 80 MHz, then Tq is 12.5 ns.

If BRP is set to 2, the clock frequency is divided to 40 MHz, making Tq 25 ns.

Sample Point

The sample point within a bit time determines whether the state on the CAN network is ‘0’ or ‘1’.

According to industry standards such as CANopen and DeviceNet, it is recommended to use an 87.5% sample point for CAN. This recommendation is because an 87.5% sample point provides a good balance between network length and oscillator tolerance.

Synchronization Jump Width (SJW)

SJW is used to compensate for oscillator tolerance. It works in conjunction with Phase Buffer Segments (Phase_Seg1 and Phase_Seg2) to ensure synchronization on the CAN bus.

In a CAN system, the frequency of the oscillator may vary due to temperature changes, voltage fluctuations, or component aging.

To ensure stable communication between different nodes, the phase buffer segments and SJW are used to compensate for phase shifts caused by oscillator tolerance.

This value is independent of NBR and DBR and primarily provides tolerance for clock drift, typically set to 1 to 2 Tq.

Calculating Segment Time

Considerations include:

  • MCU IC Clock
  • Bit Rate (NBR / DBR)
  • Transmission Line Delay
  • CAN IC Delay
  • Temperature (uncontrollable)

Known values:

  • Bit Rate (NBR / DBR)
  • System Clock (MCU may be 8 MHz / 20 MHz / 40 MHz / 80 MHz)

A preliminary assessment can be done using a calculator. Based on the selected sampling rate (commonly 75% ~ 90%, 87.5% is recommended for evaluation),

you can determine the required prescaler, TSEG1, and TSEG2.

Design and Considerations of Termination Resistors

Standard Termination

As mentioned earlier, both ends of the CAN network will have 120 Ohms termination resistors, which are specified according to ISO 11898-2.

Since each end has a resistor, the input impedance at any given endpoint, after parallel combination, is approximately 60 Ohms. This can be measured using a multimeter between $CAN_H$ and $CAN_L$, where the impedance should be around 45 to 65 Ohms.

Under the ISO 11898 definition, the maximum speed is 1 Mbps, with a length not exceeding 40 meters, stub length of 0.3 meters, and a maximum of 30 nodes.

Network design can reduce signal reflection, allowing for a longer network, longer stubs, and more devices.

For example, consider a network with 10 nodes (2 terminations + 8 devices), with each termination having a 120 Ohms resistor.

If the stub of the CAN network is very long, a 2.6 KOhms resistor can be added to reduce reflection.

Considering 8 nodes with 2.6 KOhms termination, the final impedance would be:

1
(2600 / 8) // 120 // 120 ≈ 50.65 Ohms

Even with just one endpoint, a 2.6 KOhms resistor in parallel with two termination resistors yields an impedance of 58.6 Ohms, which matches the overall line impedance. However, the actual transmission performance needs to be evaluated during communication testing.

The calculation for stub resistance is:

1
330 Ohms × number of stubs = stub termination resistance value

According to ISO standards, the default CAN network terminations must have two 120 Ohms resistors.

In the lab:

  • A network with only one termination resistor might still function correctly, but it is recommended to habitually add another termination resistor.
  • The stub resistances, due to short testing distances, often have little perceptible effect on signal quality. The final signal evaluation is performed after installation in the full vehicle network.

Split Termination

Using an RC filter composed of split resistors can filter out high-frequency noise:

This consists of two equal resistors (60 Ohms) in series to ground, with a 4.7 nF capacitor in parallel to ground at the midpoint, effectively acting as a low-pass filter. This improves noise immunity and reduces electromagnetic radiation.

The cutoff frequency, fc = 1 / (2πRC), calculates to approximately 1.12 MHz (Rt = 30 Ohms), meaning signals above this frequency will be filtered out.

Difference Between Split Resistor and Standard Termination (Image)

PCAN-View Send and Receive Test

This section explains the basic setup of PCAN and clarifies the parameters and their corresponding interfaces described in the previous chapters.

Open PCAN-View. The upper section is the receiver, and the lower section is the transmitter.

Initial Page

After inserting the hardware, click the connection icon at the top left to access the device settings.

Here, we use CAN FD, with NBR and DBR set to 1000 kbps and 5000 kbps, respectively. The sampling point is set to 87.5%.

Configure Device Information

After configuring the device, the MCU is currently set to send data every 500 ms. You can see the ID 0xC0 appearing in the Receive section.

Receive MCU Signal

To send data to the MCU, right-click on the blank area in the Transmit section and select “New message…”.

Add Transmit Message

Set the data type to CAN FD and enable BRS to speed up data transmission. The data length is set to 64 bytes.

Configure Message

After adding, select the message under the Transmit section and press the space bar to send the message. The MCU will return 0x777 upon receiving the data.

Test Send Message

References

  1. History of CAN technology
  2. FlexCAN控制器
  3. Getting Started with the MCAN (CAN FD) Module
  4. Introduction to the Controller Area Network (CAN)
  5. Basics of debugging the controller area network (CAN) physical layer
  6. TJA1040 high speed CAN transceiver
  7. Practical tips: CAN-Bus
  8. SN65HVD23x 3.3-V CAN Bus Transceivers
  9. ISO 11898-1:2015 - Road vehicles
  10. ISO 11898-2:2016 - Road vehicles
  11. XCP (protocol)
  12. Unified Diagnostic Services
  13. CAN bus
  14. Learning Module CAN
  15. CAN FD Explained
  16. Calculator for CAN Bit Timing Parameters
  17. The Configuration of the CAN Bit Timing
  18. CAN Bit Timing Requirements
  19. Top Design Questions About Isolated CAN Bus Design
  20. How To Properly Wire A CAN Bus
  21. A CAN Physical Layer Discussion
  22. CAN BUS Troubleshooting Guide
Theme Stack designed by Jimmy