2018-04-28 06:59:14 +08:00
|
|
|
.. _can-sample:
|
|
|
|
|
|
|
|
Controller Area Network
|
|
|
|
#######################
|
|
|
|
|
|
|
|
Overview
|
|
|
|
********
|
|
|
|
|
|
|
|
This sample demonstrates how to use the Controller Area Network (CAN) API.
|
2019-08-07 19:32:04 +08:00
|
|
|
Messages with standard and extended identifiers are sent over the bus.
|
|
|
|
Messages are received using message-queues and work-queues.
|
|
|
|
Reception is indicated by blinking the LED (if present) and output to the console.
|
2018-04-28 06:59:14 +08:00
|
|
|
|
|
|
|
Building and Running
|
|
|
|
********************
|
|
|
|
|
|
|
|
In loopback mode, the board receives its own messages. This could be used for
|
|
|
|
standalone testing.
|
|
|
|
|
2019-10-08 01:37:09 +08:00
|
|
|
The LED output pin is defined in the board's devicetree.
|
2018-04-28 06:59:14 +08:00
|
|
|
|
2019-10-09 20:30:16 +08:00
|
|
|
The sample can be built and executed for boards with a SoC that have an
|
|
|
|
integrated CAN controller or for boards with a SoC that has been augmented
|
|
|
|
with a stand alone CAN controller.
|
|
|
|
|
|
|
|
Integrated CAN controller
|
|
|
|
=========================
|
|
|
|
|
|
|
|
For the NXP TWR-KE18F board:
|
|
|
|
|
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/drivers/CAN
|
|
|
|
:board: twr_ke18f
|
|
|
|
:goals: build flash
|
|
|
|
|
|
|
|
Stand alone CAN controller
|
|
|
|
==========================
|
|
|
|
|
|
|
|
For the nRF52_PCA10040 board combined with the DFRobot CAN bus V2.0 shield that
|
|
|
|
provides the MCP2515 CAN controller:
|
|
|
|
|
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/drivers/CAN
|
|
|
|
:board: nrf52_pca10040
|
|
|
|
:shield: dfrobot_can_bus_v2_0
|
|
|
|
:conf: prj.mcp2515.conf
|
|
|
|
:goals: build flash
|
|
|
|
|
2018-04-28 06:59:14 +08:00
|
|
|
Sample output
|
|
|
|
=============
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2019-08-07 19:32:04 +08:00
|
|
|
Change LED filter ID: 0
|
|
|
|
Finished init.
|
|
|
|
Counter filter id: 4
|
|
|
|
|
|
|
|
uart:~$ Counter received: 0
|
|
|
|
Counter received: 1
|
|
|
|
Counter received: 2
|
|
|
|
Counter received: 3
|
2018-04-28 06:59:14 +08:00
|
|
|
|
|
|
|
.. note:: The values shown above might differ.
|