Sei sulla pagina 1di 3

Document Type: Tutorial NI Supported: Yes Publish Date: Mar 25, 2011

Developing ARM Applications to communicate via CAN


Overview This tutorial covers the how to use the LabVIEW Embedded Module for ARM to communicate over Controller Area Network (CAN) bus. This tutorial assumes that you already have installed LabVIEW for ARM 1.1 and have familiarity building applications for ARM. Table of Contents 1. 2. 3. 4. 5. Introduction to CAN CAN Interfaces on Evaluation Hardware CAN Communication VIs Examples Related Links

Introduction to CAN CAN is becoming a very popular bus for the automotive industry, with in-vehicle communications, and industrial automation applications. One of the features that makes CAN so successful is its producer-consumer oriented data transmission and multi-master capability. CAN has been standardized by the International Standards Organization as ISO 11898 for high and low-speed/fault-tolerant versions. High-speed CAN reaches 1Mbps and is used for engine control and powertrain applications. Low-speed/fault-tolerant CAN reaches 125Kbps and is used for body and comfort devices. The LabVIEW for ARM provides a simple interface for communicating over CAN. ARM controllers create the basis for low-cost, low-power-consumption embedded systems. CAN Interfaces on Evaluation Hardware Both ARM evaluation board have CAN interfaces. The hardware interfaces on the Keil MCB2300 and Luminary Micro LM3S8962 are illustrated below.

Figure 1: MCB2300 CAN Interface

Figure 2: Luminary Micro LM3S8962 CAN Inteface

CAN Communication VIs The CAN communication VIs for ARM targets are located on the ARM palette.

1/3

www.ni.com

The CAN palette features VIs to open a CAN reference, filter messages, and read/write to the bus.

ARM CAN Open VI Opens a session to a CAN controller. Use this VI to initialize the CAN hardware for CAN communication. You must open a session before you can communicate with a CAN controller.

ARM CAN Start VI This VI Starts communication with a CAN controller on a controller that has already been initialized through LabVIEW interfaces.

ARM CAN Set Receive ID VI This VI configures can interfaces to filter out incoming CAN communication based on device ID. To listen to several devices, call this VI several times.

ARM CAN Read VI Reads data from a CAN bus if available. If no data is present, the VI will wait for the specified timeout value.

ARM CAN Write VI Writes data from a CAN bus if available. Channel information for outgoing data can also be configured. Examples The example code in Figure 3, illustrates how to write data via the CAN bus on ARM hardware. A session to a controller is opened outside of the loop. Within the while loop data is sent via the CAN write VI, specifying data size, and channel.

Figure 3: Code to write data over CAN Bus The example code in Figure 4, illustrates how to read data via the CAN bus on ARM hardware. A session to a controller is opened outside of the loop. Within the while loop data is read using the CAN read VI.

2/3

www.ni.com

Figure 4: Code to read data over CAN Bus

Related Links For more information about the LabVIEW Embedded Module for ARM Microcontrollers, visit www.ni.com/labview/arm/.

Legal This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE ( http://ni.com/legal/termsofuse/unitedstates/us/).

3/3

www.ni.com