User manual
LPCXpresso Experiment Kit - User’s Guide
Page 116
Copyright 2013 © Embedded Artists AB
//Set LED1 pin as output
...
//Set SW2 button pin as inputs
...
//Use systick to get an interrupt every 10ms
SysTick_Config(SystemCoreClock / 100);
#if (CFG_ACT_AS_COORDINATOR == 1)
printf("XBee demo - COORDINATOR\r\n");
err = xbee_init(XBEE_COORDINATOR, &callbacks);
#else
printf("XBee demo - NODE\r\n");
err = xbee_init(XBEE_END_DEVICE, &callbacks);
#endif
if (err != ERR_OK) {
printf("Failed to initialize Xbee. Error code %d. Aborting...\n", err);
while (1) {
// wait forever
}
}
while (1) {
xbee_task();
if (devIsReady != 0) {
// check button state
state = GPIOGetValue(SW2_PORT, SW2_PIN);
if (oldState != state) {
oldState = state;
printf("Button: %u\r\n", state);
sendSetLedRequest(state);
}
}
}
return 0;
}
The XBee driver is provided four callbacks during initialization. The callbacks will be called when the
driver has completed initialization of the XBee module (xbeeUp), when a new node is discovered
(xbeeNode), a transfer is completed (xbeeTxStatus) and when data is received (xbeeData). The
driver’s xbee_task() function must be repeatedly called in order for the Xbee module to work correctly.
The CFG_ACT_AS_COORDINATOR define should be set to 1 for the controller and 0 for the nodes.
Look at the implementation of the xbee_init() function to see how they are treated differently.
The last thing to note about the program is the RFPT_SET_LED command that is sent when a button
is pressed. The command is received by another node and is processed in the xbeeData() function.
Run the program on both boards and note that pressing the SW2 button on one board lights the LED
on the other board.
Suggested improvements:
Extend the protocol to retrieve the temperature reading from the other board
Use one board’s quadrature encoder to control the other board’s 7-segment display
Read analog values remotely