树莓派3B+使用RS485 CAN HAT模块

1. 配置CAN接口

编辑启动配置文件:

sudo leafpad /boot/config.txt

在最下面增加:

dtparam=spi=on 
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25,spimaxfrequency=1000000 

然后重启:

sudo reboot

测试接口,执行:

dmesg | grep -i '\(can\|spi\)'

成功后显示如下信息:

树莓派3B+使用RS485 CAN HAT模块_第1张图片

can0 即为CAN接口。

使用can0前需要运行:

sudo ip link set can0 type can bitrate 500000 restart-ms 100
sudo ifconfig can0 up

可以增加开机时启动:

编辑/etc/network/interfaces文件:

sudo leafpad /etc/network/interfaces

在最后增加:

allow-hotplug can0
iface can0 can static
    bitrate 500000
    restart-ms 100

2. 配置RS485接口

打开树莓派设置:

sudo raspi-config

依次选择 Interfacing Options - Serial

树莓派3B+使用RS485 CAN HAT模块_第2张图片

树莓派3B+使用RS485 CAN HAT模块_第3张图片

树莓派3B+使用RS485 CAN HAT模块_第4张图片

树莓派3B+使用RS485 CAN HAT模块_第5张图片

编辑启动配置文件/boot/config.txt,确认如下行:

Enable_uart=1
#dtoverlay=pi3-miniuart-bt 

重启:

sudo reboot

/dev/ttyS0 即为串口。

你可能感兴趣的:(树莓派)