CAN
The Pigeon RB700 has one CAN port. The CAN controller supports both CAN frame formats as specified in ISO 11898-1:2015: the Classical format (CAN 2.0B) and the CAN Flexible Data Rate (CAN FD) format.
Features:
- Supports both CAN 2.0B and CAN FD,
- Arbitration Bit Rate up to 1Mbps,
- Data Bit Rate up to 8Mbps,
- Bus pins protected against transients,
- Connection via screw terminal.
By default, the CAN interface is automatically configured at startup using the settings in the /etc/network/interfaces.d/can0
file. The following command sets the bitrate of the can0 interface to 500 Kbps:
$ /sbin/ip link set can0 up type can bitrate 500000
Useful commands
- Check state of the CAN interface:
$ ifconfig can0 can0
Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP RUNNING NOARP MTU:16 Metric:1
RX packets:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:160 (160.0 B) TX bytes:160 (160.0 B)
- Display CAN device details:
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 minmtu 0 maxmtu 0
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 1000000 sample-point 0.750
tq 25 prop-seg 14 phase-seg1 15 phase-seg2 10 sjw 1
mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp-inc 1
dbitrate 8000000 dsample-point 0.800
dtq 25 dprop-seg 1 dphase-seg1 2 dphase-seg2 1 dsjw 1
mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp-inc 1
clock 40000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
- Configure a 500 kbit/s arbitration bitrate and a 4 Mbit/s data bitrate, and enable CAN FD mode:
$ ip link set can0 up type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
- Bring down the device:
$ ip link set can0 down
- Bring up the device:
$ ip link set can0 up
- Display CAN statistics:
$ cat /proc/net/can/stats
can-utils
The can-utils package is installed by default.
- Transmit 8 bytes with ID 0x100 (dots are optional):
$ cansend can0 100#31.32.33.34.35.36.37.38
- Transmit a CAN FD message with BRS (Bit Rate Switch):
$ cansend can0 100##131.32.33.34.35.36.37.38
- Transmit a CAN FD message without BRS:
$ cansend can0 100##031.32.33.34.35.36.37.38
- Cansend usage:
$ cansend
:
#{data} for Classical CAN 2.0 data frames
#R{len} for Classical CAN 2.0 data frames
#{data}_{dlc} for Classical CAN 2.0 data frames
#R{len}_{dlc} for Classical CAN 2.0 data frames
##{data} for CAN FD frames
: 3 (SFF) or 8 (EFF) hex chars
{data}: 0..8 (0..64 CAN FD) ASCII hex-values (optionally separated by '.')
{len}: an optional 0..8 value as RTR frames can contain a valid dlc field
{dlc}: an optional 9..F data length code value when payload length is 8
: a single ASCII Hex value (0 .. F)
CANFD_BRS 0x01 - bit rate switch (second bitrate for payload data)
CANFD_ESI 0x02 - bit error state indicator of the transmitting node
CANFD_FDF 0x04 - bit mark CAN FD for dual use of struct canfd_frame
- Receive packets:
$ candump -cae can0,0:0,#FFFFFFFF can0 100 [8] 31 32 33 34 35 36 37 38 '12345678'
- Dump data with a specific ID (e.g., 0x100):
$ candump -cae can0,100:7ff
- Save all received packets to a log file:
$ candump -l can0,0:0,#FFFFFFFF
- Use cansniffer to group messages by ID:
$ cansniffer can0