PiCAN2-CAN-Bus
CAN-Bus
Introduction
The PiCAN2 board from Tronixlabs Australia provides CAN-Bus capability which is the connection made via DB9 or 3 way screw terminal.
For more details, please visit the website: "https://tronixlabs.com.au/raspberry-pi/can-bus/pican2-can-bus-board-for-raspberry-pi-2-3-with-smps-australia/"
Outlines
a. Assembly
b. Kernel modification
c. Setup CAN-Bus
Porting steps
a. Assembly
The assembly is easy that plug the board on the top of Tinker Board (TB), please reference to below figure:
b. Kernel modification
To bring up this device, it requires to add some more kernel configs and add the new overlay dts for mcp2515, the controller of PiCAN2 board.
Let's start in adding kernel configs:
Since the driver of mcp2515 does not been built-in default, add below configs into {codebase}/kernel/arch/arm/configs/miniarm-rk3288_defconfig
# Enable CAN support of kernel # The following config will also enable can device which are required by mcp251x CONFIG_CAN=y CONFIG_CAN_DEV=y CONFIG_CAN_MCP251X=y
Then, add the overlay dts file for mcp2515 driver as following:
1. Copy the mcp2515-can0-overlay.dts (in attachment) into {codebase}/kernel/arch/arm/boot/dts/overlays
2. Modify {codebase}/kernel/arch/arm/boot/dts/overlays/Makefile to add the overlay file
# Add the red words in the end of the Makefile
dtbo-$(CONFIG_ARCH_ROCKCHIP) += \
....
ds1307.dtbo \
lirc-rpi.dtbo \
lirc-toshiba.dtbo \
The configuration is done, please build the new image and re-flash your SD card.
To load the dts overlay for your new image, modify the /boot/hw_intf.conf in your new SD card
# Add this line into the end of hw_intf.conf intf:dtoverlay=mcp2515-can0
c. Setup CAN-Bus
First, pleas check your CAN-bus device is brought up.
If everything is ok, you should be able to see the can0 in the path /sys/bus/spi/devices/spi2.0/net/ as below figure:
If the device is appear, then we can set it as a can interface for more communication:
# Setup the can0 device as a can interface with bitrate 500k $ sudo ip link set can0 up type can bitrate 500000
Then, you can use the command ifconfig to check the interface is up:
The channel is up for you to use.
Reference
"https://tronixlabs.com.au/raspberry-pi/can-bus/pican2-can-bus-board-for-raspberry-pi-2-3-with-smps-australia/"
"https://vimtut0r.com/2017/01/17/can-bus-with-raspberry-pi-howtoquickstart-mcp2515-kernel-4-4-x/"
"https://www.raspberrypi.org/forums/viewtopic.php?t=141052"
"https://github.com/krzk/tizen-tv-rpi-linux/blob/master/arch/arm/boot/dts/overlays/mcp2515-can0-overlay.dts"