Introduction to CAN Bus Technology
What is CAN Bus?
Controller Area Network (CAN or CAN Bus) is a high-speed, serial networking technology that operates in half-duplex using two wires. Originally designed for the automotive industry, it has become a standard in industrial automation and various other sectors.
Advantages of CAN
- Simple and Low Cost: The CAN bus uses only 2 wires, making it easier to connect control modules compared to traditional methods. This provides benefits in installation, repair, and maintenance during failures.
- Common Protocol: It creates a universal protocol allowing different suppliers to develop compatible control modules.
- Message Prioritization: Every message transmitted from a node or station on the CAN bus has a priority level. When multiple messages are sent simultaneously, the one with the highest priority is transmitted first. Lower-priority messages pause and retransmit when the bus is idle.
- Flexible Configuration: Allows for setting bit timing, synchronization time, and the length of transmitted and received data.
- Multicast Reception with Time Synchronization: A single message can be received by multiple nodes simultaneously. Every node sees the message on the bus and decides whether to accept it based on its own configuration.
- Multi-master Capability: Supports multiple masters on the bus.
- Error Detection and Signaling: Each message includes a CRC (Cyclic Redundancy Code) for error checking. If an error is detected, the receiving node ignores the message and transmits an error frame onto the bus. Nodes maintain their own error counters; if errors occur too frequently, a node can automatically disconnect from the bus.
- Automatic Retransmission: If a message fails due to an error, the transmitting node retains it and automatically retransmits when the bus is free, ensuring data integrity.
How Does CAN Work?
CAN uses CSMA/CD + AMP (Carrier Sense Multiple Access / Collision Detection with Arbitration on Message Priority).
Before sending, a node checks if the bus is busy. Unlike Ethernet, which stops all transmissions upon detecting a collision and waits for a random delay, CAN uses an intelligent priority arbitration principle to resolve conflicts.
Operating Principle
- Data messages do not contain the addresses of the sender or the intended receiver.
- Instead, content is labeled with a unique Identifier (ID).
- All nodes receive the message and perform an “acceptance check” on the ID to determine if the message is relevant to them.
- If relevant, it is processed; otherwise, it is ignored.
CAN Frame Types
CAN data is transmitted in Frames. There are four distinct types:
- Data Frame: Carries data from a transmitter to receivers and contains a data field.
- Remote Frame: Transmitted by a node to request data from another node. The requested node responds with data matching the requested ID.
- Error Frame: Transmitted by any node that detects a bus error.
- Overflow Frame: Sent by a node that is receiving data too quickly to process, signaling other nodes to stop sending.
Data and Remote Frames use an Arbitration Field containing the ID to determine priority. They come in two formats:
- Standard Format: Uses an 11-bit ID.
- Extended Format: Uses a 29-bit ID.
Structure of a Standard Data Frame (CAN 2.0A)
A standard Data Frame consists of seven bit fields:
1. Start Of Frame (SOF)
Occupies 1 bit (a Dominant bit/logic 0) to mark the beginning of the frame.
2. Arbitration Field
- Standard Format: 12 bits (11-bit ID + 1-bit RTR).
- Extended Format: 32 bits (29-bit ID + SRR, IDE, and RTR bits).
- RTR (Remote Transmission Request) Bit: Distinguishes between a Data Frame (0/Dominant) and a Remote Frame (1/Recessive). Data frames have higher priority than Remote frames if they share the same ID.
- SRR (Substitute Remote Request) Bit: Only in extended frames; it is a Recessive bit (1) that acts as a placeholder for the RTR position found in standard frames.
- IDE (Identifier Extension) Bit: Distinguishes between standard (IDE=0) and extended (IDE=1) frames.
3. Control Field
Contains bits like r0, r1 (reserved bits, usually ignored by receivers) and the DLC (Data Length Code). The DLC (4 bits) specifies the number of data bytes (0 to 8).
4. Data Field
Contains 0 to 8 bytes of data as specified by the DLC.
5. Cyclic Redundancy Check (CRC) Field
Includes a 15-bit CRC Sequence and a 1-bit CRC Delimiter (Recessive). This field is used to detect transmission errors by comparing the calculated CRC at the receiver with the sequence sent by the transmitter.
6. Acknowledge (ACK) Field
Consists of 2 bits:
- ACK Slot: The transmitter sets this as Recessive. Receivers that get a valid message override it with a Dominant bit.
- ACK Delimiter: A 1-bit Recessive bit.
7. End Of Frame (EOF)
A sequence of 7 Recessive bits signaling the end of the frame.