XBee radio communication between PICs
Two wired PICs can communicate by RS-232. We can replace the wires with a wireless link. In this project, that wireless link will be implemented using Zigbee radio modems that use the IEEE 802.15.4 protocol. The demonstration will show two PICs talking to each other over wireless, and a PIC talking to a PC by wireless. This demonstration has the user typing in data into hyperterminal and the PIC responding. For example, the user might type "1+5 [enter]" and the PIC responds with "6".
It is common for two pics to communicate by RS-232, a wired transmission. However, it may be desirable to communicate via a wireless link. This wiki page discusses this option by using XBee radio modems using the IEEE 802.15.4 protocol. This will allow for two pics to communicate wirelessly as well as a pic and a PC to wirelessly communicate.
The IEEE 802.15.4 is a point-point/point-multipoint communications protocol(similar to Bluetooth) designed for low-power devices. Like Bluetooth, the IEEE 802.15.4 specification also uses the 2.4 GHz ISM band. The ZigBee protocol, which deals with mesh networking and routing, is built upon the IEEE 802.15.4 specification.
The XBee radios, made by Digi (formerly Maxstream), are shipped with firmware implementing the IEEE 802.15.4 protocol, but can be loaded with the ZigBee protocol stack, which can be downloaded from the Digi website. Note that ZigBee is still in its infancy and devices from different manufacturers may not be compatible. The range for an XBee Pro indoors is up to 300 feet while line of site, outdoor communication is up to a mile. (XBee Manual
The XBee requires a 3.3 voltage regulator and the chip is designed to be mounted in specific sockets (See figure) (Note: These sockets don't fit in a standard bread board!)
For the pin locations, see page 7 of XBee Manual or the figure to the right.
For PIC to computer interface a program such as X-CTU needs to be used, X-CTU can be downloaded from X-CTU Site.
The XBee module can be connected directly to the UART port on the PIC. To connect it to a RS2-32 port, one must use a voltage shifting transceiver chip because RS232 signals are from -15V to + 15V. The MAX232/ST232 chip will convert voltage level from RS-232 to TTL logic levels and vice versa. The chip requires 4 external capacitors (the fifth is a bypass capacitor) in order to operate. The transceiver data sheet can be found here
Using the XBee Radio
AT commands enable you to set the parameters of the XBee radio. To enter AT command mode, open XC-TU and type in "+++" (without the quotes). The chip should respond with an "OK". Then, you can enter the commands. If the radio doesn't receive a commands for a while (default 10s), then it will exit command mode and return to normal operation mode. Specific instructions and descriptions of allowable parameters to send can be found in the XBee Product Manual.
Some commonly used commands:
- +++ Enter command mode
- ATCN Exit command mode
- ATAC Apply changes
- ATWR Write current parameter values to non-volatile memory (must reset or use ATAC for changes to take effect)
- ATRE Restore defaults
- ATFR Reset
- ATCH Set channel
- ATID Set network ID
- ATDH Set desination ID (high byte)
- ATDL Set destination ID (low byte)
- ATMY Set device ID
- ATBD Set baud rate
- ATAP Set transparent/API mode
By default, the radios are set to work in transparent mode (as opposed to API mode). The radios will send the whatever comes in on the serial port to all other radios having the same channel, PAN ID, and destination address (CH, ID, and DH+DL parameters).
Proprietary API mode
To use the API mode, set the AP parameter to 1 or 2, depending on whether you will need escape characters (see the manual for more information).
The API mode allows users to send data in a packet structure. Commands and specific destination addresses can be embedded into packets, which allows you to give the radio commands without having to enter the AT command mode. The packet also inclues a checksum (the packet won't be sent/received if this is wrong), and receiving packets will have things like source address and signal strength embedded.