Read parameters of xbee

I'm trying to read parameters of xbee. The problem is I can not read parameters if the DIO7/CS pin of Xbee is disabled but if I activate pin DIO7, the arduino crashes.
The Xbee is in mode at.
the code is this:

byte data;
void setup()
  {
  Serial.begin(9600);
 }

void loop()
  {
  Serial.println(" \r\n read:");   
  Serial.print("+++");
  Serial.println("\r\nATID");  //  ID  
  while(Serial.available()==0){}
  while(Serial.available()>0){
  data=Serial.read();
  delay(5);       
  }    
   Serial.print(char(data));   
   Serial.println("\r\nATCN");   
  while(Serial.available()==0){}
  while(Serial.available()>0){
  data=Serial.read();
  delay(5);       
  }    
  Serial.print(char(data));
  delay(1000);
}

Any solutions?
Thanks,
Regards.

It appears that you are using the serial port to talk to the XBee and to the PC. That won't work when you are trying to communicate with the XBees in command mode.

  Serial.print("+++");
  Serial.println("\r\nATID");  //  ID

The +++ puts the XBee in command mode. ATID would then get information from it. \r\nAT is crap that the XBee won't understand.

The XBee, if it gets the right command, will reply with more than one byte of data. You are only saving the last character that it responds with.

Knowing something about the XBee would be useful. What type is it, and how have you configured it?

Knowing something about how the XBee is connected to the Arduino would be useful.

Knowing whether you are referring to pin 7 of the XBee or pin7 of the Arduino would be useful, too.

  while(Serial.available()==0) {  }
  while(Serial.available()>0)
   {
    data=Serial.read();
    delay(5);       
   }

This is not a good way of reading serial data. Try reading this:

Hello, thanks for reply. Pauls, the Xbee is Xbee ZB Pro S2B and the xbee is configurated how end device at. To connected the xbee with arduino I use the xbee shield and de pin7 is in the XBee, is pin 12 CTS / DIO7.
Nick, thanks for the link, I will read the information.
Thanks,
Regards.

To connected the xbee with arduino I use the xbee shield

You misspelled "one of the dozen or so".

PaulS:

To connected the xbee with arduino I use the xbee shield

You misspelled "one of the dozen or so".

Yes, it's kind of a shame too. Makes it hard to pick the right one and they take up shelf space where other shields could sit. They just add to the confusion. Another rant issue I have is that they cost way too much. With the competition, they should be cheaper. I feel kind of odd paying more for a shield than the module that fits in it. Just rantin' :wink:

afremont:

PaulS:

To connected the xbee with arduino I use the xbee shield

You misspelled "one of the dozen or so".

Yes, it's kind of a shame too. Makes it hard to pick the right one and they take up shelf space where other shields could sit. They just add to the confusion. Another rant issue I have is that they cost way too much. With the competition, they should be cheaper. I feel kind of odd paying more for a shield than the module that fits in it. Just rantin' :wink:

Good point. I prefer to use an adapter like Adafruit's on a breadboard, or if I really want to go bare bones, this one from Sparkfun which does nothing electrically, but adapts the module to fit the 0.1" breadboard spacing.