herunterladen
2004 Microchip Technology Inc. DS00945A-page 1
AN945
INTRODUCTION
CANopen is a field bus protocol based on the Control-
ler Area Network (CAN). As the name implies, it is a
open network standard accepted throughout the world.
While created as a field bus protocol for industrial
automation, CANopen finds use in a wide range of
other non-industrial applications. There are so many
possibilities, in fact, that it is possible to write volumes
on specialized uses of the protocol.
Rather than being specific to one narrow application or
even one field, we present here a more generalized
approach: a generic communication stack based on
CANopen that can be tailored to the user’s needs. This
article focuses only on what is covered in the CAN in
Automation (CiA) standard DS-301. In fact, most of the
discussion is limited to the predefined areas of the
specification, with emphasis on understanding how the
code provided with this application note functions and
how users might develop an application on the
CANopen Stack. To help illustrate this, a simple exam-
ple application is developed based on the CiA DS-401
specification, Generic I/O Modules. The additional
code provided is solely for demonstration; thus there is
no detailed discussion of the demonstration code.
However, code examples with comments from the
demo application are frequently used throughout this
document.
All code provided with this application note is
developed for the PIC18F8680 and PIC18F4680
families of devices, which include ECAN technology as
part of their peripheral set. It is designed to compile with
Microchip’s C18 v2.30 (or greater) compiler. Although
developed for these specific device families, the code
is adaptable to other PIC18 families with CAN.
It is expected that the reader already has some
knowledge of CANopen, or has access to the latest
CANopen standard (listed in the References section) to
refer to for theory and/or critical terminology. The infor-
mation covered in this application note leans towards
understanding the implementation and developing on
that foundation, rather than discussing the many details
of CANopen.
OVERVIEW OF THE STACK
The CANopen Stack provides the lower layers of the
protocol. Some of the features of this design include:
• Embedded state machine for handling all
communications between all nodes and objects
• Default Service Data Object (SDO) Server
• Up to 4 transmit and 4 receive Process Data
Objects (TPDOs and RPDOs)
• Explicit and Segmented Messaging Support
• Statically-mapped PDO support
• Structured dictionary for the PDOs and SDO
• Node Guard/Life Guard
• SYNC consumer
• Heartbeat Producer
• ECAN Driver support
As this list shows, the CANopen Stack discussed here
is designed for applications that are typically more
“slave”. This design is more static in nature, which
leads to more efficient code with better effective use of
code space.
In addition, the actual CANopen code is broken into a
series of smaller source and header files, all written in
C. This allows users to select the appropriate services
that they may need for their application and selectively
build a project tailored to their specific requirements. A
complete list of source files is presented in Table 1.
Of course, the actual application and some aspects of
the communications must still be developed by the
user. The provided CANopen Stack code affords a
base on which the application may be built.
Author: Ross M. Fosler
Microchip Technology Incorporated
A CANopen Stack for PIC18 ECAN
TM
Microcontrollers