Changes

Jump to: navigation, search

SBCD-AN-001: Using the CAN interface

4,352 bytes added, 11:01, 22 November 2018
Created page with "{{InfoBoxTop}} {{AppliesToSBCD}} {{InfoBoxBottom}} == History == {| class="wikitable" border="1" !Version !Date !Divelk version !Notes |- |1.0.0 |November 2018 |Diva_Embedd..."
{{InfoBoxTop}}
{{AppliesToSBCD}}
{{InfoBoxBottom}}
== History ==

{| class="wikitable" border="1"
!Version
!Date
!Divelk version
!Notes
|-
|1.0.0
|November 2018
|[[Diva_Embedded_Linux_Kit_(DIVELK)|DIVELK 3.0.0]]
|
|-
|}

== Introduction ==
SBC Diva has two CAN interface available on J40 connector.
In order to enable the CAN interface, the correct device tree configuration must be passed to the kernel. The SBCD comes with both CAN interface enabled into its devicetree configuration.

== CAN ==
The CAN peripherals are enabled on the device tree and it can be verified on the kernel ''dmesg''

<pre class="board-terminal">
root@diva:~# dmesg | grep -i can
[ 1.357744] CAN device driver interface
[ 1.363041] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=165)
[ 1.373138] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=166)
[ 1.963737] can: controller area network core (rev 20120528 abi 9)
[ 1.974626] can: raw protocol (rev 20120528)
[ 1.978919] can: broadcast manager protocol (rev 20120528 t)
[ 140.878039] c_can_platform 481cc000.can can0: setting BTR=1c02 BRPE=0000
root@diva:~#
</pre>

The interfaces are also listed by the ''ifconfig'' command

<pre class="board-terminal">
root@diva:~# ifconfig -a
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:165

can1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:166

eth0 Link encap:Ethernet HWaddr D0:FF:50:B3:5E:84
inet addr:192.168.0.95 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:62216 errors:0 dropped:0 overruns:0 frame:0
TX packets:27598 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:75304059 (71.8 MiB) TX bytes:4214320 (4.0 MiB)
Interrupt:177

eth1 Link encap:Ethernet HWaddr D0:FF:50:B3:5E:86
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:123 errors:0 dropped:0 overruns:0 frame:0
TX packets:123 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:208530 (203.6 KiB) TX bytes:208530 (203.6 KiB)

root@diva:~#
</pre>

For enabling the CAN interface, it must be properly configured, for example:

<pre class="board-terminal">
root@diva:~# ip link set can0 type can bitrate 500000 triple-sampling on
root@diva:~# ifconfig can0 up
[ 140.878039] c_can_platform 481cc000.can can0: setting BTR=1c02 BRPE=0000
root@diva:~#
</pre>

== cansend/candump ==
These [https://wiki.linklayer.com/index.php/SocketCAN SocketCAN] utilities are present on [[Diva_Embedded_Linux_Kit_(DIVELK)|DIVELK 3.0.0]] root file system, so it is possible to send and receive packet simply via console commands:

Send packets example:

<pre class="board-terminal">
root@diva:~# cansend can0 -i 0x10 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
interface = can0, family = 29, type = 3, proto = 1
root@diva:~#
</pre>

Receive packets example:

<pre class="board-terminal">
root@diva:~# candump can0
interface = can0, family = 29, type = 3, proto = 1
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
<0x001> [8] 01 02 03 04 05 06 07 08
</pre>
8,154
edits

Navigation menu