CAN
1. Overview
This demo simulates typical CAN deployments with multiple roles: sender, receiver, monitor, and interferer.
Sender transmits frames, receives all traffic but only processes receiver responses.
Receiver accepts sender frames and forwards them.
Monitor observes all traffic to ensure the bus remains healthy.
Interferer transmits random frames and ignores all traffic—useful for filter and arbitration testing.
Before running the demo you can adjust the baud rate for all nodes. Configure acceptance filters so each device only accepts specific IDs.
2. Code Path
middleware/driver/can_demo.c
3. CLI Reference
Command |
Param |
Description |
|---|---|---|
|
|
Configure acceptance filter |
|
|
Adjust CAN FD arbitration/data rate |
|
|
CAN FD role-based demo |
|
Same parameters as above |
CAN 2.0 role-based demo |
Supported baud rates:
CAN_BR_250K (81%)
CAN_BR_500K (81%)
CAN_BR_800K (80%)
CAN_BR_1M (81%)
CAN_BR_2M (81%)
CAN_BR_4M (81%)
CAN_BR_5M (77%)
4. Hardware Setup
The demo uses an MCP2562FD transceiver. Pin assignment:
GPIO |
Function |
|---|---|
P44 |
CAN TX |
P45 |
CAN RX |
P46 |
CAN STBY |
See the figures for board wiring and the 120 Ω termination (60 Ω effective). Multi-board setups illustrate loopback tests, 2-board exchanges, and 4-board arbitration scenarios.
5. Demo Scenarios
Filters – Accept only designated IDs:
can_filter_demo 0 0x10000008 0x1fffff08can_filter_demo 0 0x10000004 0x1fffff04Dynamic baud rate – Use
can_speed_demoto reconfigure speeds.CAN FD demo (two nodes) – Sender stores 64-bit random data, transmits, receiver echoes back, sender validates. Commands:
can_stb_demo1 0x10000004 sender start/stopcan_stb_demo1 0x10000008 receiver start/stopFailures print mismatched buffer content.
CAN FD demo (three nodes) – Add a monitor node for statistics:
can_stb_demo1 0x10000001 moniter start/stopCAN FD demo (four nodes) – Add an interferer to inject traffic:
can_stb_demo1 0x10000002 interfere start/stopTo run the same scenarios under CAN 2.0, use
can_20_demo2instead ofcan_stb_demo1.