How to use CAN bus

The tutorial will guide you how to use CAN bus on NVIDIA Platform.

Supported Model:

  • ROScube-X series

  • ROScube-Pico-NX series

Hardware Pinout

  • For ROScube-X series

../../../_images/pinout-x2.png
  • For ROScube-Pico-NX series

../../../_images/pinout-pico2.png

Configuration

  1. Install necessary packages

sudo apt update
sudo apt install iproute2 can-utils
  1. Configure the bitrate for can0

sudo ip link set can0 type can bitrate 1000000

In this command, bitrate can be any valid CAN bitrate for stand CAN.

Note

125000(125 Kbps), 250000(250 Kbps), 500000(500 Kbps) and 1000000(1Mbps) are supported bitrates for Tegra MTTCAN driver.
Any other bitrate is not validated on Tegra MTTCAN driver.

If you want to show more configuration usage:

ip link set can0 type can help
  1. Turn on can0

sudo ip link set can0 up
  1. Enter ifconfig, then you should see can0

../../../_images/ifconfig2.png

Test

  1. Connect CAN_H and CAN_L to other machines.

  2. To receive CAN bus data from can0:

candump can0 -t A
  1. To send CAN bus data out of can0:

cansend can0 123#1122334455667788

Loopback Test

If you just want to self-test the CAN function:

  1. Turn loopback on:

sudo ip link set can0 down
sudo ip link set can0 type can loopback on
sudo ip link set can0 type can bitrate 1000000
sudo ip link set can0 up
  1. To receive CAN bus data from can0:

candump can0 -t A
  1. To send CAN bus data out of can0:

cansend can0 123#1122334455667788
  1. Remember to turn loopback off

sudo ip link set can0 down
sudo ip link set can0 type can loopback off
sudo ip link set can0 type can bitrate 1000000
sudo ip link set can0 up