CAN-FD on the Raspberry Pi 5
Nov 1, 2024
This is a quick write-down of how to use CAN-FD via the MCP2517FD SPI-to-CAN converter.
This is an updated version of my previous article about CAN-FD on the Raspberry Pi 2.
My Setup
Embedded Linux System: Raspberry Pi 5 Model B Rev 1.0
CAN-FD Board: MIKROE-2379 MCP2517FD from MikroElektronika
Kernel: Linux raspberrypi 6.6.59-v8-16k+ #1810 SMP PREEMPT Fri NovĀ 1 13:15:07 GMT 2024 aarch64 GNU/Linux
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/firmware/config.txt
sudo nano /boot/firmware/config.txt
Turn on SPI by uncommenting:
dtparam=spi=on
and add:
dtoverlay=mcp251xfd,spi0-0,oscillator=40000000,interrupt=12
Note: Set spi, 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 -PLL +MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD o:40.00MHz c:40.00MHz m:20.00MHz rs:17.00MHz es:16.66MHz rf:17.00MHz ef:16.66MHz) 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