Transclusion: Debian: iMX7: CAN Bus
Revision as of 15:17, 10 December 2018 by imported>Uri.mashiach
Contents
Software installation
- Use the following command to install can-utils:
root@cl-rootfs:~# apt-get install --no-install-recommends can-utils
Loading CAN modules
If the FLEXCAN driver and/or Raw CAN protocol compiled as module(s), they must be loaded prior to enabling CAN interface.
- The FLEXCAN driver gets loaded automatically. Make sure it is loaded:
root@cl-rootfs:~# lsmod | grep can flexcan 102 0
- The FLEXCAN driver can be loaded manually:
root@cl-rootfs:~# modprobe flexcan 30a00000.can supply xceiver not found, using dummy regulator flexcan 30a00000.can: device registered (reg_base=f5a00000, irq=277) 30a10000.can supply xceiver not found, using dummy regulator flexcan 30a10000.can: device registered (reg_base=f5a10000, irq=278)
- Load Raw CAN protocol module:
root@cl-rootfs:~# modprobe can-raw can: raw protocol (rev 20120528)
CAN interface configuration
It is recommended configure the CAN interface, with the iproute2 utilities.
- To make sure the right ip utility is used, run:
root@cl-rootfs:~# ip -V ip utility, iproute2-ss151103
- Configure the CAN interface bit-rate to 125 Kbits/sec (values of up to 1Mbit/sec are supported):
root@cl-rootfs:~# ip link set can0 type can bitrate 125000
- Enable the CAN interface:
root@cl-rootfs:~# ip link set can0 up flexcan 30a00000.can can0: writing ctrl=0x0b312005
Send/Receive packets
Use cansend and candump utilities to send and receive packets via CAN interface.
- Send standard CAN frame (on the first device):
root@cl-rootfs:~# cansend can0 111#1122334455667788
- Send extended CAN frame (on the first device):
root@cl-rootfs:~# cansend can0 11111111#1122334455667788
- Dump all received data frames as well as error frames (on the second device):
root@cl-rootfs:~# candump any,0:0,#FFFFFFFF can0 111 [8] 11 22 33 44 55 66 77 88 can0 11111111 [8] 11 22 33 44 55 66 77 88