CAN总线配置
在Linux系统中,CAN总线接口设备作为网络设备被系统进行统一管理。在控制台下, CAN总线的配置和以太网的配置使用相同的命令。
在控制台上输入命令:
- ifconfig –a
可以得到以下结果:
- can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
- NOARP MTU:16 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:10
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- Interrupt:18
- eth0 Link encap:Ethernet HWaddr 00:50:c2:22:3b:0e
- UP BROADCAST MULTICAST MTU:1500 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- eth1 Link encap:Ethernet HWaddr 00:50:c2:22:3b:60
- UP BROADCAST MULTICAST MTU:1500 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- Interrupt:41 Base address:0xe000
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- inet6 addr: ::1/128 Scope:Host
- UP LOOPBACK RUNNING MTU:16436 Metric:1
- RX packets:256 errors:0 dropped:0 overruns:0 frame:0
- TX packets:256 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:19952 (19.9 KB) TX bytes:19952 (19.9 KB)
在上面的结果中,eth0和eth1设备为以太网接口,can0设备为CAN总线接口。接下来使用ip命令来配置CAN总线的位速率:
- ip link set can0 type can tq 125 prop-seg 6phase-seg1 7 phase-seg2 2 sjw 1
也可以使用ip命令直接设定位速率:
- ip link set can0 type can bitrate 125000
当设置完成后,可以通过下面的命令查询can0设备的参数设置:
- ip -details link show can0
当设置完成后,可以使用下面的命令使能can0设备:
- ifconfig can0 up
使用下面的命令取消can0设备使能:
- ifconfig can0 down
###########################################
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^6
2>. 使用loopback模式测试:
使用loopback模式可测试本机的can驱动是否正常工作.
# ip link set can0 down
# ip link set can0 type can bitrate 50000 loopback on
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip link set can0 up
# candump can0 &
# cansend can0 123#11223344556677