Hardware Reference
In-Depth Information
for (int i =0 ; i <= 17 + datalen ; i++){
softSerial.write ( replyPacket[i]);
}
} // end void constructReply()
With everything compiled and hooked up, a prepared packet can be sent from the X-CTU's packet-assembly
window. Watch the code's actions in a serial monitor that is connected to the Arduino. The serial monitor should
start printing information when a packet is received and proceed through the programmed responses. This code is a
demonstration of packet handling and sometimes messes up on receive and transmit packets, because of the lack of
more robust error correction.
To make the error checking a bit more robust, you can the check the reply packet against the created checksum
for the new packet and re-create it before the packet is sent. Other error checking can be performed with flow control,
timeouts, resends, and packet-acknowledgement communication. The transmit status frame type ( 0x8B ) that is
returned when a packet is sent does not indicate that the packet was successfully received by anything other than XBee
modules. A microcontroller should form a reply packet to the state of a received packet if the incoming packets are from
serial out from an XBee module. This method of packet handling is demonstrated in greater depth in Chapter 8.
If the code in Listing 5-1 does not respond, resend the packet a few times before checking the configurations. You
can also issue an ND command to check the XBee radio connection. If the radios can see one another, double-check
the serial connections on the Arduino and, if necessary, revert to the software serial, and then double-check the code.
Endpoint Firmware
The last firmware option is that of endpoint for both AT and API modes. They act similarly to any other module
firmware by issuing and receiving data. However, unlike the router and coordinator, end devices do not route
packets to other devices. End devices also have the capability to enter sleep mode because they do not store routing
information. Sleep mode makes end devices the preferred choice when making remote sensors or controllers that
need low power consumption.
There are three types of sleep configuration that are set via the sleep mode ( SM ) register:
Setting a value of 1 in the
SM register will put the module in hibernate mode. When XBee pin 9 is
high, the module will not respond to any transmissions or requests, but will return from sleep.
Setting the
SM register to 4 is for cyclic sleep. In this mode, the endpoint module will still
respond to incoming transmissions. When using API mode, the extended timeout option
( 0x40 ) needs to be set in the packet's transmit options, giving the end device time to wake
up and respond. The controlling program in this mode must wait till the Clear to Send (CTS)
flow-control line is low.
Setting the value to 5 works the same as 4, but allows a transition from low to high on XBee pin
9 to wake the module for transmission.
Endpoint modules have the capability to connect to either routers or coordinators. The code and setup for the
last example will work for the end device.
1.
For this setup, reconfigure the router module with ZIGBEE END DEVICE API.
2.
Use the same settings to create a network, change the node identifier to ENDDEVICE, set
the SM register to 4, and connect back to the Arduino.
3.
Reconstruct the HELLO packet with 0x40 in the options byte, and send this packet to
watch the code work. In this configuration, when the end device receives a packet, it will
be awake for a period of time to allow the module to transmit the outgoing packet.
 
Search WWH ::




Custom Search