PIC interface to XBee - why will this not work?!

I am trying to get a working module going; said module consists almost entirely of a dsPIC30f2011 and an XBee standard. For some reason, the XBee seems to not be responding. The location of the forum may not be much accurate, as my problems are not related to the XBees communicating, but the XBee not responding to the dsPIC that it’s directly wired to. Here is the relevant code:

#include <p30f2011.h>


_FOSC(CSW_FSCM_OFF & FRC_PLL16);
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & MCLR_DIS);

#define MAXNODES 30

#define pin_lights _RD0
#define pin_test _RB0

long long Nodes[MAXNODES];
char field = 'A';

void PicSetup();
void XBeeSetup();
int FindNodes();
int SendField();
void Respond();
void Lights(int onnotoff);
void SendChar(char c);
char GetChar();
void Wait(int ms);

int main()
{
    int i;

    PicSetup();
    U1MODEbits.UARTEN = 1; // Enable UART
    U1STAbits.UTXEN = 1; // Enable transmission
	XBeeSetup();

    while (1)
	{
		pin_test = 1;
        if (FindNodes())
            Lights(SendField());
		pin_test = 0;
    	for (i = 0; i < 1000; i++)
        	if (!U1STAbits.URXDA)
            	Respond();
	}
}

void PicSetup()
{
    ADPCFG = 0xFFFF; // All pins digital
    CNEN1 = 0x0000;
    IEC0 = 0x0000;
    IEC1 = 0x0000;
    IEC2 = 0x0000;
    IPC0 = 0x0000;
    IPC1 = 0x0000;
    IPC2 = 0x0000;
    IPC3 = 0x0000;
    IPC4 = 0x0000;
    IPC5 = 0x0000;
    IPC10 = 0x0000;

    TRISDbits.TRISD0 = 0;
    TRISBbits.TRISB0 = 0;

    //-----------------------------------------------------------------------------
    // INIT UART CONTROL REGISTERS

    U1MODE = 0x0000;
    U1STA = 0x8110;
    U1TXREG = 0x0000;
    U1BRG = 191;
    
    T2CON = 0x0000;

}

void XBeeSetup()
{
    int i;
	Wait(1000);
    for (i = 0; i < 3; i++) SendChar('+');
	Wait(1000);
    SendChar('A');
    SendChar('T');
    SendChar('A');
    SendChar('P');
	SendChar(' ');
	SendChar('1');
    SendChar('\r');
	Wait(1000);
}

int FindNodes()
{     // Returns 1 for success, 0 for failure
    int i, check, reclength;
    int MY;
    long long S;
    char DB;
    char NI[21];

while(1){
pin_test = 0;
    SendChar((char)0x7E); // Packet start
    SendChar((char)0x00); // Packet length
    SendChar((char)0x04);
    SendChar((char)0x08); // API identifier
    SendChar('1'); // Arbitrarily chosen Frame ID
    SendChar('N'); // Node Discover command
    SendChar('D');
    check = (0x08)+'1'+'N'+'D';
    SendChar((char)0xBF);
pin_test = 1;
}
//*Irrelevant blah blah blah - code above this should just loop
}

int SendField()
{  //Whatever
}

void Respond()
{
//also unnecessary for this question
}

void Lights(int onnotoff)
{
// More superfluousness
}

void SendChar(char c)
{
   	while (!U1STAbits.TRMT);
	U1TXREG = c;
}

char GetChar()
{
    while (!U1STAbits.URXDA);
    return U1RXREG;
}

void Wait(int ms)
{
	int i;
	T2CONbits.TON = 1;
	for (i = 0; i < ms; i++)
	{
		TMR2 = 0;
		while (TMR2 < 30000);
	}
	T2CONbits.TON = 0;
}

As of right now, the code should infinitely loop in FindNodes, and infinitely ask to find local nodes. The code loops properly, and (appears to) send the FindNodes command properly. However, the XBee responds in no way whatsoever - it should at least return a message saying it never found anything. Provided the circuit is connected properly, and the XBee has the proper firmware, what have I overlooked? Thank you.

i think the xBee modules have to be set up to have the same PAN ID beforehand. xBee nodes will only find each other if they’re on the same pan id, i believe. which series/firmware are you using?

I’ll have to check, but shouldn’t Node Discover at least return an error message? I’m not even getting the OK signal from the XBee when I use +++. Nothing is getting sent to the dsPIC at all.

Antiporcupine:
I’m not even getting the OK signal from the XBee when I use +++. Nothing is getting sent to the dsPIC at all.

Are you sure your UART is working?

get an RS232 level shifter PCB. Test the XBee with a PC and XCTU. Then experiment with a micro.

Be aware of the fundamental difference between series 1 and series 2.

felis:
Are you sure your UART is working?

Yes. I've been probing the input and output UART pins, not looking at what the dsPIC reads. The PIC output/XBee input is sending normal values (0V and 5V) while the PIC input/XBee output is mostly flatline. For some reason, the latter does have tiny exponential bumps corresponding to the PIC output, but they're negligible.

stevech:
get an RS232 level shifter PCB. Test the XBee with a PC and XCTU. Then experiment with a micro.

Be aware of the fundamental difference between series 1 and series 2.

The XBee seems to work fine on X-CTU; at the very least, it's responding to my commands, more than I'm getting with the dsPICs. I wasn't aware about the level shifter, I may have to examine that. What exactly is this fundamental difference? I was not even aware there was one, I assumed the difference was firmware.

Antiporcupine:

felis:
Are you sure your UART is working?

Yes. I've been probing the input and output UART pins, not looking at what the dsPIC reads. The PIC output/XBee input is sending normal values (0V and 5V) while the PIC input/XBee output is mostly flatline.

It doesn’t mean much. Not only levels but also timings have to be right in order for Xbee to understand what you are sending to it. For testing, switch Xbee to command mode by sending three pluses and receive OK\r back. Make it work in X-CTU terminal first. Then make it work in your code. After that you can say that your UART is working.

Look at my site, there are several articles about communicating PICs to Xbees, one of them talks about AT mode. There are C code samples also.