can通信调试

1、查看是否有can设备
       ipaddr
2、关闭can设备
      ip link setcan0 down
3、配置波特率
设置CNA0的波特率为500K,在设置前需要先把CAN0关闭了
ip link set can0 type can bitrate 500000
4、打开can设备
ifconfig can0 up
5、查看can设备详细信息
ip -details link show can0
#发送接收测试
candump can0 &
cansend can0 123#1122334455667788
6、发送测试

./cansend can0 -e 0x11 0x22 0x33 0x44 0x550x66 0x77 0x88

interface = can0, family = 29, type = 3,proto = 1

测试软件上能看到接收的帧

7、接收测试,接收测试软件发送的帧:

# ./candump can0

interface = can0, family = 29, type = 3,proto = 1

<0x001> [8] 00 00 00 00 00 00 00 00
<0x002> [8] 01 00 00 00 00 00 00 00
<0x003> [8] 02 00 00 00 00 00 00 00
<0x004> [8] 03 00 00 00 00 00 00 00

8、重启

使用内核文档说的ip link set can0 type can restart-ms 100会报TNETLINK answers: Device or resource busy

9、环回测试
ip link set can0 down
ip link set can0 type can bitrate 50000 loopback on/off
ip link set can0 up
candump can0 &
cansend can0 -s 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88

 10.将两块板的can接口接起来,CANH对CANH, CANL对CANL,一边发送,另一边接收,测试之前速率要设置好,且can接口已经up.
#candump can0 开发板1执行接收命令

#cansend can0 123#11223344556677  开发板2发送数据 

发布了28 篇原创文章 · 获赞 6 · 访问量 1511

猜你喜欢

转载自blog.csdn.net/lx123010/article/details/103895899
今日推荐