因此可以联想到应该有技术文档或者外国文章早已对can总线的通讯已经做过讨论。因此Google搜索:TX2 can bus
果然有,只不过是在英伟达官方论坛中,继续深入查找,在网址:https://devtalk.nvidia.com/default/topic/1006762/jetson-tx2/how-can-i-use-can-bus-in-tx2-/3中,有以为英伟达官方人员给出了正确方法
看看,和之前CSDN中看的英文一模一样,哈哈。
则得出步骤:(1)首先想要使能canbus必须在tegra18_defconfig配置文件中配置CONFIG_MTTCAN = m 之后重新编译内核才能使用。
(2)安装canbus模块(Linux将不常用的模块做成.ko文件,在需要使用时可以将其进行载入内核,降低系统的开销)
modprobe can
modprobe can_raw
modprobe mttcan
(3)配置canbus属性,和串口的波特率设置类似,同驱动编程中的ioctl
ip link set can0 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
ip link set up can0
ip link set can1 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
ip link set up can1
ip link set up can0
ip link set can1 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
ip link set up can1
(4)安装第三方开源app can-utils 测试canbus
sudo apt-get install can-utils
(5)使用应用程序进行测试
发送程序:
cansend <can_interface> <can_frame>
e.g. cansend can0 123#abcdabcd
接收程序:
candump can_interface
e.g. candump can1
检测canbus的状态:
ip -details -statistics link show can0
ip -details -statistics link show can1
OK,那么对TX2平台下的canbus通讯初探完成,但是canbus的API,应用开发函数仍然未知,但是之前官方人员给出的测试程序app:can-utils为开源程序,因此下一步:上GIT看代码!
具体接线图:
具体收发详细步骤请看:https://blog.csdn.net/hhlenergystory/article/details/81976069
dbc载入并实现收发源代码及测试:https://blog.csdn.net/hhlenergystory/article/details/81976696