The PI-CAN module is a module with a galvanically isolated CAN FD interface based on the MCP2518FD controller with the MCP2544FD interface. Support for PI-CPUF407 is included in the sample application on GitLab. Let's also take a look at how to get it running on Raspberry OS.

Raspberry OS includes support for MCP2518FD, but it must be enabled. In the /boot/firmware/config.txt file, add the driver using:

dtoverlay=mcp251xfd,oscillator=20000000,spi0-0,interrupt=5

Then we restart and a new network interface, can0, appears in the system. We can test it directly from the command line. First, we activate the interface:

> ip link set can0 up mtu 72 type can bitrate 500000 dbitrate 2000000 fd on

In the command, we set the speed to 500 kbit/s and the high speed CAN FD to 2 Mbit/s.

We can listen on the interface with this command:

> candump can0

If we want to send something, we do so using the command:

> cansend can0 001#01234567

Message format is ID#DATA, so in our case we send identification ID 1 and 4 bytes of data with values 01 23 45 67. If there is no recipient on the bus and the message is not acknowledged, it will be transmitted repeatedly.

However, the cansend command cannot send CAN FD messages at higher speeds. This can be done using the cangen command, which primarily generates random data:

> cangen can0 -f -v 

This command generates random frames of random length. We can change this behavior by adding these switches:

-I <mode> (CAN ID generation mode)
-L <mode> (CAN data length code (dlc) generation mode)
-D <mode> (CAN data (payload) generation mode)
Mode mcan be:
'r'    => random values (default)
'i'    => increment values
<hexvalue>

Dat should be entered in hexadecimal format.

For complete instructions on the cangen command, see the manual:

> man cangen

We can close the interface with the command:

> ip link set can0 down

 

Cookies

We use cookies to deliver and enhance the quality of our services.