XBee RS-232 adapter

Product description

The XBee RS-232 Adapter provides short range wireless connectivity to any RS-232 serial device.

Note that this Wiki page documents the packaged box product, and not the RS-232 development bare board! It also covers operation when powered full-time, not when batteries are used and the product sleeps.

Assuming the serial end device is a traditional 'slave/server' which answers remote polls and is unaware of the mesh, then load the standard "AT" firmware and not the API firmware. Then use a Digi ConnectPort X gateway or another XBee module with the API firmware loaded to act as the 'master/client' and issue requests directly to end devices via MAC address, and the 'slave/server' XBee will always return responses to the MAC address of the 'master/client'.

Programming options

There are many options to consider when making wireless programmatic access to an XBee network of devices or device adapters. In broad terms, one may write a program which runs on a PC to interact with a network or one may use a gateway device, such a ConnectPort X [2] gateway.

When using a PC, one may consider using the simplistic and easy "AT-Command" mode for the XBee attached to the computer. Although using this mode is straight-forward it does not offer one as fine of control as when using the "API mode" firmware option.

One may also consider using a Digi ConnectPort X family of gateway device to provide additional intelligence and flexibility when connecting to a network of wireless devices. The ConnectPort X offers users the ability to choose to write their own applications from the ground-up, using Digi's and Python's[4] reference and example information, or to use the highly extensible DIA Application to collect and aggregate information.

XBee Module Support

All Xbee modules should work in the RS-232 adapter, and they would use the standard AT or API versions. There are not (at this time) any special builds for this adapter. However, XCTU cannot reflash firmware in this RS-232 module - you will need to move the XBee module to a USB or RS-232 development board to reflash firmware.

Module Description Tested Comments Output Defaults
XB24-A 802.15.4 on 2.4Ghz Yes No access to DTR or DSR DTR and RTS asserted/high
XB24-B ZNet 2.5 on 2.4Ghz Yes No access to DSR DTR and RTS disabled/low
XB24-ZB Zigbee 2007 on 2.4Ghz Yes No access to DSR DTR and RTS disabled/low
XB09-DM DigiMesh on 900Mhz Pending No access to DSR DTR is disabled/low, RTS asserted/high
XB24-DM DigiMesh on 2.4Ghz Pending No access to DTR or DSR  
XB08-DP Point-to-Multipoint on 868Mhz Pending   DTR is disabled/low, RTS asserted/high

Configuration to consider

These values can be set from XCTU - or use the CLI or Web UI of a Digi ConnectPort X gateway:

Note DSR cannot be read; there is no configuration required for it.

Pinouts

The RS-232 connector is an industry-standard DB9 male connector with a DTE configuration, similar to a PC serial port. However, there are limitations in the support for DTR/DSR. Pinouts for the connector are:

Pin Function Direction Module Pin DIO to rd/wr AT Command Mask in IS Response to Raise/Assert to Drop/Disable
1 CD Input 17 DIO3 D3 0x0008    
2 RXD Input 3          
3 TXD Output 2          
4 DTR Output 4 DIO12 P2 (See Note) 0x1000 'P2\x04' 'P2\x05'
5 GND ---            
6 DSR Input 9 DI8 Not Readable Not Readable    
7 RTS Output 12 DIO7 D7 0x0080 'D7\x04' 'D7\x05'
8 CTS Input 16 DIO6 D6 0x0040    
9 RI Input 19 DIO1 D1 0x0002    
9-alt 12vdc Switched Power Output 18 DIO2 D2 (See Note) 0x0004 'D2\x05' 'D2\x04'

Note on Pin 4/DTR. Some XBee modules do not offer access to raise or lower DTR; the "P2" command is not available.

Note on Pin 6/DSR. None of the XBee module allow reading the level of DSR via the "IS" command.

Note on Pin 9. By default it is an input, however setting DIO2 high turns the 12vdc 50mA switched power output on and reading RI/DIO1 returns TRUE if power is on. Setting DIO2 low sets the switched power to tri-state, thus reading RI/DIO1 returns the RI-like status of pin 9. So do not connect RI to any device which might be damaged by a +12vdc signal - while it will not damage any true EIA/RS-232 compliant device, it can't be good for any device attempting to drive RI low.

Powering 'green' or 'port-powered' RS-232 devices

Some external devices (such as RFID readers or short-haul modems) attempt to draw power from the RS-232 driver circuit. The voltage output from the XBee 232 Adapter may be too low to power such external devices.

However, cross-wiring the RS-232 cable so that the 12vdc Aux-Power (pin 9) from the XBee 232 Adapter connects to the external DTE DSR input (pin 6 of DB9) or the DCE DTR input (pin 4 of DB9) provide a solid solution. A +12vdc signal is well within the RS-232 voltage signal specification, plus the approximately 12vdc 50mA supplied is more power than the 'Port Powered' device expects to tap.

Python programming examples

Polls or Requests sent to field devices: The 'master/client' XBee module should send serial data via addressed unicast with one of the API Transmit Request frames, such as 0x00, 0x01 and 0x10.

Responses or unsolicited data from field devices: If the dest_addr (DH/DL) registers have been set properly, then any serial data received from the field devices will be forwarded to the central 'master/client' XBee module. API Receive Packet frames will be received by the 'master/client' XBee module.

Driving RS-232 control signals

DTR/RTS signals are raised or lowered by sending a 3-byte command with the API Remote AT (command 0x17) - the examples below are coded as Python expects:

Note that these commands affect the pin within one second, yet do not save the state in FLASH. Thus a reboot of the XBee adapter puts the DTR or RTS signal back into the configured default; the factory default is low/not asserted. If it is desired to have DTR or RTS asserted upon power-up, manually set the DIO12/DIO7 parameters to 4.

Why does output DO = Low assert the RS-232 signal and DO = High drop the RS-232 signal? This is how historically TTL communications systems worked. A 5v line was assumed idle, thus pulled weakly up to 5v and representing OFF or binary zero (0). A 0v line was being actively shunted to ground by a powered transistor, thus represented ON or binary one (1). Even today, most RS-232/485 chips assume 0v = 1/on and 5v = 0/off.

Reading RS-232 control signals

To read the signal status, issue the 'IS' command. You must DELAY at least one (1) second after issuing any of the D2/D7/P2 commands before issuing the 'IS' command or the output status won't be correctly returned in the response. The IS command returns 6 bytes by direct API, and 5 bytes with ddo_get_param() method, so the last 5 bytes can be decoded as:

The RS-232 signals show as inverted for historical reasons, so a '0' means the signal is HIGH/ASSERTED and '1' means LOW/DROPPED

However, the Auxiliary Power Output (pin 9) shows up per digital logic levels. Therefore, a '0' means power is off and '1' means power is on. The Auxiliary Power Output can drive 12vdc at 50mA if the XBee RS-232 adapter is direct DC powered. If battery powered, driving Auxiliary Power Output more than a second will quickly drain your batteries!

Example Python to detect CTS status

def show_CTS_status( digital_mask, digital_data):
    """
    Decode and display the CTS info from 'IS' response words
    Return True if asserted, else False
    """
    if( digital_mask & 0x0040):
        print 'CTS input configured, value = ',
        if (digital_data & 0x0040):
            print 'Low/Dropped'
            return False
        else:
            print 'High/Asserted'
            return True
    else:
        print 'CTS input ignored (not configured)'
    return False