User manual

TMCM-1640 TMCL Firmware V2.00 Manual (Rev. 2.00 / 2012-JUL-31) 11
www.trinamic.com
Checksum calculation
As mentioned above, the checksum is calculated by adding up all bytes (including the module address byte)
using 8-bit addition. Here is an example for the calculation:
in C:
unsigned char i, Checksum;
unsigned char Command[9];
//Set the “Command” array to the desired command
Checksum = Command[0];
for(i=1; i<8; i++)
Checksum+=Command[i];
Command[8]=Checksum; //insert checksum as last byte of the command
//Now, send the command back to the module
4.2 Reply Format
Every time a command has been sent to a module, the module sends a reply.
The reply format for USB and RS485 is structured as follows:
Bytes
Meaning
1
Reply address
1
Module address
1
Status (e.g. 100 means no error)
1
Command number
4
Value (MSB first!)
1
Checksum
- The checksum is also calculated by adding up all the other bytes using an 8-bit addition.
- Do not send the next command before you have received the reply!
4.2.1 Status Codes
The reply contains a status code.
The status code can have one of the following values:
Code
Meaning
100
Successfully executed, no error
101
Command loaded into TMCL
program EEPROM
1
Wrong checksum
2
Invalid command
3
Wrong type
4
Invalid value
5
Configuration EEPROM locked
6
Command not available