Good morning,
I’m working with two Xbee modules (Serie1), with a point to point configuration between two uC (AT89C51RE2). I’m using the UART0 and the Timer 2(Timer0 and Timer1 are already occupied). I was checking some information about this modules and I understood that in this kind of configuration it’s just like a wire but using the Xbee right?
I tried just to send a bit to turn on a LED, but I just succeeded sometimes. Sometimes it’s working good but sometimes I need to reset it many times till it turns on. I’ve already changed the channels to avoid interferences. I’m not sure if the program it’s not fine or what’s going on. I’ve already checked the baudrate in both components (Xbee by X-CTU and uC by program).
Here’s the configuration of the Xbee’s and the program. I tried also to connect the both UART from the uC directly by wire and was working properly (100% success).
Module 1:
CH: B
ID:ABCD
DH:0
DL: 1
MY: 2
Module 2:
CH: B
ID:ABCD
DH:0
DL: 2
MY: 1
The programm(C):
Send:
#include <at89c51xD2.H>
unsigned int i,j;
void enviar ( unsigned char x);
void main (void)
{
P3_5=0; // LED VERDE
P3_3=0; //LED ROJO
SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */
T2CON &= 0xF0; /* EXEN2=0; TR2=0; C/T2#=0; CP/RL2#=0; */
T2CON |= 0x30; /* RCLK = 1; TCLK=1; */
TH2=0xFF; /* init value */
TL2=0xD9; /* init value */
RCAP2H=0xFF; /* reload value, 9600 Baud at 12 MHz */
RCAP2L=0xD9; /* reload value, 9600 Baud at 12 MHz */
ES = 1; /* Enable serial interrupt */
EA = 1; /* Enable global interrupt */
TR2 = 1; /* Timer 2 run */
enviar(0x01);
while(1)
{
for (i=0; i<100; i++)
{
for (j=0; j<100; j++);
}
P3_3=1;
for (i=0; i<100; i++)
{
for (j=0; j<100; j++);
}
P3_3=0;
}/* endless */
}
void enviar (unsigned char x)
{
SBUF=x;
//Transmit byte
while(TI==0); //Wait for byte to be transmitted
TI=0; //Clear transmit interrupt flag
P3_5=1;
}
Recive:
#include <at89c51xD2.H>
unsigned char q;
unsigned int i,j;
void main (void)
{
P0=0x00;
P3_5=0; //LED VERDE
P3_3=0; //LED ROJO
SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */
T2CON &= 0xF0; /* EXEN2=0; TR2=0; C/T2#=0; CP/RL2#=0; */
T2CON |= 0x30; /* RCLK = 1; TCLK=1; */
TH2=0xFF; /* init value */
TL2=0xD9; /* init value */
RCAP2H=0xFF; /* reload value, 9600 Baud at 12 MHz */
RCAP2L=0xD9; /* reload value, 9600 Baud at 12 MHz */
ES = 1; /* Enable serial interrupt */
EA = 1; /* Enable global interrupt */
TR2 = 1; /* Timer 2 run */
while(1)
{
if (q==0x01)
{
P3_5=1;
}
} /* endless */
}
/**
* FUNCTION_PURPOSE: serial interrupt, echo received data.
* FUNCTION_INPUTS: P3.0(RXD) serial input
* FUNCTION_OUTPUTS: P3.1(TXD) serial output
*/
void serial_IT(void) interrupt 4
{
if (RI == 1)
{
/* if reception occur */
RI = 0;
q = SBUF;
}
else TI = 0; /* if emission occur */
} /* clear emission flag for next emission*/
Thank you so much,
Victor