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
}