Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (36 sloc) 1.47 KB

SocketCan - CAN BUS library (Linux only)

Controller Area Network Protocol Family bindings (SocketCAN).

[samples/](See sample for usage.)

Setup for Raspberry PI and MCP2515

  • Connect SPI device to regular SPI pins (SI/MOSI - BCM 10; SO/MISO - BCM 9; CLK/SCK - BCM 11; CS - CE0)
  • Interrupt pin should be connected to any GPIO pin i.e. BCM 25 (note: interrupt pin can be adjusted below)
  • Add following in /boot/config.txt

For test run ifconfig -a and check if can0 (or similar) device is on the list.

Now we need to set network bitrate and "start" the network. Other popular bit rates: 10000, 20000, 50000, 100000, 125000, 250000, 500000, 800000, 1000000

sudo ip link set can0 up type can bitrate 125000
sudo ifconfig can0 up

Diagnosing the network (tested on Raspberry Pi)

These steps are not required but might be useful for diagnosing potential issues.

  • Install can-utils package (i.e. sudo apt-get install can-utils)
sudo apt-get -y install can-utils
  • On first device listen to CAN frames (can be also sent on the same device but ensure seperate terminal)
candump can0
  • On second device send a packet
cansend can0 01a#11223344AABBCCDD
  • On the first device you should see the packet being send by the second device


You can’t perform that action at this time.