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

Difference between revisions of "Rock3/dev/can"

< Rock3‎ | dev
Line 5: Line 5:
 
     [[rock3 | ROCK 3]] > [[rock3/dev | Development]] > [[rock3/dev/can | Using Can]]
 
     [[rock3 | ROCK 3]] > [[rock3/dev | Development]] > [[rock3/dev/can | Using Can]]
  
===Description===
+
=== Description ===
 +
This guide tells about how to use can on ROCK 3 A.
  
ROCK 3 supports can function. Here we will test it on ROCK 3A.
+
=== Preparation ===
Here we use two board to test this function.
+
* Two ROCK 3 A running Linux OS
===Hardware support===
+
* Two SN65HVD23x 3.3-V CAN Bus Transceivers boards.
 +
* Several Dupont wires.
  
Support hardware platform:
+
=== Operations on ROCK 3 A ===
* ROCK 3A  x2
+
==== Install can test tool ====
* Dupont Line
+
 
+
=== Operations on ROCK 3A ===
+
==== Install Test Tool ====
+
 
  $ sudo apt update
 
  $ sudo apt update
 
  $ sudo apt-get install can-utils iproute2
 
  $ sudo apt-get install can-utils iproute2
  
==== Check the information of Can ====
+
==== Check the information about Can ====
 
Check can device  
 
Check can device  
 
  $ ifconfig can0
 
  $ ifconfig can0
Line 31: Line 29:
 
         device interrupt 62   
 
         device interrupt 62   
  
Check Can detailed information
+
See more details about device can0
 
  $ ip -details -statistic link show 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
 
  2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group defa
Line 53: Line 51:
  
 
==== Test can function by loopback test ====
 
==== Test can function by loopback test ====
Just need one board.
+
Here we need one ROCK 3 A.
 +
 
 
  $ sudo ip link set can0 down
 
  $ 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 type can bitrate 1000000 dbitrate 1000000 loopback on fd on
Line 60: Line 59:
 
  $ sudo cansend can0 123#11223344
 
  $ sudo cansend can0 123#11223344
 
  can0  123  [4]  11 22 33 44
 
  can0  123  [4]  11 22 33 44
you can run more '''candump can0 &''' to get more answer.
 
  
==== Test can function between two Rock 3a ====
+
You can run more '''candump can0 &''' to get more answer.
===== '''how to connect two board:''' =====
+
board A:CAN1_TX_M0 connect to board B:CAN1_TX_M0
+
  
board A:CAN1_RX_M0 connect to board B:CAN1_RX_M0
+
==== Test can function between two ROCK 3 A ====
===== '''board A to be receiver and board B to be sender''' =====
+
===== 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]]
 
This is the c program : [[Media:Can_test.zip]]
Board A :
+
ROCK 3 A One:
 +
 
 
  $ gcc -Wall -g -O0 -o can_receive can_receive.c
 
  $ gcc -Wall -g -O0 -o can_receive can_receive.c
 
  $ sudo ./can_receive
 
  $ sudo ./can_receive
Line 84: Line 84:
 
  data[7] = 8
 
  data[7] = 8
 
   
 
   
Board B :
+
ROCK 3 A Two:
 +
 
 
  $ gcc -Wall -g -O0 -o can_send can_secd.c
 
  $ gcc -Wall -g -O0 -o can_send can_secd.c
 
  $ sudo ./can_send
 
  $ sudo ./can_send
Line 98: Line 99:
 
  data[6] = 7
 
  data[6] = 7
 
  data[7] = 8
 
  data[7] = 8
This is the communication between the two boards.
+
 
 +
These are the communication between the two boards.
 +
 
 +
==== Troubleshooting ====
 +
 
 +
Check [[rock3/FAQs |ROCK 3 FAQs]] first, if it doesn't help, start a new post on the forum https://forum.radxa.com/c/rock3.

Revision as of 07:59, 7 September 2021

    ROCK 3 >  Development >  Using Can

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.