Example can

From wiki.emacinc.com
Jump to: navigation, search

This is a guide to the can C example project included in the EMAC OE SDK.

A Controller Area Network (CAN bus) is a robust bus standard for in-vehicle networks. Originally designed for use in the automotive industry, CAN allows micro-controllers and devices to communicate through a message-based protocol with device priority and is used in many different applications to this day.

This project serves as a demonstration of using the CAN bus.

The can project builds one executable: can.

Opening, Building and Uploading the Project Files

For information on opening the project from within Eclipse, please see Importing the EMAC OE SDK Projects with Eclipse. Then, follow Using the EMAC OE SDK Projects with Eclipse for information on how to build, upload and execute the example.

Alternatively, the Makefile can be used with the make command from the commandline to build and upload the example. For information on this method, please see Using EMAC OE SDK Example Projects.

EMAC SDK 5.X

For information on opening the project from within QtCreator, please see QtCreator: Adding Source Files. Then, follow Getting Started With Qt Creator for information on how to build, upload and execute the example.

Alternatively, the CMakefile.txt can be used with the cmake command from the commandline to build and upload the example. For information on this method, please see Getting Started with the EMAC OE SDK.

Usage and Behavior

Hardware Requirements

It should run just fine on any device with a CAN interface. You will need:

  • Two devices with a CAN interface

Using can

The can program is executed from the console. Requires either the argument "send" or "receive"

./can [send/recieve]

The program will wait for data payload to be received (argument: "receive") through CAN or send data payload (argument: "send"), 8 random hex bytes, through CAN. The payload will then be printed on the receive end.

Usage Example

Prepare Device 1 to receive:

root@ipac9x25:~# ./can receive
.

Send Data from Device 2:

root@somimx6ul:~# ./can send
root@somimx6ul:~#

Device 1 received:

root@ipac9x25:~# ./can receive
<0x001> [8] 87 5a 6a 37 7a 94 a4 01
root@ipac9x25:~#

Summary

The can C example project demonstrates the use of the CAN bus.