API operation
API operation with escaped characters (AP parameter = 2)
XBee Wi-Fi RF Module User Guide
100
API escaped operating mode works similarly to API mode. The only difference is that when working in
API escaped mode, the software must escape any payload bytes that match API frame specific data,
such as the start-of-frame byte (0x7E). The following table shows the structure of an API frame with
escaped characters:
Frame fields
Byte Description
Start delimiter 1
0x7E
Length
2 - 3
Most Significant Byte, Least Significant Byte
Characters escaped if needed
Frame data
4 - n
API-specific structure
Checksum
n + 1 1 byte
Escape characters
When sending or receiving a serial data frame, specific data values must be escaped (flagged) so they
do not interfere with the data frame sequencing. To escape an interfering data byte, insert 0x7D and
follow it with the byte to be escaped (XORed with 0x20).
The following data bytes need to be escaped:
0x7E (start delimiter)
0x7D (escape)
0x11 (XON)
0x13 (XOFF)
To escape a character:
1. Insert 0x7D (escape character).
2. Append it with the byte you want to escape, XORed with 0x20.
In API operating mode with escaped characters, the length field does not include any escape
characters in the frame and the firmware calculates the checksum with non-escaped data.
Example
: Raw serial data frame (before escaping interfering bytes):
0x7E 0x00 0x02 0x23
0x11
0xCB
0x11
must be escaped which results in the following frame:
0x7E 0x00 0x02 0x23
0x7D 0x31
0xCB
Note
Note In the above example, the length of the raw data (excluding the checksum) is 0x0002 and
the checksum of the non-escaped data (excluding frame delimiter and length) is calculated as:
0xFF - (0x23 + 0x11) = (0xFF - 0x34) = 0xCB
Start delimiter field
This field indicates the beginning of a frame. It is always 0x7E. This allows the device to easily detect a
new incoming frame.
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.