Post

What is CANopen bus communication protocol

The scope of this article is to understand the basics of the CANopen bus protocol; the object dictionary, services, SDO, PDO and master/slave nodes.

What is CANopen bus communication protocol

Table of contents

Definition

CANopen is a CAN based communication protocol. It is a “Layer 7” CAN protocol that defines communication and device functions for CAN-based systems. Designed for very flexible configurable embedded networks. CANopen specifies the basic communication mechanisms and device profiles, but also application profiles with specific support for selected application fields.

Maintained by CAN in Automation (CiA) organization.

Mostly used in Automotive, factory automation, off-road vehicles, maritime electronics, medical equipment, and railways.

These are some of the core specs you should know about CANopen:

See an Transfer syntax for data type INTEGERn
octet number12345678
INTEGER8b7..b0
INTEGER16b7..b0b15..b8
INTEGER24b7..b0b15..b8b23..b16
INTEGER32b7..b0b15..b8b23..b16b31..b24
INTEGER40b7..b0b15..b8b23..b16b31..b24b39..b32
INTEGER48b7..b0b15..b8b23..b16b31..b24b39..b32b47..b40
INTEGER56b7..b0b15..b8b23..b16b31..b24b39..b32b47..b40b55..b48
INTEGER64b7..b0b15..b8b23..b16b31..b24b39..b32b47..b40b55..b48b63..b56

CANopen protocol on OSI model

CANopen (CiA 301) only defines the application layer, based on CAN bus:

CANopen Application layer with CAN protocol layers in relation to the OSI model CANopen Application layer with CAN protocol layers in relation to the OSI model

CAN acts like a telephone line enabling communication, while CANopen is like the language spoken over that line.

Basic CANopen Device Model

A device is structured like the following:

  • Communication interface: This part sends and receives data over the network.
  • Object Dictionary: A list of all data items (information) that controls how the device works and communicates.
  • Application: The main function of the device for the interaction with the process environment.

CANopen basic device model schema CANopen basic device model schema Device Model

Communication models

On CANopen three different communication models are used. Each one closely linked to the CANopen communication protocols.

CANopen communication models CANopen communication models CANopen communication models

Master/Slave

One node (master) controls the communication by requesting or sending data to all other nodes (slaves). This setup is mostly used for tasks like diagnostics, configuration, or managing states. The system can include 0-127 slaves.

Protocol that use it: NMT.

Producer/Consumer

A producer node broadcasts data to the network to zero or more consumer(s). There are two options:

  • push model: The producer send data without been requested.
  • pull model: The producer send data by a consumer request.

Protocol that use it: PDO, HEARTBEAT, SYNC, TIME, EMCY.

Client/Server

A client send a request (upload/download) triggering the server to perform a certain task.

  • Upload: Client read from a server.
  • Download: Client write to a server.

Protocol that use it: SDO.

CANopen CAN frame

CANopen gives meaning to the arbitration part of a CAN frame and defines how to encode its data part.

CANopen over CAN frame CANopen over CAN frame CANopen data over CAN frame

The 11 bits of the CAN ID correspond to the CANopen COB-ID, which is divided into two parts: the first 4 bits are the function code, and the remaining 7 bits are the node ID.

See pre-defined COB-IDs used in CANopen.
Communication objectFunction code [bin]Node ID [bin (hex)]Generic COB-ID [hex]Resulting COB-ID [dec (hex)]Communication Parameters at Index
NMT000000h0-
SYNC0001080h128 (80h)1005h, 1006h, 1007h
TIME STAMP00100100h256 (100h)1012h, 1013h
EMERGENCY00010000001 (1h) – 1111111(127h)80h + Node ID129 (81h) – 255 (FFh)1014h, 1015h
TPDO100110000001 (1h) – 1111111(127h)180h + Node ID385 (181h) – 511 (1FFh)1800h
RPDO101000000001 (1h) – 1111111(127h)200h + Node ID513 (201h) – 639 (27Fh)1400h
TPDO201010000001 (1h) – 1111111(127h)280h + Node ID641 (281h) – 767 (2FFh)1801h
RPDO201100000001 (1h) – 1111111(127h)300h + Node ID769 (301h) – 895 (37Fh)1401h
TPDO301110000001 (1h) – 1111111(127h)380h + Node ID897 (381h) – 1023 (3FFh)1802h
RPDO310000000001 (1h) – 1111111(127h)400h + Node ID1025 (401h) – 1151 (47Fh)1402h
TPDO410010000001 (1h) – 1111111(127h)480h + Node ID1153 (481h) – 1279 (4FFh)1803h
RPDO410100000001 (1h) – 1111111(127h)500h + Node ID1281 (501h) – 1407 (57Fh)1403h
TSDO10110000001 (1h) – 1111111(127h)580h + Node ID1409 (581h) – 1535 (5FFh)1200h
RSDO11000000001 (1h) – 1111111(127h)600h + Node ID1537 (601h) – 1663 (67Fh)1200h
HEARTBEAT (NMT Error Control)11100000001 (1h) – 1111111(127h)700h + Node ID1793 (701h) – 1919 (77Fh)1016h, 1017h

Communication objects: Communication protocols and services

Process Data Object (PDO)

Used for real-time data transfer. PDO can contain 8 bytes of data and multiple object parameter values in a single frame.

‘Consumer/producer’ protocol is used and there are two kinds of PDO:

  • Transmit-PDO (TPDO) -> Node acts as producer
  • Receive-PDO (RPDO) -> Node acts as consumer

The following PDO transmission modes are distinguished:

  • Synchronous transmission (in response to a SYNC)
    • Cyclic: Transmission is triggered periodically after every 1, 2 or up to 240 SYNC messages
    • Acyclic: Synchronized with SYNC
  • Asynchronous
    • Event-driven transmission (e.g. periodically, with an application event…)
    • Remotely requested PDO (Legacy, no recommended)

CANopen PDO transmission modes CANopen PDO transmission modes CANopen PDO transmission modes

Data type and mapping of application objects into a PDO is determined by a corresponding default PDO mapping structure within the Object Dictionary (OD).

If variable PDO mapping is supported the configuration process is done by the SDO services to the corresponding objects of the OD.

Service Data Object (SDO)

Used to provide direct access to entries in a node’s object dictionary, allowing transfer of data of any size/type between a client and server.

Transfer Types:

  • Expedited: For small data sets (up to 4 bytes, fast single transfer during initialization), transfers the full payload in a single initialization/confirmation flow.
  • Segmented: First is an initialization/confirmation step an then data is sent as a sequence of smaller parts (7 bytes of data segments).
  • Block Transfer: For large data sets, groups segments into blocks (up to 127 segments per block) for faster transfer, with initialization and finalization/check phases.
sequenceDiagram
    Client->>Server: Initiate SDO expedited download (Request)
    Server-->>Client: Initiate SDO expedited download (Confirmation)
    Note over Client,Server: Can be download or upload
    Client->>Server: Initiate SDO expedited upload (Request)
    Server-->>Client: Initiate SDO expedited upload (Confirmation)
sequenceDiagram
    Client->>Server: Initiate SDO segmented download (Request)
    Server-->>Client: Initiate SDO segmented download (Confirmation)
    Client->>Server: SDO download segment 1
    Server-->>Client: SDO download segment (Confirmation)
    Client->>Server: SDO download segment 2
    Server-->>Client: SDO download segment (Confirmation)
    Note over Client,Server: After n segments | Where n_max = 7
    Client->>Server: SDO download segment 7 (End)
    Server-->>Client: Final SDO download segment (Confirmation)

    Note right of Server: Can be<br/>download or upload
sequenceDiagram
    Client->>Server: SDO block download initiate (Request)
    Server-->>Client: SDO block download initiate (Confirmation)
    Client->>Server: SDO block 1 download segment 1
    Note over Client,Server: After n segments | Where n_max = 127
    Client->>Server: SDO block 1 download segment 127
    Server-->>Client: SDO block download (Confirmation)
    Client->>Server: SDO block 2 download segment 1
    Note over Client,Server: After n segments
    Client->>Server: SDO block 2 download segment 127
    Server-->>Client: SDO block download (Confirmation)
    Note over Client,Server: After n blocks
    Client->>Server: SDO block n download segment 1
    Note over Client,Server: After n segments
    Client->>Server: SDO block n download segment 42
    Server-->>Client: SDO final block download (Confirmation)
    Client->>Server: SDO block download end (Request)
    Server-->>Client: SDO block download end (Confirmation)

    Note right of Server: Can be<br/>download or upload

CANopen generic TSDO frame example CANopen generic TSDO frame example CANopen generic Transmission-SDO frame example

All services are defined on CiA 301 section 7.2.4.2. To see every frames you can go here CANopen high-level protocol for CAN-bus

Special Protocols

Network Management (NMT)

Used to control the state of CANopen nodes. To request a state change, the NMT master sends a 2-byte message with COB-ID = 0: the first data byte specifies the desired state, and the second byte identifies the target node by its node ID.

Node ID = 0 indicates a broadcast command.

CANopen NMT frame CANopen NMT frame CANopen NMT frame example

Node states machine

CANopen node state machine CANopen node state machine CANopen node state machine

Synchronization Object (SYNC)

Periodically broadcasts a synchronization (SYNC) object that provides the basic network synchronization mechanism. Nodes that operate synchronously may use the SYNC object to synchronize their timing with the SYNC producer.

This synchronization is usually triggered by the application master.

The SYNC frame has the COB-ID = 080. And the data field may include a SYNC counter, used to explicitly associate the current SYNC cycle with PDO transmission.

Using the SYNC counter several groups of synchronously operating devices can be configured.

Time Stamp Object (TIME)

This function is used to provide global network time.

The frame has COB-ID = 100 and contains 6 data bytes: the first four bytes represent the time in milliseconds since midnight, and the next two bytes show the number of days since January 1, 1984.

Emergency Object (EMCY)

Used in case a device experiences a fatal error, sending broadcasts frame to indicate this to the rest of the network.

Take into account that the EMCY is optional.

See data bytes emergency error code classes.
Error codeDescription
00xxhError reset or no error
10xxhGeneric error
20xxhCurrent
21xxhCurrent, CANopen device input side
22xxhCurrent inside the CANopen device
23xxhCurrent, CANopen device output side
30xxhVoltage
31xxhMains voltage
32xxhVoltage inside the CANopen device
33xxhOutput voltage
40xxhTemperature
41xxhAmbient temperature
42xxhCANopen device temperature
50xxhCANopen device hardware
60xxhCANopen device software
61xxhInternal software
62xxhUser software
63xxhData set
70xxhAdditional modules
80xxhMonitoring
81xxhCommunication
82xxhProtocol error
90xxhExternal error
F0xxhAdditional functions
FFxxhCANopen device sp
See data bytes emergency error codes.
Error codeDescription
0000hError reset or no error
1000hGeneric error
2000hCurrent – generic error
2100hCurrent, CANopen device input side – generic
2200hCurrent inside the CANopen device – generic
2300hCurrent, CANopen device output side – generic
3000hVoltage – generic error
3100hMains voltage – generic
3200hVoltage inside the CANopen device – generic
3300hOutput voltage – generic
4000hTemperature – generic error
4100hAmbient temperature – generic
4200hDevice temperature – generic
5000hCANopen device hardware – generic error
6000hCANopen device software – generic error
6100hInternal software – generic
6200hUser software – generic
6300hData set – generic
7000hAdditional modules – generic error
8000hMonitoring – generic error
8100hCommunication – generic
8110hCAN overrun (objects lost)
8120hCAN in error passive mode
8130hLife guard error or heartbeat error
8140hrecovered from bus off
8150hCAN-ID collision
8200hProtocol error - generic
8210hPDO not processed due to length error
8220hPDO length exceeded
8230hDAM MPDO not processed, destinationobject not available
8240hUnexpected SYNC data length
8250hRPDO timeout
9000hExternal error – generic error
F000hAdditional functions – generic error
FF00hDevice specific – generic error

NMT Error Control: Node Guarding and Heartbeat

To know nodes status, CANopen uses Node Guarding and Heartbeat to ensure devices are operational and to alert the system if communication fails. At least one mechanism is required for network reliability.

Node guarding

The NMT master periodically sends out guarding requests to each slave. If a slave device responds within a specified time window, it is considered healthy and connected.

Some systems support life guarding, allowing the slave to monitor if the master is still communicating. If not, the slave alerts its own local application.

NMT Node Guarding communication workflow NMT Node Guarding communication workflow NMT Node Guarding communication workflow

HEARTBEAT

In this system, devices assigned as heartbeat producers send out a special “heartbeat” broadcasts message at regular intervals and heartbeat consumers, listen for these messages.

NMT HEARTBEAT communication workflow NMT HEARTBEAT communication workflow NMT HEARTBEAT communication workflow

Object Dictionary (OD)

Attribute Description rw read and write access wo write only access ro read only access const read only access

Standardized structure that contain node’s all parameters describing its behavior. All nodes must have one. OD entries are looked up via a 16-bit index and 8-bit subindex.

Each entry is described by:

  • Index: 16-bit base address of the object
  • Object name: Manufacturer device name
  • Object code: Array, variable, record…
  • Data type: BOOL, UNSIGNED32, Record Name…
  • Access attributes: rw (read/write), ro (read-only), wo (write-only)…
  • Category: Indicates if this parameter is mandatory/optional (M/O)
See General Object dictionary index structure.
IndexObject
0000hnot used
0001h – 001FhStatic data types (standard data types, e.g. Boolean, Integer16)
0020h – 003FhComplex data types (predefined structures composed of standard data types, e.g. PDOCommPar, SDOParameter)
0040h – 005FhManufacturer-specific complex data types
0060h – 025FhDevice profile specific data types
0260h – 0FFFhreserved
1000h – 1FFFhCommunication profile area (e.g. Device Type, Error Register, Number of PDOs supported)
2000h – 5FFFhManufacturer-specific profile area
6000h – 9FFFhStandardised Device Profile Area (e.g. "DSP-401 Device Profile for I/0 Modules" [3]: Read State 8 Input Lines, etc.)
A000h – BFFFhStandardized network variable area
C000h – FFFFhreserved
>Don't be confused by all the 'data types' located in the OD at indices below 0FFF; they're there mainly or definition purposes only. The relevant range of a node's OD lies between 1000 and 9FFF.
See Object dictionary objects definitions.
Object codeObject nameDefinition
00hNULLAn object with no data fields
02hDOMAINLarge variable amount of data (e.g.executable program code)
05hDEFTYPEDenotes a type definition such as a BOOLEAN, UNSIGNED16, FLOAT...
06hDEFSTRUCTDefines a new record type (e.g. the PDO mapping structure at 21h)
07hVARVariable of a single data type (BOOL, UNSIGNED16, INTEGER8…)
08hARRAYArray of variables of the same data type
09hRECORDArray of variables with different data types. Sub-index 0 has always data type UNSIGNED8 and conatins the number of elements
See Object dictionary data types.
IndexObjectName
0001hDEFTYPEBOOLEAN
0002hDEFTYPEINTEGER8
0003hDEFTYPEINTEGER16
0004hDEFTYPEINTEGER32
0005hDEFTYPEUNSIGNED8
0006hDEFTYPEUNSIGNED16
0007hDEFTYPEUNSIGNED32
0008hDEFTYPEREAL32
0009hDEFTYPEVISIBLE_STRING
000AhDEFTYPEOCTET_STRING
000BhDEFTYPEUNICODE_STRING
000ChDEFTYPETIME_OF_DAY
000DhDEFTYPETIME_DIFFERENCE
000Ehreserved
000FhDEFTYPEDOMAIN
0010hDEFTYPEINTEGER24
0011hDEFTYPEREAL64
0012hDEFTYPEINTEGER40
0013hDEFTYPEINTEGER48
0014hDEFTYPEINTEGER56
0015hDEFTYPEINTEGER64
0016hDEFTYPEUNSIGNED24
0017hreserved
0018hDEFTYPEUNSIGNED40
0019hDEFTYPEUNSIGNED48
001AhDEFTYPEUNSIGNED56
001BhDEFTYPEUNSIGNED64
001Ch – 001Fhreserved
0020hDEFSTRUCTPDO_COMMUNICATION_PARAMETER
0021hDEFSTRUCTPDO_MAPPING
0022hDEFSTRUCTSDO_PARAMETER
0023hDEFSTRUCTIDENTITY
0024h – 003Fhreserved
0040h – 005FhDEFSTRUCTManufacturer-specific Complex Data types
0060h – 007FhDEFTYPEDevice profile specific Standard Data types 1 st logical device
See Access attributes for data objects
AttributeDescription
rwRead and write access
rwwAn accessory definition of CiA 306 v1.2, read and write access to an object where writing affects directly a process output. Objects with this attribute can be mapped in a devices RPDO
rwrAn accessory definition of CiA 306 v1.2, read and write access to an object where reading reads a process input. Objects with this attribute can be mapped in a devices TPDO
woWrite only access
roRead only access
constRead only access, but the value is always the same, it's constant
Exaple of an PDO records specification PDO communication parameter record ↴
IndexSub-indexNameData type
0020h00hHighest sub-index supportedUNSIGNED8
01hCOB-IDUNSIGNED32
02hTransmission typeUNSIGNED8
03hInhibit timeUNSIGNED16
04hreservedUNSIGNED8
05hEvent timerUNSIGNED16
06hSYNC start valueUNSIGNED8
PDO mapping parameter record ↴
IndexSub-indexNameData type
0021h00hNumber of mapped objects in PDOUNSIGNED8
01h1st object to be mappedUNSIGNED32
02h2nd object to be mappedUNSIGNED32
04h2nd object to be mappedUNSIGNED32

Electronic Data Sheet (EDS): Human-readable form of Object Dictionary (by CiA 306)

An INI file format, acting as the ‘template’ for the OD of a device and contains info on all device objects (PDOs, SDOs, specific objects defined in the device profiles…)

See an example of an EDS's one RPDO definition ```ini [...] [1402] ParameterName=Receive PDO Communication Parameter 2 ObjectType=0x9 SubNumber=4 [1402sub0] ParameterName=Number of entries ObjectType=0x7 DataType=0x0005 AccessType=ro DefaultValue=5 PDOMapping=0 LowLimit=0x02 HighLimit=0x05 [1402sub1] ParameterName=COB ID ObjectType=0x7 DataType=0x0007 AccessType=rw DefaultValue=0x400+$NODEID PDOMapping=0 LowLimit=0x00000001 HighLimit=0xFFFFFFFF [1402sub2] ParameterName=Transmission Type ObjectType=0x7 DataType=0x0005 AccessType=rw DefaultValue=1 PDOMapping=0 [1402sub5] ParameterName=Event Timer ObjectType=0x7 DataType=0x0006 AccessType=rw DefaultValue=0 PDOMapping=0 [...] [1602] ParameterName=Receive PDO Mapping Parameter 2 ObjectType=0x9 SubNumber=5 [1602sub0] ParameterName=Number of entries ObjectType=0x7 DataType=0x0005 AccessType=rw DefaultValue=4 PDOMapping=0 LowLimit=0 HighLimit=8 [1602sub1] ParameterName=PDO Mapping Entry ObjectType=0x7 DataType=0x0007 AccessType=rw DefaultValue=0x20000910 PDOMapping=0 [1602sub2] ParameterName=PDO Mapping Entry ObjectType=0x7 DataType=0x0007 AccessType=rw DefaultValue=0x20000a10 PDOMapping=0 [1602sub3] ParameterName=PDO Mapping Entry ObjectType=0x7 DataType=0x0007 AccessType=rw DefaultValue=0x20010110 PDOMapping=0 [1602sub4] ParameterName=PDO Mapping Entry ObjectType=0x7 DataType=0x0007 AccessType=rw DefaultValue=0x20010210 PDOMapping=0 [...] [2000] ParameterName=Reception Element 2 ObjectType=0x9 SubNumber=11 [2000sub0] ParameterName=NrOfObjects ObjectType=0x7 DataType=0x0005 AccessType=rww DefaultValue=10 PDOMapping=0 [...] [2000sub9] ParameterName=i_sp_lim_pow ObjectType=0x7 DataType=0x0006 AccessType=rww PDOMapping=1 [2000subA] ParameterName=i_sp_lim_pow_ef ObjectType=0x7 DataType=0x0006 AccessType=rww PDOMapping=1 [2001] ParameterName=Reception Element 3 ObjectType=0x9 SubNumber=11 [2001sub0] ParameterName=NrOfObjects ObjectType=0x7 DataType=0x0005 AccessType=rww DefaultValue=10 PDOMapping=0 [2001sub1] ParameterName=rcw_gen_10 ObjectType=0x7 DataType=0x0006 AccessType=rww PDOMapping=1 [2001sub2] ParameterName=rcw_gen_11 ObjectType=0x7 DataType=0x0006 AccessType=rww PDOMapping=1 [...] ```

Cable connectors (by CiA 303-1)

Despite CiA 303-1 list a lot of connector pin assignment for general and special purpose, here I am going to focus on DB9 connector, de facto standard for general purpose CAN bus.

D-SUB 9-pin connector pin assignment schema D-SUB 9-pin connector pin assignment

CANopen history

gantt
    title CANopen bus history milestones
    dateFormat  YYYY-MM-DD
    axisFormat %Y
    todayMarker off

    CiA (CAN in Automation) founded                         :milestone, 1992-01-01, 0d
    CiA 301 v1.0, CAN Application Layer (CAL) protocol is released      :milestone, 1994-01-01, 0d
    The standard is given the name "CANopen"                :milestone, 1995-01-01, 0d
    CiA 401 released (device profiles for generic I/O modules)          :milestone, 1996-01-01, 0d
    CiA 402 released (device profiles for drives and motion control)    :milestone, 1997-01-01, 0d
    CiA 303-1 v1.0 released (connectors and cabling)        :milestone, 1999-01-01, 0d
    CANopen v4.01 internationally standardized (EN 50325-4) :milestone, 2002-01-01, 0d
    CiA 306 v1.3.0 released (EDS, DCF)                      :milestone, 2005-01-01, 0d
    CiA 1301 released (CANopen FD)                          :milestone, 2017-01-01, 0d
    CiA 510 released (mapping CANopen protocols to J1939)   :milestone, 2020-01-01, 0d

CAN bus standard overview

CiA develops and publishes technical documents. Specifications contain functional requirements and permissions to be implemented in hardware or software. These are the most important:

  • CiA 301: CANopen application layer and communication profile
  • CiA 302: CANopen additional application layer functions
  • CiA 303-1: Device and network design - Part 1: CANopen physical layer
  • CiA 305: CANopen layer setting services (LSS) and protocols
  • CiA 306: CANopen electronic data sheet (EDS)
  • CiA 401: CANopen profile for I/O devices
  • CiA 402: CANopen device profile for drives and motion control

References

Useful tools

This post is licensed under CC BY 4.0 by the author.