Using CAN port

Configuring CAN

The following commands bring up the CAN interface:

    ip link set can0 type can bitrate <your-desired-bitrate-in-hz> triple-sampling on
    ifconfig can0 up

Add these to your init scripts to automatically bring up the CAN interface during boot.

Alternatively the canconfig utility can be used to configure the interface.

Testing CAN

The canutils package provides utilities for basic CAN functionality tests. candump will listen for incoming CAN messages and dump them to the console. cansend can0 message-byte-string will transmit a message (message-byte-string is a string of hex octets separated by spaces, eg. 0x12 0x34 0x56 0x78).

The following scripts test the can interface:
  • - Loopback test, Expects the CAN0 and CAN1 ports to be connected together.
    Test at 500Kb/s
    ./ 500000
  • - Echo test between two devkits
    Test can0 at 500Kb/s
    ./ 500000 can0


Go to top
Add picture from clipboard (Maximum size: 600 MB)