Skip to content

Instantly share code, notes, and snippets.

@cbonesana
Last active July 2, 2021 04:06
Show Gist options
  • Save cbonesana/4bafbda680b4a709a5b9638d72b14104 to your computer and use it in GitHub Desktop.
Save cbonesana/4bafbda680b4a709a5b9638d72b14104 to your computer and use it in GitHub Desktop.
Install and use the can-utils package on a Raspberry Pi 3 B
# Board: Raspberry Pi 3 Model B
# OS: Raspbian Jessie Lite (https://www.raspberrypi.org/downloads/raspbian/)
# GPIO reference image: http://imgur.com/a/Cqi9p
# Requirements
# - 4GB at least compatible SD card
# - LAN connection for configuration
# - CAN enabled module
# - HDMI cable for first configuration
# Installation
# Guide: https://www.raspberrypi.org/documentation/installation/installing-images/README.md
# Quick how to:
# - Download Etcher portable (https://etcher.io/)
# - Download the compressed image
# - Unzip the image
# - Use etcher to create an SD card
# First setup
# Username: pi
# Password: raspberry
# reconfigure the board
raspi-config
# enable SSH
# enable SPI
# enable i2c
# disable UART
# OPTIONAL: update software
sudo apt update
sudo apt upgrade
# Bus CAN setup
# Guide: https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=141052
# check boot configuration
sudo vi /boot/config.txt
# some of these values are changed by the raspi-config utility
# to enable, remove the '#' symbol
# enable i2c: dtparam=i2c_arm=on
# enable spi: dtparam=spi=on
# enable mpc2515
# append following lines to enable interface with bus CAN
# we are using a mcp2515 with 8MHz quartz and the interrupt is on GPIO 6
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=6
# the SPI works with a bcm2835 chip
dtoverlay=spi-bcm2835-overlay
# install can-utils
sudo apt install can-utils
# setup can interface for testing purposes
# baudrate of 125k
sudo ip link set can0 down
sudo ip link set can0 up type can bitrate 500000 loopback off listen-only off
# to make this configuration definitve, edit the interfaces file
sudo vi /etc/network/interfaces
# and append following text
auto can0
iface can0 can static
bitrate 500000
loopback off
listen-only off
# reboot
sudo reboot -h 0
# for more information on can-utils package refer to the following GitHub page:
# https://github.com/linux-can/can-utils
# var & utils
# alias for quick details on can0 interface
alias candet='ip -details -statistics link show can0'
# quick monitor of the can0 interface status
while true; do clear; candet; date; sleep 1; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment