CAN

Pigeon RB700 has one CAN port. The CAN controller supports both CAN frames formats as specified in ISO 11898-1:2015, these are the Classical format (CAN2.0B) and 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 CAN interface is configured after boot. Below command set the bitrate of the can0 interface to 500 Kbps:

/sbin/ip link set can0 up type can bitrate 500000

you can edit this command in /etc/network/interfaces.d/can0 file.

Useful commands

  • Check state of 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
  • Example configuring 500 kbit/s arbitration bitrate and 4 Mbit/s data bitrate, enable the 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
  • Statistics
    cat /proc/net/can/stats

can-utils

Can-utils is installed by default.

  • Transmit 8 bytes, id number is 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) use:

    cansend can0 100##131.32.33.34.35.36.37.38
  • Transmit a CAN FD message with no BRS use:

    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'
  • Candump also has the ability to dump data with a specific ID, here is an example for 0x100:

    candump -cae can0,100:7ff
  • Save all the received packets into a logged file:

    candump -l can0,0:0,#FFFFFFFF
  • Cansniffer group the messages by ID's (identifiers):
    cansniffer can0

Links