CAN-FD on the Raspberry Pi 2
Oct 22, 2021
This is a quick write-down of how to use CAN-FD via the MCP2517FD SPI-to-CAN converter.
I spent multiple hours getting this running and decided to write it down so that I don't have to remember it the next time. Also, maybe it helps some of you...
An updated version of this article for the Raspberry Pi 5 can be found here.
My Setup
Embedded Linux System: Raspberry Pi 2 Model B Rev 1.1
CAN-FD Board: MIKROE-2379 MCP2517FD from MikroElektronika
Kernel: Linux raspberrypi 5.10.63-v7+ #1459 SMP Wed Oct 6 16:41:10 BST 2021
Image: Raspberry Pi OS Lite from May 7th, 2021
The Hardware version of your Raspberry Pi can be read using:
cat /sys/firmware/devicetree/base/model
The Kernel version can be read using:
uname -a
Now, out of principle, we first run:
sudo apt-get update
sudo apt-get upgrade
Install some CAN utilities:
sudo apt-get install can-utils
Edit /boot/config.txt
Turn on SPI by uncommenting:
dtparam=spi=on
and add:
dtoverlay=mcp251xfd,oscillator=40000000,interrupt=12
Note: Set oscillator
and interrupt
according to your hardware.
Check
After rebooting, check the boot log using:
dmesg
The boot log should contain something like this:
mcp251xfd spi0.0 can0: MCP2517FD rev0.0 (-RX_INT +MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:20.00MHz r:17.00MHz e:15.62MHz) successfully initialized.
The device should now be available in the device tree. This can be verified using the following command:
ls /sys/bus/spi/devices/spi0.0/net/can0/
Buy me a Coffee
If this article was helpful to you, you can support this website via a one-time donation using the following button:
Initialize
sudo ip link set can0 up type can bitrate 500000 dbitrate 500000 sample-point 0.75 dsample-point 0.75 sjw 2 fd on
Note: Change initialization according to your BUS settings.
Now, the can0 interface should be visible when running:
ifconfig
Test
Use
candump can0