Module support Writing custom firmware
XBee/XBee-PRO ZigBee RF Modules User Guide 179
GPIO_CFG = x;
Example 2
The following code enables GPIO 0, 1, 2, 3, and 12 and maintains all other GPIO_CFG bits.
int16u x;
x = GPIO_CFG;
x &= (0xFF0F); // Clear bits 4 - 7
x |= 0x0070;// Set bits 4 - 7 to 0111 as shown in the table above.
GPIO_CFG = x;
Detecting XBee versus XBee-PRO
For some applications, it may be necessary to determine if the code is running on an XBee or an XBee-PRO device.
The GPIO1 pin on the EM250 is used to identify the module type; see Pin signals on page 16. GPIO1 is connected to
ground on the XBee module. The following code could be used to determine if a module is an XBee or XBee-PRO:
GPIO_DIRCLRL = GPIO(1);// Set GPIO1 as an input
GPIO_PUL |= GPIO(1);// Enable GPIO1 pullup resistor
ModuleIsXBeePro = (GPIO_INL & GPIO(1));//ModuleIsXBeePro > 0 if XBee-PRO, =0 if non-PRO.
Ensuring optimal output power
XBee modules manufactured before February 2008 had an incorrect configuration setting that caused the default
output power mode to be set incorrectly. Digi's ZB and ZNet firmware compensate for this by setting the output
power mode in the application firmware.
Custom applications should call the emberSetTxPowerMode() function to set the output power mode as shown
below:
XBee applications
emberSetTxPowerMode(EMBER_TX_POWER_MODE_DEFAULT); or
emberSetTxPowerMode(EMBER_TX_POWER_MODE_BOOST);
XBee-PRO applications:
emberSetTxPowerMode(EMBER_TX_POWER_MODE_ALTERNATE); or
emberSetTxPowerMode(EMBER_TX_POWER_MODE_BOOST_AND_ALTERNATE);
XBee-PRO modules must also set a couple of IO lines to enable output power compensation. This is shown below.
Once the IO lines are initialized (after powerup), the XBee will enable the power amplifier and LNA as needed.
On powerup:
/* GPIO 2 should be set low for at least 10 milliseconds when coming up from power cycle. */
GPIO_DIRSETL = GPIO(2);// Set GPIO 2 as an output
GPIO_CLRL = GPIO(2);// Drive GPIO 2 low
/* After at least 10ms, GPIO 2 should be set high to power the output power compensation circuitry.
At the same time GPIO 1 should be configured as an output and set low to enable the output power
compensation circuitry. */