Difference between revisions of "Rockpi4/use-rs485-can-hat-on-rock-pi-4"
< Rockpi4
Line 11: | Line 11: | ||
This guide tells The SPI interface of the development board is converted into can interface through RS485 CAN HAT interface | 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 | |
− | sudo apt | + | |
− | sudo apt | + | $ sudo apt update |
+ | $ sudo apt install -y linux-4.4-rock-pi-4-latest | ||
=== Download routine === | === Download routine === | ||
Line 24: | Line 25: | ||
At board terminal: | At board terminal: | ||
− | |||
− | |||
$ sudo apt-get install p7zip-full | $ sudo apt-get install p7zip-full | ||
$ wget http://www.waveshare.net/w/upload/d/de/RS485_CAN_HAT_Code.7z | $ 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 | $ 7z x RS485_CAN_HAT_Code.7z -r -o./RS485_CAN_HAT_Code | ||
$ sudo chmod 777 -R RS485_CAN_HAT_Code/ | $ sudo chmod 777 -R RS485_CAN_HAT_Code/ | ||
− | |||
=== Connection mode === | === Connection mode === | ||
Line 49: | Line 47: | ||
root@rockpi4b:/home/rock# ./can_receive | root@rockpi4b:/home/rock# ./can_receive | ||
this is a can receive demo | this is a can receive demo | ||
− | |||
=== Send === | === Send === | ||
Line 58: | Line 55: | ||
$make | $make | ||
$sudo ./can_send | $sudo ./can_send | ||
− | |||
Can see | Can see |
Revision as of 12:27, 20 August 2021
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
$ sudo apt update $ sudo apt install -y linux-4.4-rock-pi-4-latest
Download routine
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