The CAN bus ist widely used in many types of vehicles like cars and trucks, airplanes and now even drones. A few years ago the spec was updated and CAN FD was introduced. This upgraded the transmission speed and even more important extended the payload size from 8 byte to 64 byte. The Raspberry Pi doesn't have a CAN controller by default so this needs to be added with a HAT with an external controller.
The MCP2518FD is such a controller offered by Microchip and is connected via SPI. In the last year the driver for this controller found its way into the kernel of the raspbian distribution. So I decided to develop a HAT with it.
The board has only a few components:
- the MCP2518FD CAN controller
- a TCAN332 CAN transceiver which also supports CAN FD
- a switch to enable the termination resistor
- JST GH connectors
- a terminal header to connect other CAN devices
- and a few LEDs to show the status
In reality it looks like this:
It plugs directly ontop of a Raspberry Pi. In my case I used a Raspberry Pi 4.
The HAT is open source hardware and all the data is available on github:
https://github.com/generationmake/CANFDZeroHAT
To enable the HAT and the CAN controller in raspbian you simply have to edit /boot/config.txt
and add line:
dtoverlay=mcp251xfd,spi0-0,interrupt=25
keep care that you choose the right interrupt and SPI CE line and populate the corresponding resistor.
To enable CAN after boot up you have to enter:
sudo ip link set can0 up type can bitrate 250000
So what can be done with this HAT?
I connected an Arduino MKR with an Arduino MKR CAN shield.
On the Arduino side I used the arduino-CAN library ( https://github.com/sandeepmistry/arduino-CAN/ ) and installed the CANSender example.
On the Raspberry Pi the messages can be displayed using the command candump -decaxta can0
and this generates the following output:
As I mentioned before the CAN bus is now also used in drones using the UAVCAN protocol ( https://uavcan.org/ ). There exists also the Dronecode standard ( https://www.dronecode.org/ ) which defines the mechanical connection for the CAN bus and that's why there are JST GH connectors on the HAT.
You can find more infos on this topice here: https://forum.uavcan.org/t/how-to-use-the-raspberrypi-with-mcp2518fd-to-debug-uavcan/1091
In the following picture the HAT is connected to a Zobax Orel 20 motor controller.
Top Comments