Skip to content

CAN Shield Configuration

tobiasjaehnelavl edited this page May 31, 2023 · 5 revisions

In order to configure the SPI controller of the Raspberry Pi to make it communicate with the CAN-Shield, you need to add a few lines to config.txt which is available on the boot partition of the RaspberryPi OS / CarSimulator Image. This is different for each CAN shield:

CAN-Shield lines to be added to config.txt Notes
![PiCAN 2](images/PiCAN-2.jpg) PiCAN 2
    dtparam=spi=ondtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
    dtoverlay=spi-bcm2835-overlay
  
PiCAN 2 DUO PiCAN 2 DUO
    dtparam=spi=on
    dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
    dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=24
    dtoverlay=spi-bcm2835-overlay
  
![RS485 CAN HAT](images/RS485-CAN-HAT.jpg) RS485 CAN HAT
  dtparam=spi=on
  dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25,spimaxfrequency=1000000
  
This CAN-Shield has a 8MHz clock only. During high bus activity this can lead to problems. We especially experienced this during flashing where frames got lost.
![PiCAN 2](images/PiCAN-3.jpg) PiCAN 3
  dtparam=spi=on
  dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25,spimaxfrequency=500000
  dtoverlay=spi-bcm2835-overlay
  
[PICAN3_UGA_10.pdf](https://copperhilltech.com/content/PICAN3_UGA_10.pdf)

Note: spimaxfrequency needs to be set, which is not mentioned in the User Guide, in case the shield is used on RPi4, because the SPI bus has a higher frequency by default than the CAN controller can handle. Maybe higher freq is possible. If it's too high, the controller driver can't be loaded during bootup and there is an error message in dmesg visible.

See this link for more details.

Clone this wiki locally