如何在TX2上使用CAN

下面是官方的說明

  1. Enable kernel support for mttcan(Other required modules are already supported)
    ​ CONFIG_MTTCAN = m (Here mttcan is compiled as a module)

  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)

  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.

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

  2. 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.

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

回环测试(自发自收)

使能内核支持mttcan,如果mttcan已经编入内核可以省去这步(一般刷机后都把该mttcan模块编入内核了)

CONFIG_MTTCAN = m  (Here mttcan is compiled as a module)

插入can总线子系统支持模块

 sudo modprobe can

插入raw can协议模块

sudo modprobe can_raw

can接口支持

modprobe mttcan

设置can0波特率,回环模式对波特率不做要求

sudo ip link set can0 type can bitrate 500000 loopback on

启动can0

sudo ip link set up can0

查看can配置是否正常

ifconfig

发送数据

cansend can0 123#abcdabcd

在另外一個終端接受数据

candump can0

要想重新配置波特率先关掉can

sudo ip link set down can0

只收(测试毫米波雷达)

毫米波引脚
在这里插入图片描述
测试毫米波的硬件条件,我使用到了TJA1050模块,TJA1050模块的can端接毫米波雷达的can端,TXD,RXD端接开发板的TXD,RXD端
在这里插入图片描述
注意:根据引脚描述,TJA1050模块的TXD应接tx2的TXD端,RXD应接tx2的RXD端,有些can模块有可能是反着接

使能内核支持mttcan,如果mttcan已经编入内核可以省去这步(一般刷机后都把该mttcan模块编入内核了)

CONFIG_MTTCAN = m  (Here mttcan is compiled as a module)

插入can总线子系统支持模块

 sudo modprobe can

插入raw can协议模块

sudo modprobe can_raw

can接口支持

modprobe mttcan

安装用户应用来检查can通信

sudo apt-get install can-utils

若已开启can0则先关掉

sudo ip link set down can0

若之前开启回环测试还没关闭(最好执行)

sudo ip link set can0 type can bitrate 500000 loopback off

启动can0

sudo ip link set up can0

接受信号

candump can0
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值