User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
64
2.2.6 CRC16 Checksum Calculation
MCP uses a CRC(Cyclic Redundancy Check) to validate each packet it receives. This is more
complex than a simple checksum but prevents errors that could otherwise cause unexpected
actions to execute on the controller.
The CRC can be calculated using the following code(example in C):
//Calculates CRC16 of nBytes of data in byte array message
unsigned int crc16(unsigned char *packet, int nBytes) {
for (int byte = 0; byte < nBytes; byte++) {
crc = crc ^ ((unsigned int)packet[byte] << 8);
for (unsigned char bit = 0; bit < 8; bit++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021;
} else {
crc = crc << 1;
}
}
}
return crc;
}
2.2.7 CRC16 Checksum Calculation for Received data
The CRC16 calculation can also be used to validate data sent from the MCP. The CRC16 value
should be calculated using the sent Address and Command byte as well as all the data received
back from the Roboclaw except the two CRC16 bytes. The value calculated will match the CRC16
sent by the Roboclaw if there are no errors in the data sent or received.
2.2.8 Easy to use Libraries
Source code and Libraries are available on the Ion Motion Control website that already handle
the complexities of using packet serial with the MCP. Libraries are available for Arduino(C++),
C# on Windows(.NET) or Linux(Mono) and Python(Raspberry Pi, Linux, OSX, etc) as well as a
LabView Instrument Driver.