- XBee Module and AT/API Background
- Project Brief
- Project Requirements
- XBee Module Configuration
- Microcontroller Firmware
- Hardware Connections
- Testing the Example Code
- Contact the Author
XBee modules provide an easy way to add wireless capability to an embedded application. The purpose of this page is to demonstrate how to interface and control an XBee module in AT mode with a host microcontroller.
Digi International provides a large array of wireless modules. Each have their individual benefits. Some are meant for WiFi, while some are meant for ZigBee applications. Some XBee modules are 802.15.4 compliant but do not necessarily comply with a wireless network protocol. Still other XBee modules from Digi International are completely proprietary and do not comply with well accepted standards. All of these modules can be used to accomplish wireless communication. It is up to the designer to determine what, if any, protocols the design must comply with and which XBee modules actually comply with the needed standard.
This example demonstrates XBee operation in AT mode. AT mode is synonymous with "Transparent" mode. In AT mode, any data sent to the XBee module is immediately sent to the remote module identified by the Destination Address in memory. When the module is in AT mode, it can be configured by the user or a host microcontroller by first placing the module in Command mode and then sending predefined AT commands through the UART port. This mode is useful when you don't need to change destination addresses very often, or you have a very simple network, or simple point to point communication. For larger networks that involve nodes talking to multiple targets, API mode is more useful. In API mode, rather than sending AT commands serially, data packets are assembled that include the Destination Address. API mode allows you to change destination address much more quickly because Command Mode doesn't need to be entered. API mode is also useful if the user needs to change the configuration of a remote module. This project focuses on AT mode operation.
A list of supported AT commands can be found in Chapter 10 of the following XBee module user guide:
This project will demonstrate how to interface an XBee module with a host microcontroller. We will cover what hardware connections are needed and what communication settings are required. For this particular project, the microcontroller used was a PSoC4 device from Cypress (CY8C4245). The PSoC4 Pioneer Kit was used as the development platform for the microcontroller. For this particular project, the XBee module used was an XBee-PRO ZigBee module (XBP24BZ7WIT-004). A wireless Arduino shield (A000065) was used to interface the XBee module to the host microcontroller. The microcontroller was loaded with a user application that can place the module in Command Mode or Transmit mode. The application also accepts user input from a PC terminal. If the application is in Command Mode, it checks whether the user entered a valid AT command and either executes the command or displays an error message. If the application is in the Transmit state, any characters entered by the user are transmitted wirelessly to a remote node. The microcontroller uses two UART ports–one for communication between the PC and the microcontroller, and one for communication between the microcontroller and the XBee module. In this way, the microcontroller acts as a sort of "middle man" between the PC and the XBee device and monitors user input before sending it to the XBee module. The PSoC4 Pioneer Board includes an on-board UART / USB bridge, so we will be able to connect to a USB port of the PC with just a simple USB mini-B cable.
The X-CTU software provided for free by Digi International is still required to configure the XBee modules as Coordinators, Routers, or End Devices, and to switch between AT and API mode. For examples of how to configure XBee modules using X-CTU software, click here. Once the modules are configured, they can be used in an embedded application.
This project uses a Cypress microcontroller. If the reader is using a different host microcontroller, this project can still demonstrate, conceptually, what is required to interface with an XBee module. The reader can still view the example code and use it to re-create the application in the desired microcontroller software development environment. The reader should keep in mind, however, that two UART ports are required to re-create this demo.
The following hardware/software is required if the reader wishes to re-create this demo:
This project used a PC running x64 Windows 7 Pro with all of the required software.
XBee modules can be easily configured using the Parallax USB Adapter Board. If you have the Parallax adapter board, you can skip to the Configuration Settings section below.
The modules can be configured without the Parallax adapter board by using the Arduino Wireless Shield, the PSoC 4 Pioneer board, and jumper wires. The user must connect an XBee module to the Wireless Shield and make the following connections (it may be easier to connect the pins if the Arduino Shield is not mounted on the Pioneer Board) as shown in the Figure to the right:
|Arduino Shield||Pioneer Board|
|Pin1 of J6||Pin9 of J8|
|Pin2 of J6||Pin10 of J8|
|*5V on Power Header||Pin4 of J1|
|*GND on Power Header|
Pin2 of J1
*The Power/GND pins only need to be connected if the Arduino Shield is not mounted on the Pioneer Board.
Module Configuration without Parallax USB Adapter Board
Refer to this example for configuring XBee modules using the X-CTU software and the Parallax adapter board.
Use the Parallax USB Adapter board or the setup shown above to connect the XBee modules to the PC for configuration. If using the above setup, ensure the 'Serial Select' slide switch is set to 'Micro'.
The application code for the host microcontroller sets up two UART ports. One UART port allows communication between the PC and microcontroller. The other allows communication between the microcontroller and the XBee module. For a simple PSoC UART example, click here. In PSoC Creator, two UART (SCB) components were added to the design.
The following settings were applied to each UART:
UART1 - PC / Micro
The UART between the PC and microcontroller used the following settings:
UART2 - Micro / XBee
The UART between the microcontroller and XBee module used the following settings:
The application code also used a push-button to switch between Command Mode and Transmit Mode. The PSoC4 Pioneer Kit comes with a tactile push-button (SW2) connected between Pin 0_7 and ground. When SW2 is pressed, P0_7 sees a logical '0'. In PSoC Creator, a digital input pin was created for P0_7. This is already done for you in the provided example code, but here are some step by step instructions:
The application code involves setting up and monitoring the UARTs and the push-button. The bulk of the application code involves checking user-entered data and string manipulation. The application code implements a 2-state machine. The two states are the Command Mode state and the Transmit Mode state. SW2 is used to toggle between the two states. On power-up the machine starts in Transmit Mode state. Any characters typed will be immediately transmitted to the node assigned by the "Destination Address". If the machine is placed in the Command Mode state, the code checks for a valid command entered by the user. If the command is valid, the XBee module is placed in Command Mode and the entered AT command is executed. After the command is executed, the XBee module is placed back in Idle Mode. However, the state-machine remains in Command Mode until SW2 is pressed again. Therefore, the user doesn't need to press SW2 every time an AT command is entered.
The following code block presents a code outline to assist the reader in generating application code for various platforms.
Download the following PSoC Creator example project to demonstrate running the XBee modules in AT mode through PC terminal software.
The PC UART used P4[1:0] of the micro while the XBee UART used P0[5:4] of the micro. The Digital Input Pin was ported to P0_7. These connections are already done for you in the provided example code, but here are some step by step instructions:
The following table shows which pins were used for each signal:
Jumper wires (included in the Pioneer Kit) are needed to connect the PSoC4 device to the on-board UART / USB bridge. The following connections will need to be made for each Pioneer Board while powered down:
On power up, the application is in the Transmit state. Since the XBee modules are configured in AT mode, any characters received on the local module's UART will be transmitted wirelessly to the remote node. The address of the remote node is hard-coded into the module when configured (using X-CTU software).
If characters don't appear in both terminals:
Below are some example screenshots of Transmit mode operation:
User Entered "HELLO"
Remote Module Received "HELLO"
When the XBee modules are configured in AT mode, predefined AT commands can be sent to the modules serially through the XBee UART port. First, the module must be placed in Command Mode by sending a predefined sequence of characters. Once the Command Mode Sequence is received, the XBee module is ready to receive any valid Read/Write commands received over UART. This tutorial demonstrates how to Read different configurations of the module. Specifically, this tutorial uses the "ATID", "ATSx", and "ATDx" commands to read the Network PAN ID, the module's Serial ID, and the module's Destination Address.
Type characters in the terminal and verify that characters are still received by the remote node.
"Read" Commands / Transmit "HELLO"
Remote Module Received "HELLO"
Refer to Chapter 10 of the XBee module user guide for a list of all supported commands. The example code currently does not support the "Node Discover" or "Destination Node" commands.
This tutorial demonstrates how to Write different configurations to the module. Specifically, this tutorial implements a 3-node network and uses the "ATDx" commands to change the Destination Address of the Coordinator from one Router to another Router. This demonstrates how the user would change the destination node using AT serial commands in a multi-node network.
Note: This tutorial requires that the user have Node 1 configured as an AT Coordinator and Nodes 2 and 3 configured as AT Routers. X-CTU software should be used to configure the modules. Also, the Destination Address of both Routers (Nodes 2 and 3) should be the Serial ID of the Coordinator and the Destination Address of the Coordinator (Node 1) should be the Serial ID of Node 2.
It is important to note that "Write" commands sent to XBee modules will only remain after reset if the "ATAC <enter>" command (Apply Changes) is issued, or if Command Mode is exited. For this example, even though the Application remains in Command Mode until SW2 is pressed, the program always forces the XBee module itself to exit Command Mode using the "ATCN <enter>" command. Because of this, any "Write" command sent to the XBee modules in this example will persist even after reset.
Refer to Chapter 10 of the XBee module user guide for a list of all supported commands and the parameter requirements. The example code currently does not support the "Node Discover" or "Destination Node" commands.
The provided example code can be used freely. However, it has not been tested with every AT command. Valid parametric entries are not extensively checked for within the application code and it is the user's responsibility to either add parametric validity checks or be sure to only enter valid parameters with "Write" commands. I hope this example project was useful to you. The goal of this project was not to provide a perfect XBee command program. The goal was to demonstrate how to properly interface an XBee module with a host microcontroller and how to setup basic communication in AT mode. Hopefully this program will help familiarize you with the XBee modules enough to implement them in your own embedded design. I encourage you to play around with the code and add some of your own functionality. Try different AT commands not mentioned in this demo. If you have any questions or interesting breakthroughs, I would love to hear about them. You can contact me at firstname.lastname@example.org. I hope you enjoy experimenting with XBee modules from Digi International!