Sampling Data from XBee Radio in Change Detection Mode

Change detection as the word itself says detects change of state. We can monitor one or more digital I/O pins for change of state. A sample is transmitted whenever this change of state occurs.  In change detection sampling, a request is made to send a sample of data when ever there is a change in state at one or more digital I/O pins. Here the request is made by the XBee coordinator to the remote XBee end device by sending IC 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, before 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, for setting IC value in the remote end device. IC 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 43 00 10 28
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: IC(0x4943). For HEX codes refer ASCII Table.
Command Parameters: 0x0010 for IC.
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.

The IC command is a bitmask which can be set for the digital I/O lines that need to be observed for change of state. In our case IC=0x0010 is set in the remote end device by the XBee coordinator. The XBee remote end device first sends IC command response (frame type 0x97, called Remote Command Response as seen in the below image) and then automatically samples data from the input lines, frames it and wirelessly transfers it to the coordinator when ever there is a change in state at digital input pin.

Change detection Sampling

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 12 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 00 00 08 B5
16 bit network address of source Receive Options Number of samples Digital Channel Mask Analog Channel Mask Digital Sample Check Sum

Length of payload: Calculated by the number bytes between Frame Type and Command parameter. In the above, there are 18 bytes(HEX equivalent 0x12) 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 0x00 = 0000b, indicating that no analog 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. Since the value of Analog Channel Mask is 0x00, then this field will not have any value.
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