Sampling Data from XBee Radio in Periodic Sampling Mode

In this post we will walk through the process of acquiring data samples in periodic sampling mode(IR) and transmit them to the coordinator. To acquire data in this mode, IR value should be set to non-zero value. IR corresponds to the rate at which the remote end device will sample data and transmit it to the requesting device. Only devices running API firmware can send IO data samples out of their UART. Devices running AT firmware will discard received IO data samples. Hence the remote Zigbee end devices are configured with API firmware.

We have already looked into remotely configuring the end device I/O pins as digital input, digital output and analog input from the coordinator. We will look into setting the IR value to non-zero value, to start periodic sampling and then decoding the remote response frame containing the sample to obtain the I/O pin status or value.

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, 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,  for setting IR value in the remote end device. IR value is passed as part of command parameter.

7E 00 11 17 01 00 13 A2 00 40 A9 E4 A2
Delimiter Length of payload Frame Type Frame ID 64 bit address of destination
FF FE 02 49 52 02 00 EA
16 bit network address of destination Command options AT command Command parameter Checksum

Length of payload: Calculated by the number bytes between Frame Type and Command parameter. In the above, there are 17 bytes(HEX equivalent 11) between Frame Type and Command Parameter.
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: IR(0x4952). For HEX codes refer ASCII Table.
Command Parameters: 0x200 for IR which is equivalent to 512 ms or ≈ 0.5s.
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(encircled in red). 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 setting IR to non-zero value, I have configured XBee end device I/O pins as digital input(DIO4), digital output(DIO3) and analog input(AD2) one each as done in our previous posts, so that we get some appropriate digital and analog sample data.

In the below image, the encircled value(black) in the API frame is sampling rate and the underlined part is one set of data. Sampling rate is provided as HEX value(here 0x200) which is equivalent to 512 ms or ≈ 0.5s. The XBee remote end device first sends IR command response and then starts acquiring samples from the input lines, frames it and wirelessly transfers it to the coordinator at IR intervals. Tweak the value of command parameter, to check for varying sampling frequency.

Xbee Periodic Sampling

To stop periodic sampling, pass the above frame with command parameter set to zero(IR=0). This will stop the automatic sampling that is under process as shown below.

XBee Periodic Sampling Stop

The text in blue is the API request frame 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 0x92 i.e, IO Data Sample Rx Indicator frame is shown below. The XBee remote end device will continuously transmit the samples(as seen in red in the above image). Lets decode one sample (underlined) frame and understand the content.

7E 00 14 92 01 00 13 A2 00 40 A9 E4 A2
Delimiter Length of payload Frame Type Frame ID 64 bit address of source
2F 03 41 01 00 18 04 00 08 02 2E C5
16 bit network address of source Receive Options 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 20 bytes(HEX equivalent 0x14) 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: 0x92 for IO Data Sample Rx Indicator 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.
Receive Options: 0x41
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 0x022E = 558 in decimal), then apply the below formula
Voltage = (Equivalent Decimal value* Vref)/1024
Here Voltage = (558*1.2)/1024 = 0.6539 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