Xbee-Xbee problem

Hi

I have a problem with communication between. I tried passing simple integers between two megas using xbee and it worked without any problem. Now when I try to implement it in my program I run into problems.
Here is the program which I am using,

void loop()
{
\\stuff
comm();
delay(10);
}
void comm()
{
  char *Data=NULL;
  int count=0;
    //Read the Serial2 data from the buffer
  while(Serial2.available()>0)
    {
      char inChar = Serial2.read();
      if(inChar == '<')
      {
        index=0;
        inData[index]='\0';
        started=true;
        ended=false;
      }
      else if(inChar == '>')
      {
        ended=true;
        break;
      }
      else
      {
        if(index < 49)
        {
          inData[index]=inChar;
          index++;
          inData[index]='\0';
        }
      }
    } //while(Serial2.available()>0)
 
  Serial2.print(started);Serial2.print("\t");Serial2.print(ended);Serial2.print("\n");
    //Process data received 
  if(started && ended)
    {
      Data =strtok(inData,",");
      if (atof(Data)==1){
        senddata();
    //Convert received data into floats and assign them to variables
        while(Data != NULL){
          vData[count]=atof(Data);
          Data=strtok(NULL,",");
          count++;
        }
      }
     //Reset booleans
      started = false;
      ended= false;
      index=0;
      inData[index]='\0';
    } //if(started && ended)
} //comm

void senddata()
{
  Serial2.print(2);Serial2.print(',');
  Serial2.print(PosX);Serial2.print(',');
  Serial2.print(PosY);
} //senddata

Now the problem is after the send the data from the first 1st Xbee, the receiver does not respond in anyway. I have included the print statement to see if the receiving operation has started & ended, I always receive 0 0 as the output.

In short there is no receiving happening. Can someone help me with this ? Is this because of the short delay in the loop after I call the comm() function. ?

Thanks for your help
ksp

There is so much information missing from your post that it is hard to know where to begin.

What kind of XBees are they? How are they configured? How are they connected to the Arduinos?

Your receive code expects data like <2, posX, posY>, but you are sending 2, posX, posY. I suppose that there is a reason for that, but your receiver code is ignoring everything, because it never sees the start marker (<).

Sorry I could not reply earlier, I was caught up in some other work

ThankYou Paul, I did not notice that I have missed ‘<’ and ‘>’

But still I have no luck in getting the thing working. I could get it to work if I have a large delay in the void loop as seen in the attached code.

void setup()
{
\\stuff
timer1.initialize(500000);
timer1.attachinterrupt(Control);
}
void loop()
{
\\stuff
comm();
delay(100);
}
void Control()
{
\\stuff using information from xbee
}


void comm()
{
  char *Data=NULL;
  int count=0;
    //Read the Serial2 data from the buffer
  while(Serial2.available()>0)
    {
      char inChar = Serial2.read();
      if(inChar == '<')
      {
        index=0;
        inData[index]='\0';
        started=true;
        ended=false;
      }
      else if(inChar == '>')
      {
        ended=true;
        break;
      }
      else
      {
        if(index < 49)
        {
          inData[index]=inChar;
          index++;
          inData[index]='\0';
        }
      }
    } //while(Serial2.available()>0)
 
  Serial2.print(started);Serial2.print("\t");Serial2.print(ended);Serial2.print("\n");
    //Process data received 
  if(started && ended)
    {
        senddata();
      Data =strtok(inData,",");
    //Convert received data into floats and assign them to variables
        while(Data != NULL){
          vData[count]=atof(Data);
          Data=strtok(NULL,",");
          count++;
        }
     //Reset booleans
      started = false;
      ended= false;
      index=0;
      inData[index]='\0';
    } //if(started && ended)
} //comm

void senddata()
{
  Serial2.print('<');
  Serial2.print(2);Serial2.print(',');
  Serial2.print(PosX);Serial2.print(',');
  Serial2.print(PosY);
  Serial2.print('>');
} //senddata

I am using Xbee Series 1, both are configured to a baudrate of 9600 and they are connected to arduino mega 2560 boards using an xbee shield from sparkfun.

I have a two layer controller, the outer loop runs at every 50ms (using timer1) and the inner loop at every 10ms. I need the information that i receive from the xbee when the outer loop is executed. The function loop() executes the inner layer. The sending and receiving occurs at the end of the void loop().

The first xbee sends data, and waits until it receives data from the second before it transmits again.

From the looks of it the very small delay that I had previously is causing problems, but I programmed it such that the data is not sent unless data is received except in the beginning when the first xbee sends data to initiate communication cycle. i.e., (1->2->1->2…)

I have no clue whats going on.

Serial2 does not appear to be set up in Setup().

I did not put the complete setup in there. Serial2.begin(9600) is in setup.

I was able to send and receive data if i used a delay > 100ms in the void loop().

ksp