TX2平台CAN总线收发功能的测试

前言

项目实现过程中需要将获取的数据信息通过CAN总线传输到控制规划模块,本文主要介绍如何在TX2平台测试CAN总线的收发功能。

TX2是英伟达旗下为嵌入式平台人工智能应用开发出的一个硬件平台,TX1没有CAN bus功能,TX2有。

CAN bus作为TX2的外设,一般需要驱动,也有一些功能函数,可以用这些函数进行应用编程。Linux下的canbus是通过socket进行can传输的。

大致实现步骤是:安装驱动 -> 安装开源canbus通信的user app -> 连接CAN接口以及canbus收发器 -> 测试CAN总线收发功能;

实现方法

参考英伟达官方论坛here,可以找到官方的回复,步骤如下:

These are the steps can be followed to enable and check CAN on TX2.
1. Enable kernel support for mttcan(Other required modules are already supported)
CONFIG_MTTCAN = m (Here mttcan is compiled as a module)

使能canbus需要在tegra18_defconfig配置文件中配置CONFIG_MTTCAN=m之后重新编译内核才能使用。

本人拿到的板子这一步已经完成,直接进行之后的步骤;


2. Insert CAN BUS subsystem support module.
modprobe can

3. Insert Raw CAN protocol module (CAN-ID filtering)
modprobe can_raw
4. Real CAN interface support (for our case, it is: mttcan)
modprobe mttcan (dependent module is can_dev: can driver with netlink support)

modprobe是在linux的shell运行的命令行,用于安装canbus模块;

Linux将不常用的模块做成.ko文件,在需要使用时可以将其进行载入内核,降低系统的开销;


5. CAN interface settings for both the controllers
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

CAN interfaces are up now. Use ifconfig to list all the interfaces which are up.

配置canbus的属性(命令行配置),和串口的波特率设置类似,同驱动编程中的ioctl.


6. Installation of user app to check CAN communication
sudo apt-get install can-utils

安装第三方开源app can-utils测试canbus的收发功能;


7. Commands to run to check CAN packet send/receive
broadcasting a can data packet:(发送程序)
cansend <can_interface> <can_frame>
e.g. cansend can0 123#abcdabcd

Receiving a can data packet:(接收程序)
candump can_interface
e.g. candump can1
Different tools (i.e. cangen, cangw etc) can be used for various filtering options.

命令行使用应用程序测试canbus的收发功能;


8. To check the interface statistics
ip -details -statistics link show can0
ip -details -statistics link show can1

检测canbus的状态;

以上完成在TX2平台使用命令行测试CAN通讯,有机会会介绍canbus的API和应用开发函数,具体可参看github上can-utils的开源程序here.

问题

1.使用CAN分析仪测试CAN总线的收发功能,打开can分析仪的应用工具CANPro,连接TX2平台can接口、CAN分析仪和应用工具主机,使用命令行测试can口的收发功能;

2.测试成功,但是每次重启或者开机需要重新配置CAN的环境,解决方法是在/etc/rc.local中添加canbus模块和属性(2-5步骤)即可;

3.若各个设备连接没有问题,且相关配置也已完成,但是不能正常收发,需要查看板子的can接口硬件部分PIN脚是否连接正确;(重要!!)

参考

1.英伟达官网论坛

2.CSDN系列博客

3.can-utils开源程序

转载于:https://www.cnblogs.com/happyamyhope/p/8796844.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值