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.