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

CAN CLI commands

Command

Param

Description

can_filter_demo [aid] [acode] [amask]

aid: standard/extended ID; acode: ≤29 bits; amask: 1=disable, 0=enable

Configure acceptance filter

can_speed_demo [s_speed] [f_speed]

s_speed: slow speed; f_speed: fast speed

Adjust CAN FD arbitration/data rate

can_stb_demo1 [can_id] [role] [ctrl]

can_id: device ID; role: sender/receiver/monitor/interfere; ctrl: start/stop

CAN FD role-based demo

can_stb_demo2 [can_id] [role] [ctrl]

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

  1. Filters – Accept only designated IDs:

    can_filter_demo 0 0x10000008 0x1fffff08

    can_filter_demo 0 0x10000004 0x1fffff04

  2. Dynamic baud rate – Use can_speed_demo to reconfigure speeds.

  3. CAN FD demo (two nodes) – Sender stores 64-bit random data, transmits, receiver echoes back, sender validates. Commands:

    can_stb_demo1 0x10000004 sender start / stop

    can_stb_demo1 0x10000008 receiver start / stop

    Failures print mismatched buffer content.

  4. CAN FD demo (three nodes) – Add a monitor node for statistics:

    can_stb_demo1 0x10000001 moniter start / stop

  5. CAN FD demo (four nodes) – Add an interferer to inject traffic:

    can_stb_demo1 0x10000002 interfere start / stop

  6. To run the same scenarios under CAN 2.0, use can_20_demo2 instead of can_stb_demo1.