Calculating the Checksum of an API Packet

The API operation of the radios (XTend and XBee) requires that communication through the UART or serial port of the radio be done through a structured interface where data is communicated in formatted hexadecimal frames. New frames begin with the delimiter 7E. Consider the following sample data packet.

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

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 2nd and 3rd 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

 

Now take the result of 0x247 and keep only the lowest 8 bits which in this example is 0x47 (the two far right digits). Subtract 0x47 from 0xFF and you get 0xB8 (0xFF - 0x47 = 0xB8). 0xB8 is the checksum for this data packet.

If an API data packet is composed with an incorrect checksum, the radio will consider the packet invalid and the data will be ignored.

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


More information can be found here: API Frame Specs
 

Last updated: Aug 23, 2017

Recently Viewed

No recently viewed articles

Did you find this article helpful?