Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Rock3/dev/can

< Rock3‎ | dev
    ROCK 3 >  Development >  CAN bus communication

Description

This guide tells about how to use can on ROCK 3 A.

Preparation

  • Two ROCK 3 A running Linux OS
  • Two SN65HVD23x 3.3-V CAN Bus Transceivers boards.
  • Several Dupont wires.

Operations on ROCK 3 A

Install can test tool

$ sudo apt update
$ sudo apt-get install can-utils iproute2

Check the information about can

Check can device

$ ifconfig can0
can0: flags=193<UP,RUNNING,NOARP>  mtu 72
       unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
       RX packets 144  bytes 1152 (1.1 KiB)
       RX errors 175  dropped 0  overruns 0  frame 35
       TX packets 0  bytes 0 (0.0 B)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
       device interrupt 62  

See more details about device can0

$ ip -details -statistic link show can0
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group defa
ult qlen 10
   link/can  promiscuity 0 minmtu 0 maxmtu 0 
   can <FD> state ERROR-WARNING (berr-counter tx 0 rx 0) restart-ms 0 
         bitrate 1000000 sample-point 0.740 
         tq 20 prop-seg 18 phase-seg1 18 phase-seg2 13 sjw 1
         rockchip_canfd: tseg1 1..128 tseg2 1..128 sjw 1..128 brp 1..256 brp-inc 2
         dbitrate 1000000 dsample-point 0.720 
         dtq 40 dprop-seg 8 dphase-seg1 9 dphase-seg2 7 dsjw 1
         rockchip_canfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp-inc 2
         clock 100000000
         re-started bus-errors arbit-lost error-warn error-pass bus-off
         0          140        0          0          15         0         numtxqueues 1 n
umrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
   RX: bytes  packets  errors  dropped overrun mcast   
   1152       144      175     0       35      0       
   TX: bytes  packets  errors  dropped carrier collsns 
   0          0        0       0       0       0

Test can function by loopback test

Here we need one ROCK 3 A.

$ sudo ip link set can0 down
$ sudo ip link set can0 type can bitrate 1000000 dbitrate 1000000 loopback on fd on
$ sudo ip link set can0 up
$ sudo candump can0 &
$ sudo cansend can0 123#11223344
can0  123   [4]  11 22 33 44

You can run more candump can0 & to get more answer.

Test can function between two ROCK 3 A

Hardware connection

ROCK 3 A One --- SN65HVD23x 3.3-V CAN Bus Transceivers Board One --- SN65HVD23x 3.3-V CAN Bus Transceivers Board Two --- ROCK 3 A Two

Example: ROCK 3 A Two send data to ROCK 3 A One via can

This is the c program : Media:Can_test.zip

ROCK 3 A One:

$ gcc -Wall -g -O0 -o can_receive can_receive.c
$ sudo ./can_receive
this is a can receive demo
can_id = 0x123
can_dlc = 8 
data[0] = 1
data[1] = 2
data[2] = 3
data[3] = 4
data[4] = 5
data[5] = 6
data[6] = 7
data[7] = 8

ROCK 3 A Two:

$ gcc -Wall -g -O0 -o can_send can_secd.c
$ sudo ./can_send
this is a can send demo
can_id  = 0x123
can_dlc = 8
data[0] = 1
data[1] = 2
data[2] = 3
data[3] = 4
data[4] = 5
data[5] = 6
data[6] = 7
data[7] = 8

These are the communication between the two boards.

Troubleshooting

Check ROCK 3 FAQs first, if it doesn't help, start a new post on the forum https://forum.radxa.com/c/rock3.