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
Configuration¶
Install necessary packages
sudo apt update
sudo apt install iproute2 can-utils
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
Turn on can0
sudo ip link set can0 up
Enter
ifconfig
, then you should see can0
Test¶
Connect CAN_H and CAN_L to other machines.
To receive CAN bus data from can0:
candump can0 -t A
To send CAN bus data out of can0:
cansend can0 123#1122334455667788
Loopback Test¶
If you just want to self-test the CAN function:
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
To receive CAN bus data from can0:
candump can0 -t A
To send CAN bus data out of can0:
cansend can0 123#1122334455667788
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