This project demonstrates how easy it is to communicate with an XBee module on LPC1343 and Embedded Artists LPCXpresso Base board to an XBee module on an XBee explorer attached to the PC.

To connect the UART on the LPCXpresso Base Board to the XBee module interface, we need to insert two jumpers as illustrated in the figure 2 below.

In this small demo we wanted to create a test-setup where we communicate with another XBee module connected to a PC. The joystick on the LPCXpresso Base Board controls the mouse pointer on the PC by sending commands that indicates mouse movements.
To modify or read the XBee module parameters, it needs to be in Command Mode. When it's in Command Mode the XBee module interprets all incoming data as commands. To communicate with the XBee, AT commands can be used. To activate the XBee module to Command Mode, send "+++" through the UART. Then it's possible to send AT-commands such as "ATVL" to retrieve firmware version, and so on. To exit Command Mode, send "ATCN" to the XBee module. The XBee module then returns to Idle Mode. If we start sending data through the UART the XBee module shifts to Transmit Mode, and same if we receive data the XBee module is shift to Receive Mode. All AT commands that can be used and more information about the XBee module are stated in the XBee manual.
This is how main() could look like. In main() we need to install the GPIO interrupt handler, initiate timers if we want to use delays. We also need to initialize SSP port routine and setup the UART to 9600 baud rate. We want to use the joystick, so we need to initialize this as well and finally we initialize and clear the OLED screen because we want to show some information on the OLED screen
int main(void) {
uint8_t buf[10];
uint32_t len = 0;
uint32_t time = 0;
GPIOInit();
init_timer32(0, 10);
UARTInit(9600);
SSPInit();
joystick_init();
oled_init();
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1, 1, (uint8_t*) "Contacting XBee",
OLED_COLOR_BLACK,OLED_COLOR_WHITE);
//set XBee in command mode
UARTSendString((uint8_t*) "+++");
delay32Ms(0, 1100);
// Set the PAN (personal area network) ID number, Range 0 - 0xFFFF,
// comma at the end of the command indicates that another
// command will follow
UARTSendString((uint8_t*) "ATID4565,");
// Set Destination High to 0x0s
UARTSendString((uint8_t*) "DH0,");
// Set Destination Low to 0x1
// This example use 0x0 to send and 0x1 to receive
UARTSendString((uint8_t*) "DL1");
// Exit command mode
UARTSendString((uint8_t*) "CN");
// Wait for response, OK
while (1) {
len = UARTReceive(&buf[0], 3, FALSE);
if (buf[0] == 'O' && buf[1] == 'K') {
buf[len] = '\0';
break;
}
delay32Ms(0, 1);
time++;
if (time > 3000)
break;
}
if (time > 3000) {
oled_putString(10, 10, (uint8_t*) "Error!", OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
oled_putString(10, 20, &buf[0], OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
} else {
oled_putString(1, 10, (uint8_t*) "Success!",
OLED_COLOR_BLACK, OLED_COLOR_WHITE);
oled_putString(1, 20, (uint8_t*) "Move joystick!",
OLED_COLOR_BLACK, OLED_COLOR_WHITE);
delay32Ms(0, 100);
while (1) {
uint8_t joyState = joystick_read();
if ((joyState & JOYSTICK_CENTER) != 0) {
UARTSendString((uint8_t*) "EAC\n");
} else if ((joyState & JOYSTICK_DOWN) != 0) {
UARTSendString((uint8_t*) "EAD\n");
} else if ((joyState & JOYSTICK_UP) != 0) {
UARTSendString((uint8_t*) "EAU\n");
} else if ((joyState & JOYSTICK_LEFT) != 0) {
UARTSendString((uint8_t*) "EAL\n");
} else if ((joyState & JOYSTICK_RIGHT) != 0) {
UARTSendString((uint8_t*) "EAR\n");
}
delay32Ms(0, 100);
}
}
while (1);
}
To setup the XBee module we set PAN (Personal Area Network) id to 4645. Only modules with matching PAN IDs can communicate with each other. Then we need to set High and Low Destination, we use 0x0 to send and 0x1 to receive. After that we exit command mode and wait for "OK" response. If the setup was a success we start to send information of joystick movements through the XBee module.
We have also made a simple program in Java, XBeeApp.jar, which connects to the XBee explorer USB. The Java program listens for commands sent from the LPCXpresso Base Board and runs on the PC. It has the same PAN id 4645 as the demo running on the LPCXpresso Base Board. When the joystick is moved or pressed on the LPCXpresso Base Board, the mouse pointer on the PC is also moved or pressed. To run XBeeApp.jar just simple execute "java -jar XBeeApp.jar COMX" in the commando-prompt. Default com port is COM1 if no arguments are used.

Begin by importing the driver and sample application bundle (zip file) for the LPC1343 LPCXpresso Board found at the Embedded Artists support site.
The second step is to import the XBee module project. Do the same as when importing the drivers, but choose xbee_1_example.zip in step 2. To build or debug the example just click build/debug in the QuickStart tab
More information on how to work with the LPCXpresso Base Board as well as the LPCXpresso IDE can be found in the User's Manual for the LPCXpresso Base Board. This User's Manual can be found at the Embedded Artists support site.

