|
| 1 | +--- |
| 2 | +date: 2026-04-30 |
| 3 | +title: Controller Area Network (CAN) |
| 4 | +--- |
| 5 | + |
| 6 | +Controller Area Network (CAN) is a communication protocol used for reliable, real-time data exchange between multiple devices in embedded and robotic systems. It enables microcontrollers, sensors, and actuators to communicate over a shared bus without requiring a central controller. CAN is widely used in robotics for motor control, sensor integration, and distributed system architectures due to its robustness, fault tolerance, and resistance to electrical noise. This article provides an overview of CAN, along with practical setup, usage, and debugging considerations in robotic systems. |
| 7 | + |
| 8 | +## Overview and Key Concepts |
| 9 | + |
| 10 | +CAN is a multi-master, message-based communication protocol where all nodes share a common communication bus. Each node can transmit and receive messages, and communication is prioritized using message identifiers. |
| 11 | + |
| 12 | +Key characteristics: |
| 13 | +- Message-based communication (no device addressing) |
| 14 | +- Arbitration-based priority system (lower ID = higher priority) |
| 15 | +- Built-in error detection and retransmission |
| 16 | +- Differential signaling using CAN_H and CAN_L |
| 17 | + |
| 18 | +Each CAN message typically contains: |
| 19 | +- Identifier (used for priority and filtering) |
| 20 | +- Data payload (up to 8 bytes in classic CAN) |
| 21 | +- Error checking fields |
| 22 | + |
| 23 | +When multiple nodes transmit simultaneously, arbitration ensures that the highest priority message is sent without data corruption. |
| 24 | + |
| 25 | +## Hardware and Software Setup |
| 26 | + |
| 27 | +### Hardware Requirements |
| 28 | +- CAN controller (often integrated in microcontrollers) |
| 29 | +- CAN transceiver (e.g., MCP2551, SN65HVD230) |
| 30 | +- Twisted pair wiring (CAN_H and CAN_L) |
| 31 | +- Two 120Ω termination resistors at both ends of the bus |
| 32 | + |
| 33 | +Topology guidelines: |
| 34 | +- Use a linear bus configuration |
| 35 | +- Avoid star topology |
| 36 | +- Keep cable lengths appropriate for bitrate |
| 37 | + |
| 38 | +### Software Setup (Linux / SocketCAN) |
| 39 | + |
| 40 | +Bring up CAN interface: |
| 41 | +sudo ip link set can0 up type can bitrate 500000 |
| 42 | + |
| 43 | +Send a CAN message: |
| 44 | +cansend can0 123#DEADBEEF |
| 45 | + |
| 46 | +Receive CAN messages: |
| 47 | +candump can0 |
| 48 | + |
| 49 | +Useful tools: |
| 50 | +- candump for monitoring traffic |
| 51 | +- cansniffer for identifying changing signals |
| 52 | + |
| 53 | +## Usage in Robotics Systems |
| 54 | + |
| 55 | +CAN is widely used in robotics systems that require reliable communication between distributed components. |
| 56 | + |
| 57 | +Common applications: |
| 58 | +- Motor controllers (e.g., ODrive, Roboteq) |
| 59 | +- Sensors such as IMUs and encoders |
| 60 | +- Battery management systems |
| 61 | +- Mobile robot subsystems |
| 62 | + |
| 63 | +CAN allows multiple devices to communicate over a single bus, reducing wiring complexity and improving system robustness. |
| 64 | + |
| 65 | +## Common Issues and Debugging |
| 66 | + |
| 67 | +> Missing termination resistors or incorrect bitrate settings are common causes of CAN communication failure. |
| 68 | + |
| 69 | +Common issues: |
| 70 | +- Missing or incorrect termination resistors |
| 71 | +- Bitrate mismatch between nodes |
| 72 | +- Wiring errors (CAN_H / CAN_L swapped) |
| 73 | +- Electrical noise or poor grounding |
| 74 | + |
| 75 | +Debugging steps: |
| 76 | +- Verify termination at both ends of the bus |
| 77 | +- Ensure all nodes use the same bitrate |
| 78 | +- Use candump to confirm message transmission |
| 79 | +- Inspect signals using an oscilloscope if needed |
| 80 | + |
| 81 | +## Summary |
| 82 | + |
| 83 | +CAN is a reliable and widely used communication protocol for robotics systems that require real-time, fault-tolerant communication between distributed components. Its message-based design, robustness to noise, and deterministic arbitration make it suitable for motor control and sensor integration. Proper hardware setup, consistent configuration, and effective debugging practices are essential for successful deployment in robotic systems. |
| 84 | + |
| 85 | +## See Also: |
| 86 | +- [ROS2 QoS](/wiki/networking/ros2-qos/) |
| 87 | +- [Actuation](/wiki/actuation/) |
| 88 | +- [Embedded Systems](/wiki/computing/) |
| 89 | + |
| 90 | +## Further Reading |
| 91 | +- SocketCAN documentation – useful for understanding Linux-based CAN interfaces |
| 92 | +- CANopen overview – higher-level protocol built on CAN |
| 93 | +- ISO 11898 – CAN communication standard |
| 94 | + |
| 95 | +## References |
| 96 | +- Bosch CAN Specification |
| 97 | +- ISO 11898 Standard |
0 commit comments