101501-565 Rev C
Page 37 of 58
Here is another example, this time for command 22 (Request Status) which has
no arguments.
The original message with a placeholder for checksum is:
<STX>22,<CSUM><ETX>
First, you add up all the characters starting with the ‘2’ in the command
number to the comma before the checksum with their ASCII values (in
hexadecimal):
0x32 + 0x32 + 0x2C = 0x90
Next, you then take the two’s complement of that number by negating it,
by subtracting it from 0x100 (decimal 256), and only retain the lowest 7
bits by bitwise ANDing the results with 0x7F:
NOTE: This combines the steps of getting the twos complement,
truncating the result to 8 bits and clearing the 8
th
bit.
(0x100 – 0x90) & 0x7F = 0x70
Finally, bitwise OR the result with 0x40:
0x70 | 0x40 = 0x70
The checksum byte is 0x70 (Decimal 112, ASCII: p)