Home > Support > Knowledge Base
Knowledge Base
Reset Search



Calculating the Checksum of an API Packet

« Go Back


Problem Resolution

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

To aide in the creation of API frames, we have developed an API Frame Maker, it can be found here: http://www.digi.com/support/kbase/kbaseresultdetl?id=3215

We also have a video that explains API checksum calculations located here: http://www.digi.com/learningcenter/video/player?id=xbee-zb-checksum-calculation



Was this article helpful?



Please tell us how we can make this article more useful.

Characters Remaining: 255