Rockpi4/use-rs485-can-hat-on-rock-pi-4
< Rockpi4
ROCK Pi 4 > use-rs485-can-hat-on-rock-pi-4
Contents
Introduction
This guide tells The SPI interface of the development board is converted into can interface through RS485 CAN HAT interface
Upgrade kernel or flash system image if needed
I use the following image to test can here. https://dl.radxa.com/rockpi4/images/debian/rockpi4b_debian_buster_xfce4_arm64_20210608_1321-gpt.img.gz and install it to ROCK Pi 4B.
# ls /usr/lib/modules/`uname -r`/kernel/drivers/net/can/spi/mcp251x.ko /usr/lib/modules/4.4.154-112-rockchip-gfdb18c8bab17/kernel/drivers/net/can/spi/mcp251x.ko
You need to update APT first
go to https://wiki.radxa.com/Rockpi4/radxa-apt
Download code sample
At board terminal:
$ sudo apt-get install p7zip-full $ wget http://www.waveshare.net/w/upload/d/de/RS485_CAN_HAT_Code.7z $ 7z x RS485_CAN_HAT_Code.7z -r -o./RS485_CAN_HAT_Code $ sudo chmod 777 -R RS485_CAN_HAT_Code/
Connection mode
H-H L-L
Block reception
- open the board terminal, and run:
$cd RS485_CAN_HAT_Code/CAN/wiringPi/receive/ $make clean $make $sudo ./can_receive
Can see
root@rockpi4b:/home/rock# ./can_receive this is a can receive demo
Send
- open the another board terminal and run:
$cd RS485_CAN_HAT_Code/CAN/wiringPi/send/ $make clean $make $sudo ./can_send
Can see
# ./can_receive this is a can receive demo can_id = 0x123 can_dlc = 8 data[0] = 1 data[1] = 2 data[2] = 3 data[3] = 4 data[4] = 5 data[5] = 6 data[6] = 7 data[7] = 8
$ ./can_send this is a can send demo can_id = 0x123 can_dlc = 8 data[0] = 1 data[1] = 2 data[2] = 3 data[3] = 4 data[4] = 5 data[5] = 6 data[6] = 7 data[7] = 8 $ ./can_send