Wireless communication with XBee
XBee modules enable wireless, serial communication among devices.
To connect an XBee module to a DE2-115 board, use an XBee module on a
serial base unit
and connect it to the DE2-115's
serial port via a
male-male,
null-modem serial cable.
You'll also need to connect a 5-16V power adapter to the serial base unit.
To connect an XBee module to a computer, use an XBee module on a
USB base unit and
connect it to the computer's USB port.
To configure an XBee module, first connect it to a Windows computer. You
may need to add a USB-serial
adapter if your computer lacks a serial port and the XBee module is on
a serial base unit. Then install and run the X-CTU program from Digi (look
under Diagnostics, Utilities and MIBs). Under the PC Settings
tab, select the COM port that is attached to your XBee module.
In order for X-CTU to communicate with the XBee module, both will need to
use the same baud rate.
When you start using a particular XBee module, you may need to
try a few different baud rates to figure out what it has been set to.
Configure the baud rate used by X-CTU under the PC Settings tab
(the other settings should be no flow control, 8 data bits, no parity, 1
stop bit), then click Test/Query to see if X-CTU can communicate
with the XBee module. The most common baud rates are 9600 and 115200.
Next, restore the XBee module to its default settings. Under the Modem
Configuration tab, click Restore. The default baud rate is 9600,
so you'll need to configure X-CTU's baud rate to 9600 to match.
After you've restored the XBee module to its default settings, you can
configure its parameters (under the Modem Configuration tab).
First, click Read to read the current configuration. Then set
the following parameters:
- Under Serial Interfacing, set Interface Data Rate
(i.e., the baud rate) to 115200 (this matches the baud rate of the DE2-115 boards).
- Under Networking & Security, set Channel to 1A
to avoid
conflicting with WiFi.
- Under Networking & Security, set PAN ID to something
unique to your project. All XBee modules that are communicating with each
other need to use the same PAN ID. It's best to use something other than
the default value (3332), so you don't accidentally talk with another
group's XBee module.
- Click Write to save this configuration to the XBee module, then
change the baud rate of X-CTU to 115200.
With these settings, all data sent from one XBee module will be broadcast
to all other XBee modules that are using your PAN ID. If you don't want
to broadcast to all other XBee modules, there are three strategies for sending
data to one particular XBee module.
- The first strategy is to use X-CTU to configure the XBee module to send to
specific destinations. Under Networking & Security, set
Destination Address High and Destination Address Low to
the 64-bit serial number of the XBee module you want to send data to.
This strategy is very easy, but it only allows you to change the destination
addresses while you're running X-CTU.
- The second strategy is to use the communicating program itself (e.g.,
the E100 program) to change the destination address while the system is
running. The program can do this by sending
AT commands to the
XBee module:
- Enter command mode by sending +++ (make sure that no data
is sent for 1 second before or after the +++).
- Set the destination address by sending the following data:
- ATDH <HIGH><CR>
- ATDL <LOW><CR>
where <HIGH> is the high 32 bits of the destination address
(represented as the ASCII characters of the hexadecimal value);
<LOW> is the low 32 bits of the destination
address (represented as the ASCII characters of the hexadecimal value);
and <CR> is the carriage return character (ASCII 13).
- Exit command mode by sending ATCN. The XBee module will
automatically exit command mode after 6.4 seconds if you don't keep sending
AT commands.
- The XBee module will respond to each AT command; your
program will need to receive and ignore these responses.
- The third strategy is to add a header field to each message and
specify the intended destination in the header field. All XBee modules
will receive the message and examine the header field.
Only the intended recipient will process the message; other nodes will
ignore the message.
See the XBee documentation for full details on how to
use XBee modules.