XBee PRO S1 always gets response with API MODEM_STATUS_RESPONSE instead of nothing

StackOverflow https://stackoverflow.com/questions/20839347

  •  22-09-2022
  •  | 
  •  

My wiring is this: XBee wiring

XBee is configured in API mode 1 and mbed (LPC1768) runs this code:

Serial terminal(USBTX, USBRX);

wait_ms(1000);

while(!terminal.readable()) {
  wait_ms(10);
}
terminal.getc();
mbed_led1 = 1;

while(1) {
  xbee.readPacketUntilAvailable();
  terminal.puts("Packet available\r\n");
  XBeeResponse response = xbee.getResponse();
  if (response.isAvailable()) {

    char tmp[20];
    int c = response.getApiId();
    sprintf(tmp, "%d", c);
    terminal.puts("Response available at API: ");
    terminal.puts(tmp);
    terminal.puts("\r\n");

    if (response.getApiId() == RX_16_RESPONSE) {
      Rx16Response rx16 = Rx16Response();
      response.getRx16Response(rx16);

      uint8_t len = rx16.getDataLength();
      char l[20];
      sprintf(l, "%d", len);

      terminal.puts("We have data: ");
      terminal.puts(l);
      terminal.puts("\r\n");
    }
  }
  wait(1);
}

XBee library for mbed is essentially a port of a widely popular Arduino XBee library. Sources are here: http://mbed.org/users/okini3939/code/XBee/

And when aforementioned code runs, my output is this:

Terminal ready
Packet available
Response available at API: 138
Packet available
Response available at API: 138
...

138 is a decimal representation of a hex 0x8A, which in turn is mapped to MODEM_STATUS_RESPONSE.

This XBee module is the only one that is powered.

And my question is why would I have that weird behaviour? How come this XBee have successfully read packet at all?

有帮助吗?

解决方案

The XBee module sends the Modem Status frame to the host, and it's not the result of the module receiving a packet. Try dumping the rest of the Modem Status frame to see what status the XBee module is trying to report. It might be reporting Hardware Reset (0x00), followed by Coordinator Started (0x06).

The XBee Series 1 documentation includes a list of all possible Modem Status values.

BTW, updating the sprintf(tmp, "%d", c); to use "0x%02X" as the format string will print the frame type in hex and make it easier to look up frame types in the documentation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top