7 years, 1 month ago.

Using the XBEE with mbed

I am attempting a simple two-xbee, two-mbed system where I send a byte from one mbed via a connected xbee to a second xbee connected to a second mbed. The xbees are the S1 type. I modified Vlad Cazan's code (from the xbee section of the cookbook) slightly as shown below and placed this code on both mbed's. The xbees were placed on a Sparkfun USB explorer board and connected as described in the Cookbook example. I first tested the code by connecting physical wires between the two mbed's and all worked as expected. The "success" is simply that the two LEDs flash as expected on both mbeds upon sending and receiving a byte.

I cant seem to get this to work with the xbees in the loop. I see no evidence that the bytes are being transmitted. I have set up the S1 xbee devices using Digi's XCTU utility: ID=2332, MY=1/2, DL=2/1 and confirmed the settings by communicating successfully between the xbees using the XCTU terminal utility without the mbeds.

Any ideas would be appreciated.

include "mbed.h"
Serial xbee(p9, p10); //Creates a variable for serial comunication through pin 9 and 10
DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset
DigitalOut myled1(LED3);//Create variable for Led 3 on the mbed
DigitalOut myled2(LED4);//Create variable for Led 4 on the mbed

void ReceiveXbee()  {
    unsigned char c = xbee.getc();
    myled1 = !myled1;
}

int main() {
    xbee.attach(&ReceiveXbee);
    xbee.baud(9600);

    rst1 = 0; //Set reset pin to 0
    myled1 = 0;//Set LED3 to 0
    myled2= 0;//Set LED4 to 0
    wait_ms(1);//Wait at least one millisecond
    rst1 = 1;//Set reset pin to 1
    wait_ms(1);//Wait another millisecond

    while (1) {
        wait(0.50);
        xbee.putc(0x55);
        wait(0.50);
        xbee.putc(0xAA);
        myled2 = !myled2;
    }
}
Be the first to answer this question.