Use Cases: Node Cluster Setup , System Configuration
RPI-CAN Card Configuration Guide
Table of contents
Introduction
This section outlines the steps to set up a Raspberry Pi (RPI) for CAN bus support using the MCP2515 module.
Step 1: Configuring the MCP2515 on RPI
First, configure the MCP2515 for communication in the RPI’s Linux environment:
sudo nano /boot/config.txt
This command opens the config.txt
file using the nano editor. Add the following line at the end of the file:
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25
- Ensure the oscillator value corresponds to the one on your MCP2515 module (indicated on the silver oscillator).
- Use interrupt value 25, as the card is designed to utilize RPI pin 25 for the (SPI) interrupt.
Note: When compiling the ESP32 firmware, ensure the board’s CPU Frequency is set to 240 MHz to align with the CAN bus speed.
Step 2: Auto-Starting the CAN Interface on RPI
Configure the RPI to bring up the CAN interface automatically upon boot:
sudo nano /etc/network/interfaces
Open the network interfaces file and add the following configurations:
auto can0
iface can0 inet manual
pre-up /sbin/ip link set can0 type can bitrate 125000 triple-sampling on restart-ms 100
up /sbin/ifconfig can0 up
down /sbin/ifconfig can0 down
These settings initiate can0
as the interface with a bitrate of 125k.
Step 3: Testing the Configuration
To test the setup:
ifconfig can0
-
Run this command in a terminal window to confirm the CAN interface is correctly set up. Look for CAN Bus traffic.
-
Here an example of the
ifconfig
output, showing active CAN communications on CAN0 with data transmission.- If encountering errors, check all connections, reboot both RPI and ESP32, and retest.
- Persistent issues may require rechecking configuration files, settings, and connections to the MCP2515 module.
References
- Adding CAN to the Raspberry PI - provides information on selection of the MCP2515 board and information used in the design of RPI-CAN Card and Linux configuration.