I'm trying to connect two xbee's pro s2 and make them communicate with each other in API Mode (further, I will use more end and router devices). Basically, I have a xbee coordinator plugged on my PC through digi adapter and I have other xbee connected to a PIC18f25. Right now I'm working on send and receive data from one to another and vice versa. When I connect both on the usb adapter, the communication works just fine (I can send and receive data from/to both devices). However, when I try to work with the previous configuration, I find it impossible to get the data, which is sent from the coordinator, from the end device with the PIC. Here goes the data that I'm trying to send:
From Coord 2 EndD - 7E 00 13 10 01 00 13 A2 00 40 8D 5A 8B FF FE 00 00 48 65 6C 6C 6F 96
From EndD 2 Coord - 7E 00 13 10 01 00 00 00 00 00 00 00 00 FF FE 00 00 48 65 6C 6C 6F FD
I think it's usable to say that when I try to send the data from the PIC, through end device, to coordinator, it works. I wonder if the problem relies on my code, which can be found below:
#include <18F25K20.h>
#device adc =10
#device ICD=TRUE
#FUSES noWDT // Watch Dog Timer
#fuses LP //low power crystal
#FUSES XT //Crystal osc <= 4mhz
#fuses BROWNOUT_SW //Brownout enabled during operation, disabled during SLEEP
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //brownout reset
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOPUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES noDEBUG //No Debug mode for ICD
#FUSES noLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES noIESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled*/
#use delay(clock = 4000000) /* Clock definition */
#use rs232(BAUD = 9600, XMIT = PIN_C6, RCV = PIN_C7) /* ZigBee and PIC Communication */
int16 var;
byte var2=0x00;
long timeout;
void main() {
output_low(PIN_C5); // Turning on Xbee
delay_ms(10);
while(1) {
delay_ms(100);
output_high(PIN_C0); // TESTE
delay_ms(100);
output_low(PIN_C0);
timeout=0;
while(!kbhit()&&(++timeout<5000)) delay_us(5);
if(kbhit()){
output_high(PIN_C0);
delay_ms(10);
output_low(PIN_C0);
delay_ms(10);
output_high(PIN_C0);
delay_ms(10);
output_low(PIN_C0);
delay_ms(10);
output_high(PIN_C0);
delay_ms(10);
output_low(PIN_C0);
var2 = getc();
delay_ms(1000);
}
/* Data which is succesfully sent to coordinator
putc(0x7E);
putc(0x00);
putc(0x13);
putc(0x10);
putc(0x01);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0xFF);
putc(0xFE);
putc(0x00);
putc(0x00);
putc(0x48);
putc(0x65);
putc(0x6C);
putc(0x6C);
putc(0x6F);
putc(0xFD);*/
}
}
The program is supposed to blink a LED (PIN_C0) with 100 ms, and blink it faster if any data enter in the PIC. However it doesn't work as I planned and I have no clue why.
Any help will be appreciated.
Thank you all in advance,
Regards.
You know that a lot of pieces are working at this point. If the PIC is sending frames to the XBee module that the coordinator receives, then:
RESET
line of the XBee module is asserted correctly.Is it possible that you have hardware handshaking enabled (ATD6=1
) on the XBee module, so it's failing to send to the PIC due to it not asserting RTS?
Can you connect a standard serial cable to the PIC (instead of the XBee), and confirm that data sent in from a terminal program triggers your flashing, and that the terminal program sees the sent frame?
Can you use an XBee interface that flashes LEDs on Tx and Rx so you can visually see if data is coming through?