new to XBee question about entering command mode

Hi,

I am trying to establish the communication between two PICs using Xbee. The PIC i am uisng is PIC18F4525.

I am new to Xbee. I have problem even getting the Xbee to enter command mode. Below is my codes. I wait for 1 second (tried 2 seconds as well, didnt work), send “+++”, wait for 1 second, but didnt get the response “OK” from Xbee. Instead, the Xbee at the other end receive the data “+++”. Would you please help me to take a look my code? I have been stuck in this problem for a few days :oops: . Thx~~

#include <p18f4525.h>

#include <delays.h>

#include <stdlib.h>

#include <stdio.h>

#include <usart.h>

#pragma config WDT = OFF

#pragma config OSC = INTIO67

void usartInit(void);

void sendcmd();

int setup();

void main()

{

char dollar = ‘a’;

OSCCON = 0x62; //4MHZ

RCSTA = 0x90;

TRISCbits.TRISC7 = 1; //pin C7 input, Rx

TRISCbits.TRISC6 = 0; //pin C6 ouput, Tx

usartInit();

putcUSART(b); //b=‘X’

if (setup()==1)

{

putrsUSART(“good”); //i have never got the “good” printed out.

}

dollar = getcUSART();

while(dollar != ‘O’)

{

if (RCSTAbits.OERR)

{

RCSTAbits.CREN=0;

RCSTAbits.CREN=1;

}

Delay10KTCYx(110);

putrsUSART(“+++”);

Delay10KTCYx(110);

}

while(1)

{

putrsUSART(“abc”);

}

dollar=getcUSART(); //ie: GPGGA,

if(dollar == ‘K’)

{

while(1)

{

putrsUSART(“efg”);

}

}

}

void sendcmd()

{

Delay10KTCYx(220);

putrsUSART(“+++”);

Delay10KTCYx(220);

}

int waitforresp()

{

int result = 0;

int timer = 100000;

for(;timer>0; timer–)

{

if(!DataRdyUSART())

{

Delay10KTCYx(100);

}

else

{

result = 1;

break;

}

}

return result;

}

int setup()

{

int result = 0;

sendcmd();

if(waitforresp()!=1)

{

setup();

}

else

{

result = 1;

return result;

}

}

void usartInit(void) {

// configure USART

OpenUSART( USART_TX_INT_OFF &

USART_RX_INT_OFF &

USART_ASYNCH_MODE &

USART_EIGHT_BIT &

USART_CONT_RX &

// USART_BRGH_LOW,

USART_BRGH_HIGH,

25); //9600bps

}

A quick guess based on what I’ve seen of other AT command interfaces is that you’re sending the +++ in one string which is too rapid succession. I’ve seen LANtronix devices, for example, which ignored my +++ when I sent it as a string, but if I sent each + individually with a small time delay between each, it worked fine. By small time delay I mean - many AT interfaces expect a human to be typing at it, so maybe try .5s between + transmissions.

Also make sure putrsUSART isn’t adding another character like a \r or \n on the end of a string it sends. That would also cause it to be ignored as a command mode sequence.

XBee’s are a lot more forgiving re: timing to break in with +++ than LANtronix AT interfaces, I’ve found.

Hope that helps.

Thanks, landon. I modified the function sendcmd(), and I got the “OK” response finally… :smiley: . Thx~~ :stuck_out_tongue:

void sendcmd()

{

char plus = ‘+’;

Delay10KTCYx(240);

//putrsUSART(“+++”);

putcUSART(plus);

Delay10KTCYx(50);

putcUSART(plus);

Delay10KTCYx(50);

putcUSART(plus);

Delay10KTCYx(240);

}