Sampling Data from XBee Radio in Queried Sampling Mode

Now that in our previous posts, we have already looked into remotely configuring the end device I/O pins as digital input, digital output and analog input from the coordinator. In this post we will proceed further to acquire data samples from these pins and transmit them to the coordinator. We will also look into decoding the remote response frame to obtain the I/O pin status or value.

The samples are acquired in Queried Sampling(IS) mode. In queried sampling, a request is made to send a sample of data for the I/O pins that are enabled. Here the request is made by the XBee coordinator to the remote XBee end device by sending IS command to the remote end device using Digi X-CTU software.

Hardware/Software environment settings

  • One XBee node configured as Zigbee Coordinator API (Firmware version: 21A7)
  • One XBee node configured as Zigbee End Device API(Firmware version: 29A7)
  • Digi X-CTU application software (Version: 5.2.8.6)

As API mode is enabled in the XBee coordinator, while requesting for sample data from end device we need to check Enable API in the PC Settings tab of the X-CTU.

Enable API

In XBee we have the API frame type 0x17, called Remote AT Command Request frame,  to pass the queried sample request.

7E 00 0F 17 01 00 13 A2 00 40 7C 0F D3
Delimiter Length of payload Frame Type Frame ID 64 bit address of destination
FF FE 02 49 53 F9
16 bit network address of destination Command options AT command Checksum

Length of payload: Calculated by the number bytes between Frame Type and Command parameter. In the above, there are 15 bytes(HEX equivalent 0F) between Frame Type and AT command.
Frame Type: 0x17 for Remote AT Command Request frame.
Frame ID: 0x01 for ACK.
64 bit address of the destination: Assigned by the manufacturer. This is the address of the XBEE end device that the coordinator is talking/requesting to.
16 bit address of the destination: Assigned by the coordinator while forming network. If not known, set it to 0xFFFE. If known, use the appropriate value.
Command Options: 0x02 for update.
AT Command: IS(0x4953). For HEX codes refer ASCII Table.
Checksum: Calculated by adding all bytes after length(exclude delimiter and length) and then keeping only the lowest 8 bits of the result. Next subtract the result from 0xFF to obtain checksum.

In X-CTU, go to Terminal Tab and select Assemble Packet. This will pop up send packet window. Select display as HEX. Enter the API frame that you would like to transfer to the remote end device here and click on send data. Before sending the frame for Queried sample request, I have configured XBee end device I/O pins as digital input(DIO4), digital output(DIO3) and analog input one each as done in our previous posts, so that we get some appropriate digital and analog sample data.

Queried Sample

Here we will discuss only about the last frame from the above image. The text in blue is the API request frame for queried sample passed out from the coordinator to the remote end device. The text in red is the API response frame received from the remote end device by the coordinator. The API response frame type is 0x97, called Remote Command Response.

7E 00 17 97 01 00 13 A2 00 40 A9 E4 A2
Delimiter Length of payload Frame Type Frame ID 64 bit address of destination
2B DB 49 53 00 01 00 18 04 00 08 01 B6 C5
16 bit network address of destination AT Command Command Status Number of samples Digital Channel Mask Analog Channel Mask Digital Sample Analog Sample Check Sum

Length of payload: Calculated by the number bytes between Frame Type and Command parameter. In the above, there are 23 bytes(HEX equivalent 0x17) between Frame Type and Analog sample. For every additional analog I/O enabled, another 2 bytes will be added. So may vary based upon the number analog I/O enabled.
Frame Type: 0x97 for Remote Command Response frame.
Frame ID: 0x01 .
64 bit address of the source: Address of the remote radio returning this response.
16 bit address of the source: Network address of the remote radio.
AT Command: IS(0x4953).
Command Status: 0x0o for OK.
Number of Samples: 0x01. A frame only includes one sample at a time in the payload.
Digital Channel Mask: Bitfield mask to indicate the digital I/O lines that are enabled. In the above frame, the value is 0x0018 = 00011000b, indicating that DIO3(set as output) and DIO4(set as input) are enabled as digital I/O.
Analog Channel Mask: Bitfield mask to indicate the analog I/O lines that are enabled. In the above frame, the value is 0x04 = 0100b, indicating that AD2 is enabled as analog I/O.
Digital Sample: Bitfield with digital sample data. If the value of Digital Channel Mask is 0x00, then this field will not have any value. In the above frame, the value is 0x0008 = 00001000b, indicating that DIO3 is high and DIO4 is low. If you cross check above, DIO3 is set as output high.
Analog Sample: For each enabled analog line, there will be a 2Byte data. In case you have enabled 2 analog input pins in the remote end device, then you will receive 4 bytes data as part of analog sample. If the value of Analog Channel Mask is 0x00, then this field will not have any value. The sample data is in HEX format, which you need to convert and scale, to get the exact voltage value. The ADC is 10 bit, ranging from 0-3FF. First convert the hex to equivalent decimal(here 0x01B6 = 438 in decimal), then apply the below formula
Voltage = (Equivalent Decimal value* Vref)/1024
Here Voltage = (438*1.2)/1024 = 0.513 volt
Checksum: Calculated by adding all bytes after length(exclude delimiter and length) and then keeping only the lowest 8 bits of the result. Next subtract the result from 0xFF to obtain checksum.

NOTE: Except at the instant of sampling, the voltage on the analog pin is 3.3V. It may be due to strong pull-up resistor on the chip associated with the pin, than the potentiometer.

Leave a Reply