Calculate and verify checksums

To test data integrity, the device calculates and verifies a checksum on non-escaped data.

To calculate the checksum of an API frame:

  1. Add all bytes of the packet, except the start delimiter 0x7E and the length (the second and third bytes).
  2. Keep only the lowest 8 bits from the result.
  3. Subtract this quantity from 0xFF.

To verify the checksum of an API frame:

  1. Add all bytes including the checksum; do not include the delimiter and length.
  2. If the checksum is correct, the last two digits on the far right of the sum equal 0xFF.

Example

Consider the following sample data packet: 7E 00 0A 01 01 50 01 00 48 65 6C 6C 6F B8+

Byte(s) Description
7E Start delimeter
00 0A Length bytes
01 API identifier
01 API frame ID
50 01 Destination address low
00 Option byte
48 65 6C 6C 6F Data packet
B8 Checksum

To calculate the check sum you add all bytes of the packet, excluding the frame delimiter 7E and the length (the second and third bytes):

7E 00 0A 01 01 50 01 00 48 65 6C 6C 6F B8

Add these hex bytes:

01 + 01 + 50 + 01 + 00 + 48 + 65 + 6C + 6C + 6F = 247

If an API data packet is composed with an incorrect checksum, the XBee/XBee-PRO Zigbee RF Module will consider the packet invalid and will ignore the data.

To verify the check sum of an API packet add all bytes including the checksum (do not include the delimiter and length) and if correct, the last two far right digits of the sum will equal FF.

01 + 01 + 50 + 01 + 00 + 48 + 65 + 6C + 6C + 6F + B8 = 2FF

 

© 2018 Digi International Inc. All rights reserved.
Calculate and verify checksums updated on 05 Jan 2018 08:50 AM