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

7EStart Delimeter
00 0ALength Bytes
01API Identifier
01API Frame ID
50 01Destination Address low
00Option Byte
48 65 6C 6C 6FData Packet

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

To aide in the creation of API frames, we have developed an API Frame Maker, it can be found here: http://Calculating the Checksum of an API Packet

We also have a video that explains API checksum calculations located here:
Last updated: Aug 23, 2017

Recently Viewed Articles

No recently viewed articles