下面是官方的說明
-
Enable kernel support for mttcan(Other required modules are already supported)
CONFIG_MTTCAN = m (Here mttcan is compiled as a module) -
Insert CAN BUS subsystem support module.
modprobe can -
Insert Raw CAN protocol module (CAN-ID filtering)
modprobe can_raw -
Real CAN interface support (for our case, it is: mttcan)
modprobe mttcan (dependent module is can_dev: can driver with netlink support) -
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.
-
Installation of user app to check CAN communication
sudo apt-get install can-utils -
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.
- 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