Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 3 months ago.
IS command from FRDM-coordinator to remote xbee
Hi guys, I have got a problem getting a responce from my remote xbee router module. I just get a responce of zeros on my terminal 00 00 00 00 00 00.....I am supposed to get an actual responce with information about the state of my xbee.I use the devices below: xbee coordinator API= (SH = 0013A200) , (SL=409209EF),(MY=0) remote Xbee Router AT = (SH 0013A200) , (SL=408AD9B3),(MY=9D34)
I also attach you my code in case you can see something wrong which i cannot see myselfThank you in advance for your time.
#include "mbed.h"
//Input-output and serial I/O definitions
Serial pc(USBTX, USBRX); // tx, rx
Serial xbee(PTD3, PTD2); // tx, rx
DigitalOut LedPin(LED1);
// Define API "IS" command-packet array here
int packetIS[] = {0x7E,0x00,0x0F,0x17,0x01,0x00,0x13,0xA2,0x00,0x40,0x8A,0xD9,0xB3,0x9D,0x34,0x02,'I','S'}; //0x17 = FRAME TYPE-remote command request,AT Command immediate.0x01 = FRAME ID,identifies the UART data frame for the host to correlate with a subsequent acknowledgement(If set to 0->no responce.0x49(I)/0x53(S) = AT Command=(2 ASCII characters=I,S).
int packetISlength = 18; //array for setting up 8 bytes for the API ND command
const int dataISlength = 40; //define the number of bytes in array dataND[] for XBee modules
//Define extra variables
unsigned int bytecount_hi;
unsigned int bytecount_lo;
unsigned int bytecount;
unsigned int counter;
unsigned int chksum;
unsigned int calculated_sum = 0; //calculated checksum
int dataIS[dataISlength]; //array which stores the data received from the xbee
int inputdata;
int SerialInput() // This function reads UART after it has new data
{
while (xbee.readable() == 0) //wait for UART to have new data
{
}
return (xbee.getc()); //get new data, return
}
//Main XBee program.This program asks a remote xbee module to reply with information about the state of it's digital and anlog pins
int main(void)
{
LedPin = 1; //turn test LED off to start
//Transmit packetIS as requested using for and not while
counter = 0;
for (counter = 0; counter < packetISlength; counter++)
{
xbee.putc(packetIS[counter]); // send the API packet
if (counter > 2) //we calculate the sum after the length bytes
{
calculated_sum = calculated_sum + packetIS[counter]; // calculate the sum
}
}
chksum = 0xFF- (calculated_sum & 0xFF);
xbee.putc(chksum) ; //calculate the proper checksum & send it to the xbee
pc.printf("The checksum of the IS command is: %x",chksum);
pc.printf("\n\r");
wait(1);
calculated_sum = 0;
chksum=0; //clear the checksum value
//The below program gets serial data sent by the XBee module and saves the data in an array of bytes for each module.
inputdata = SerialInput();
if (xbee.readable())
{
if (inputdata == 0x7E) //start byte of API frame
{
bytecount_hi = SerialInput();
bytecount_lo = SerialInput();
bytecount = (bytecount_hi * 256) + bytecount_lo; //number of bytes in message
for (counter = 0; counter < bytecount; counter++) //put XBee data received in array
{
dataIS[counter] = SerialInput();
if (counter > 2)
{
calculated_sum = calculated_sum + dataIS[counter];
}
}
chksum = SerialInput();
} //get checksum--last byte
if (chksum != (0xFF - (calculated_sum & 0xFF))) //do checksums match in case something went wrong
{
while(1) //NO MATCH, flash LED forever
{ //Error handling could go
LedPin = 0; //here instead.
wait(1);
LedPin = 1;
wait(0.5);
}
}
} //IF Checksums match, it proceeds for the next module
//OK, got data for all XBee modules
LedPin = 0; //turn on LED
wait(0.5); //half-second delay
//print data in each XBee array as hex characters.Data shows up to the PC terminal
pc.printf("\n\r");
for (counter = 0; counter < dataISlength; counter++)
{
pc.printf("%02X ", dataIS[counter]); //show up the information received from the remote xbee on our terminal
}
pc.printf("\n\r"); //start a new line in the pc terminal window
while(1) //end program in an infinite do-nothing
{ //loop????
}
}