09 CAN
1 CAN Bus Overview
CAN bus protocol (Controller Area Network) is a serial communication protocol bus developed by German BOSCH company in 1986. GM-3568JHF development board is equipped with 2 CAN interfaces, implemented based on the integrated CAN controller of RK3568J processor, providing reliable communication solutions for industrial control, automotive electronics, and device interconnection.
1.1 CAN Bus Technical Specifications
| Parameter | Specification |
|---|---|
| Protocol Standard | ISO 11898-1 (CAN 2.0A/2.0B) |
| Interface Quantity | 2 independent CAN interfaces |
| Transmission Medium | Twisted pair |
| Network Topology | Bus type |
| Transmission Distance | Max 1000 meters (5Kbps) |
| Max Node Count | 110 nodes |
| Data Frame Length | 0-8 bytes |
| Arbitration Mechanism | Non-destructive bitwise arbitration |
1.2 CAN Protocol Features
Technical Advantages
- Multi-master Communication: Supports multiple nodes sending data simultaneously
- Non-destructive Arbitration: High priority messages are transmitted first
- Error Detection: Powerful error detection and handling mechanism
- Real-time: Deterministic message transmission delay
- High Reliability: Differential signal transmission, strong anti-interference ability
Application Fields
- Automotive Electronics: Engine management, body control, instrument system
- Industrial Automation: PLC control, sensor network, actuator control
- Medical Equipment: Medical instrument interconnection, monitoring equipment communication
- Marine System: Navigation equipment, power system control
- Building Automation: Lighting control, air conditioning system, security equipment
2 GM-3568JHF CAN Interface Configuration
According to product specifications, GM-3568JHF development board provides 2 CAN interfaces to meet various industrial application needs.
2.1 CAN Hardware Connection
CAN wiring between development board and external devices is as follows:
| Development Board | External Device |
|---|---|
| CAN_L | CAN_L |
| CAN_H | CAN_H |

2.2 CAN Communication Test
This test uses a CAN analyzer for testing. Connect the H terminal and L terminal of the two devices.

Check Interface
Check if can0 and can1 interfaces are generated on the development board
root@linaro-alip:/# ifconfig -a
can0: flags=128<NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 54
can1: flags=128<NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 55
···Parameter Setting
Set the baud rate on the development board and test (take CAN0 as a test sample this time)
# Turn off CAN0 interface
sudo ip link set can0 down
# Set bit rate to 250000
sudo ip link set can0 type can bitrate 250000
# Turn on CAN0 interface
sudo ip link set can0 up
# Send (Standard frame, data frame, ID:7ff, data:11223344556677)
cansend can0 -i 0x7ff 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
# Receive
candump can0Test Results
- Development Board Test Result:

- CAN Analyzer Test Effect:

3 CAN Network Diagnosis and Debugging
3.1 Using cansniffer for Network Analysis
# Install cansniffer
sudo apt-get install can-utils
# Start network sniffing
cansniffer can0
# Sniffing with filter
cansniffer can0 -c 0x100-0x200
# Save log
candump can0 -L > can_log.txt3.2 Network Load Test
# Generate test traffic
cangen can0 -g 10 -I 123 -L 8
# Test network bandwidth
canbusload can0@250000
# Stress test
for i in {1..1000}; do
cansend can0 123#DEADBEEF
done4 Troubleshooting
4.1 CAN Interface Cannot Start
Check Steps:
# Check kernel modules
lsmod | grep can
# Manually load CAN modules
sudo modprobe can
sudo modprobe can-raw
sudo modprobe can-dev
# Check device tree configuration
dmesg | grep can
# Check hardware connection
cat /proc/interrupts | grep can4.2 Communication Error or Packet Loss
Diagnosis Method:
# Check error statistics
ip -s link show can0
# View error details
cat /proc/net/can/stats
# Check bus status
candump can0 -e
# Adjust baud rate and timing
sudo ip link set can0 type can bitrate 125000 sample-point 0.754.3 Network Conflict and Arbitration Issues
Solution:
# Check network load
canbusload can0@250000
# Analyze message conflict
cansniffer can0 -c
# Optimize message priority
# Use lower CAN ID to get higher priority4.4 Hardware Connection Issues
Check Points:
- Terminal Resistor: Ensure there are 120Ω terminal resistors at both ends of the network
- Cable Quality: Use twisted pair to avoid long distance transmission
- Grounding: Ensure good signal ground connection
- Power Supply: Check CAN transceiver power supply
# Test loopback mode
sudo ip link set can0 type can bitrate 250000 loopback on
cansend can0 123#DEADBEEF
candump can0