Back to ESAcademy Home Page


MicroCANopen

MicroCANopen V3.30

 

The changes made for version 3.30 of MicroCANopen are:

  1. Auto-generated code:
    The C source files produced by the CANopen Editor CANopen Architect EDS are now supported and can be directly used within MicroCANopen. This allows for a very fast setup of CANopen nodes.
  2. MicroLSS:
    ESAcademy invented MicroLSS, an extension to the existing Layer Setting Services. MicroLSS is an efficient way to auto-detect and configure nodes that do not yet have a node ID assigned.
  3. CANopen Bootloader Support:
    The examples provided now support the CANopen bootloader as avilable from ESAcademy.

MicroCANopen Example

The example code for version MicroCANopen 3.30 was written to be compatible with the CANopen device profile DS401 for generic I/O devices. It uses files auto-generated by CANopen Architect EDS.

Variable Definitions

To allow for an easy address method of variables located in the process image, #define statements are to specify offsets to the location of single variables. The can be auto-generated and are stored in pimg.h:

// mapping entries for RPDO1 [1400]
// [6200,01] UNSIGNED8
#define P620001_DIGOUTPUT8_ 0x00000000
// [6200,02] UNSIGNED8
#define P620002_DIGOUTPUT8_ 0x00000001
// [6200,03] UNSIGNED8
#define P620003_DIGOUTPUT8_ 0x00000002
// [6200,04] UNSIGNED8
#define P620004_DIGOUTPUT8_ 0x00000003
 

// mapping entries for RPDO2 [1401]
// [6411,01] INTEGER16
#define P641101_ANALOGOUTPUT16_ 0x00000004
// [6411,02] INTEGER16
#define P641102_ANALOGOUTPUT16_ 0x00000006
 

// mapping entries for TPDO1 [1800]
// [6000,01] UNSIGNED8
#define P600001_DIGINPUT8_ 0x00000008
// [6000,02] UNSIGNED8
#define P600002_DIGINPUT8_ 0x00000009
// [6000,03] UNSIGNED8
#define P600003_DIGINPUT8_ 0x0000000A
// [6000,04] UNSIGNED8
#define P600004_DIGINPUT8_ 0x0000000B
 

// mapping entries for TPDO2 [1801]
// [6401,01] INTEGER16
#define P640101_ANALOGINPUT16_ 0x0000000C
// [6401,02] INTEGER16
#define P640102_ANALOGINPUT16_ 0x0000000E

// [1018,04] UNSIGNED32
#define P101804_SERIAL_NUMBER 0x00000010

// last byte used in process image
#define PIMGEND 0x00000013


The 20-byte process image contains 4 digital input bytes, 2 analog input words, 4 digital output bytes and 2 analog output words and a serial number of 4 bytes.

It must be ensured that all variables that go into one PDO (a single CAN message with process data) are located consecutively in the process image!

Numerical values with multiple bytes (word, long) must be stored in the process image in "Little Endian" format (least significant byte first).

Upcoming Classes

MicroCANopen Example Application Code Pieces

Initialization

The initialization sequence for the example is implemented within the user call-back function MCOUSER_ResetCommunication() in module user_xxx.c. The auto-generated version looks like this:

#define INITPDOS_CALLS \
MCO_InitRPDO(1, 0x00000000, 4, P620001_DIGOUTPUT8_); \
MCO_InitRPDO(2, 0x00000000, 4, P641101_ANALOGOUTPUT16_); \
MCO_InitTPDO(1, 0x00000000, 200, 50, 4, P600001_DIGINPUT8_); \
MCO_InitTPDO(2, 0x00000000, 300, 20, 4, P640101_ANALOGINPUT16_); \

The parameters for the TPDOs are PDO Number, CAN ID (0 for default), event time, inhibit time, length in bytes, offset in process image.

Main Loop

// background loop
while(1)
{
  // Update process data
  // Echo all data
  gProcImg[P600001_DIGINPUT8_] = gProcImg[P620001_DIGOUTPUT8_];
  gProcImg[P600001_DIGINPUT8_] = gProcImg[P620002_DIGOUTPUT8_];
  gProcImg[P600001_DIGINPUT8_] = gProcImg[P620003_DIGOUTPUT8_];
  gProcImg[P600001_DIGINPUT8_] = gProcImg[P620004_DIGOUTPUT8_];

  // first analog input is real I/O
  pot = read_poti();
  gProcImg[P640101_ANALOGINPUT16_] = pot & 0x000000FF; // lo
  gProcImg[P640101_ANALOGINPUT16_+1] = (pot >> 8) & 0x000000FF; // hi

  // echo all other I/O values from input to output
  // analog
  gProcImg[P640102_ANALOGINPUT16_] =
     gProcImg[P641102_ANALOGOUTPUT16_];
  gProcImg[P640102_ANALOGINPUT16_+1] =
     gProcImg[P641102_ANALOGOUTPUT16_+1];

  // Operate on CANopen protocol stack
  MCO_ProcessStack();

} // end of while(1)

Return to MicroCANopen Home

© Embedded Systems Academy, Inc. All Rights Reserved.

San Jose, CA
Tel. (877) 812-6393
Fax. (877) 812-6382

www.esacademy.com
info@esacademy.com