4.5 can bus

This example demonstrates the MYD-AM335X series of the same type of two development board how to use Linux APIs to send and receive data from CAN bus, please refer to the source code for detail.

Hardware Preparation:

  • Hardware debugging environment to see chapter2.
Board Type MYD-AM335X MYD-AM335X-Y MYD-AM335X-J
CAN interface U16 7,8 Pin were connected to the same type of development board 7,8 Pin CON2 1,2 Pin were connected to the same type of development board 1,2 Pin Disconnect jumper cap JP7,Shorted JP4, J17 1,2 Pin were connected to the same type of development board 1,2 Pin

Software Preparation:

  • Linux Kernel 4.1.18
  • can_test application
  • ip link applicatoin
Board Type MYD-AM335X MYD-AM335X-Y MYD-AM335X-J
Operation node can1 can1 can0

Test Steps:

  • Copy cross compiled <WORKDIR>/Examples/can/can_test to /usr/bin directory of the MYD-AM335x series development board, run can_test application as below:
1
2
3
4
5
6
7
8
9
10
# can_test --help
Usage: can_test [options]

Version 1.0
Options:
-d | --device name can device name: can0
-b | --baudrate baudrate set baudrate, default baudrate:50000
-l | --loop operate circularly, default not operate circularly!
-w | --write frame frame string with format ID#MESSAGE. such as: 123#112233445566
-h | --help Print this message
1
2
3
# ip link set can1 down
# ip link set can1 type can bitrate 50000 triple-sampling on
# ip link set can1 up
  • The previous processes are no need to be executed manually. During running can_test, it will be set automatically. One board is used as sender, the other is used as receiver, they communicate with can_test application as below:
1
2
3
4
5
6
7
8
9
10
11
# chmod 777 /usr/bin/can_test
# can_test -d can0 -w 123#112233445566
[ 5783.823623] c_can_platform 481cc000.can can0: setting BTR=1c1d BRPE=0000
[ 5786.888723] can: controller area network core (rev 20120528 abi 9)
[ 5786.895565] NET: Registered protocol family 29
[ 5786.952090] can: raw protocol (rev 20120528)
====== write frame: ======
frame_id = 0x123
frame_len = 6
frame_data = 0x11 0x22 0x33 0x44 0x55 0x66
===========================
  • Execute the following command at other board to receive data as below:
1
2
3
4
5
6
7
# chmod 777 /usr/bin/can_test
# can_test -d can1 -l
[ 5888.821956] c_can_platform 481d0000.can can1: setting BTR=1c1d BRPE=0000
[ 5891.884726] can: controller area network core (rev 20120528 abi 9)
[ 5891.898711] NET: Registered protocol family 29
[ 5891.952878] can: raw protocol (rev 20120528)
can1 0x123 [6] 0x11 0x22 0x33 0x44 0x55 0x66
  • -l option is used for operating circularly.

Note: In case of the following error, please modify the value of “tx_queue_len” as below:

1
2
3
4
# can_test -d can0 -w 123#112233445566
can raw socket write: No buffer space available

# echo 1000 > /sys/class/net/can0/tx_queue_len
  • Exchange roles of the two boards, the result is the same.