Operate in API mode
API frame format
Digi XBee® 3 802.15.4 RF Module User Guide
187
Example: escape an API frame
To express the following API non-escaped frame in API operating mode with escaped characters:
Start delimiter Length Frame type
Frame Data
Checksum
Data
7E
00 0F 17
01 00 13 A2 00 40 AD 14 2E FF FE 02 4E 49 6D
You must escape the 0x13 byte:
1. Insert a 0x7D.
2. XOR byte 0x13 with 0x20: 13
⊕
20 = 33
The following figure shows the resulting frame. Note that the length and checksum are the same as
the non-escaped frame.
Start delimiter Length Frame type
Frame Data
Checksum
Data
7E
00 0F 17
01 00 7D 33 A2 00 40 AD 14 2E FF FE 02 4E 49 6D
The length field has a two-byte value that specifies the number of bytes in the frame data field. It does
not include the checksum field.
Length field
The length field is a two-byte value that specifies the number of bytes contained in the frame data
field. It does not include the checksum field.
Frame data
This field contains the information that a device receives or will transmit. The structure of frame data
depends on the purpose of the API frame:
Start delimiter
Length
Frame data
Checksum
Frame type
Data
1
2
3
4
5
6
7
8
9
...
n
n+1
0x7E
MSB
LSB
API frame type
Data
Single byte
n
Frame type
is the API frame type identifier. It determines the type of API frame and indicates
how the Data field organizes the information.
n
Data
contains the data itself. This information and its order depend on the what type of frame
that the Frame type field defines.
Multi-byte values are sent big-endian.
Calculate and verify checksums
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.