1, NMT Messages
CANopen devices have three states: pre-operational, operational, and stopped. By default, after startup, they automatically enter the pre-operational state, during which PDO messages cannot be sent. If PDO messages need to be sent, the device must be manually switched to operational (run) state after startup.
The following message can be sent to switch all devices to operational state.
0x000 : 01 00
The message returned by the device indicates that it has entered the operational state. (This feedback message and all subsequent feedback messages will only appear in the upper computer software’s reception area after the heartbeat period has been set for the mixed IO module. How to set the heartbeat is described in detail in the heartbeat message.)
0x742 : 05
If you need to switch back to the pre-operational state, you can send the following message:
0x000 : 80 00
The message returned by the device indicates that it has entered the pre-operational state.
0x742 : 7f
The following message can be sent to put the device into stopped state, during which only heartbeat messages and emergency messages can be sent, and messages can be normally received.
0x00 : 02 00
The message returned by the device indicates that it has entered the stopped state.
0x742 : 04
If you need to restart the device, you can send the following message, at which point temporary modified parameters will automatically revert.
0x000 : 81 00
If you only need to restart communication-related parameters and do not wish to revert other temporary modified parameters, you can send a restart communication message, as follows:
0x000 : 82 00
Note: Node ID is 000, indicating that the sending method is broadcast. The above numbers are all in 16 hexadecimal.
This summarizes the meanings of each value.
Table NMT Message Command Word Values and Their Functions
Command Word (10 decimal/16 hexadecimal) |
Function |
1/1 |
Start Device |
2/2 |
Stop Device |
128/80 |
Put Device into Pre-operational State |
129/81 |
Restart Device |
130/82 |
Restart Device’s Communication Parameters |
2, SDO Messages
SDO messages are mainly used to access various parameters in the object dictionary. They are based on variable addresses (indexes and sub-indexes lock the addresses of various parameters) to read and write various parameters. The format of SDO messages is shown in Table 2.
Table 2 SDO Message Format
Node ID |
Function Code |
Index |
Index |
Sub-index |
Data4 |
Data3 |
Data2 |
Data1 |
Note: Node ID is 600h + device address, the four data are arranged in little-endian format, i.e., reversed. Since the message is byte-based and the index is 16 bits long, it is divided into high 8 bits and low 8 bits. The function code mainly indicates the specific function of the message, which can be divided into read and write. For writing, the function codes can be further subdivided based on the number of bytes written: 2F (read one byte of data, such as digital quantity), 2B (read 2 bytes of data such as analog quantity), 27 (read 3 bytes of data, which is rare), 23 (read 4 bytes of data). When reading messages, it is not necessary to specify the length of the data; the universal code is 40h, but the function code of the SDO message response from the device will show the length of the read data. The specific response function codes are: 4F (1 byte length), 4B (2 bytes length), 47 (3 bytes length), 43 (4 bytes length). Below is an example of reading and writing the values of the IO module’s analog channels.
The index of the IO module is 6411H for various analog quantities. The sub-index 01 corresponds to channel 1, and 02 corresponds to channel 2, for a total of two channels. For example, to write 300 to channel 1, the following message can be sent:
0x642 : 2b 11 64 01 2c 01 00 00
Upon success, the IO returns the following message to the computer, indicating successful writing.
0x5C2 : 60 11 64 01 00 00 00 00 (Function code 60h indicates success; if it is 80h, it indicates failure)
To read the current value of that channel, the following message can be sent:
0x642: 40 11 64 01 00 00 00 00
IO responds to the computer with the message:
0x5C2 : 4b 11 64 01 2c 01 00 00
Note: The high byte of the value written is in byte6, and the low byte is in byte5, for example, the above should translate to 012c (decimal 300). The feedback message’s ID is 580h + node address.
3, PDO Messages
PDO messages are used to transmit process data with real-time requirements. The transmission types can be event type, synchronous transmission, or cyclic transmission. PDO messages are based on the producer-consumer model, so they need to be configured beforehand. This is done in the mapping parameters (1600h+n) and communication parameters (1400h+n). The specific process is completed in three steps. Note: n is the device address.
3.1 RPDO (Receiving PDO)
① Write COB-ID (4 bytes) in the variable specified at index 1400h+n, sub-index 01.
② Write the transmission type in index 1400h+n, sub-index 02 (1 byte); t=1–240 means the device sends PDO every t sync messages received; t=253 means it can only send after receiving one remote (RTR=1) PDO request; t=255 means the transmission type is event-based, meaning the device automatically sends a PDO message whenever a predefined event occurs.
③ Define the mapping relationship under index 1600h+n, which is completed by various sub-indexes. Sub-index 00: defines the total number of subsequent sub-indexes, which in this case is 2; sub-index 01: write the mapping address of the first variable in the following format:
Index (2 bytes)-Sub-index (1 byte)-Data type (1 byte). For example, if the analog value of channel 1 is defined as a mapping variable, its index is 6401h, sub-index is 01, data type is 2 bytes 16-bit, coded as 10h, combined it is 64010110h;
Sub-index 02: here defines the digital input of channels 1-8 (index 6000h: 01) as mapping variables, so its content is 60000108h. Thus, the configuration is complete.
3.2 TPDO (Sending PDO)
① Write COB-ID in index 1800h+n, sub-index 01;
② Write the transmission type in the corresponding sub-index 02, same as 3.1;
③ Configure the mapping in index 1A00h+n, same as 3.1.
4, Heartbeat Messages
If you want the device to automatically report its operational status at regular intervals, you can set the heartbeat message in index 1017H. The default time interval is 0ms, meaning heartbeat messages are disabled. If you want to change this function, simply write the specific interval time directly to 1017H, with the data unit in ms. For example, if you want to send a message every 1s, you can write the following message:
0x642 : 2b 17 10 00 e8 03 00 00
After setting, every second you will receive a message like “0x742 : 7f” (feedback for node address 42, pre-operational state)
Note: In this article, the default device address is set to 42.
5, Synchronization Messages – SYNC
Synchronization messages are only used in PDO messages, serving synchronous transmission types of PDO messages. The generation period of synchronization messages can be set in index 1006h, sub-index 00, with the time unit in microseconds us.
For example, if you want to generate a synchronization message every 10ms, you can write 10000 (0x2710) into the above index. The specific message to send is as follows.
0x642 23 06 10 00 10 27 00 00 (assuming node address is 42) If you want to stop generating synchronization messages, simply change the above value to 0.
If you want to start synchronization messages, write 0x40000080 into index 1005h, sub-index 00. The synchronization message ID is 80h, and there is no data. The format is as follows.
0x80 00 00 00 00 00 00 00 00