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\)'
成功后显示如下信息:
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 :
编辑启动配置文件/boot/config.txt,确认如下行:
Enable_uart=1
#dtoverlay=pi3-miniuart-bt
重启:
sudo reboot
/dev/ttyS0 即为串口。
————————————————
版权声明:本文为CSDN博主「lixiaoxin1989」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lixiaoxin1989/article/details/91905860