RaspberryPi CAN Interfaces - victronenergy/venus GitHub Wiki

Main document for running Venus OS on a RaspberryPi is here.

On a raspberrypi running Venus OS, CAN-bus interfaces will be automatically recognized and used.

Before reading on to the list of accessories and methods that are known to result in a working CAN-bus port, first be aware of these notes:

  1. Connecting multiple CAN interfaces to a Pi will not work reliably: the Linux kernel will number the interfaces in the order it found them, don't be surprised if they change after a reboot. An udev rule is needed to assign a fixed name. Venus OS only does that for onboard CAN-devices, but there isn't one on a Raspberry PI.

  2. Don’t use products that use SLCAN. The slcan protocol is the interface that the usb accessory and the linux kernel use to communicate. Any product using slcan: reprogram them to a firmware that uses gsusb or don't use them. While the rpi hardware in itself is already unsupported - but works quite well in many cases - the slcan protocol is next level: it is not supported because it doesn't work for VE.Can / NMEA2000 and/or similar higher load and more complex CAN protocols. Both slcan and gsusb are protocols that can be used over cq. on top of USB.

List of products that add CAN to a Pi

CANable

make sure to use the Candelight software, see https://github.com/candle-usb/candleLight_fw or visit https://canable.io/updater/

Peak PCAN-USB (Also Victron CANUSB Interface)

The Peak driver is included in the RPi Venus image, it is recognized automatically.

WAVESHARE

WARNING: These boards use the MCP2515, which only has 2 RX buffers which is not enough to guarantee a loss-free CAN connection. Boards using MCP2518 are better.

This is a RPi HAT board that connects to the SPI bus via the GPIO header. The RPi Venus image includes kernel drivers for the MCP2515 chip used by the WaveShare, as well as a device tree overlay to configure it.

To activate this device, the file /u-boot/config.txt should have the following lines at the end:

[all]
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000

if the crystal on the board is the old 8MHz and not the 12MHz, the dtoverlay should be:

dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25,spimaxfrequency=1000000

The Waveshare isolated 2-CH CAN HAT (https://www.waveshare.com/wiki/2-CH_CAN_HAT), uses a 16MHz crystal with interrupts 23 & 25. Add the following two dtoverlay lines to support both channels on this board:

dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=23,spimaxfrequency=2000000
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=25,spimaxfrequency=2000000

PiCAN HATs

WARNING: This board uses MCP2515, which only has 2 RX buffers which is not enough to guarantee a loss-free CAN connection. Boards using MCP2518 are better.

The PiCANs are a series of RPi HATs available in single and dual port versions, some with isolation that connects to the SPI bus via the GPIO header. It is available from a number of resellers. Reference this dual port example: http://skpang.co.uk/catalog/pican2-duo-canbus-board-for-raspberry-pi-23-p-1480.html or https://copperhilltech.com/raspberry-pi/

The RPi Venus image includes kernel drivers for the MCP2515 chip used by the PiCANs, as well as a device tree overlay to configure it.

To activate edit the file /u-boot/config.txt and add the following lines at the end:

[all]
dtparam=spi=on

# Bring up the PiCAN controllers.
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=mcp2515-can1-overlay,oscillator=16000000,interrupt=24
dtoverlay=spi-bcm2835-overlay

(Omit "...can1..." line if single port HAT is begin used)