hello everyone,
I have strange with my board composed with PIC 18f452 (HSPLL 8Mhz x 4)and XBEE S1 (v10A5). I work in API mode. I don’t use RTS and CTS function.
I want the PIC send a TX REQUEST (64bits) to XBEE , get the TX STATUS ,package it in new TX REQUEST packet , and send it . The problem is TX_STATUS is never received if pic don’t wait 10s .In fact , i just receive the first two byte 7E 00 .
If the PIC wait 10s , it received TX STATUS succesfull !!!
I have simulated this board with Proteus VSM + COMPIN model (and connect PC Xbee board on COM port) . No problem appear.
I think it’a a timing problem but i don’t see where ?!?
This is my mikro C source code
#define WIBEE_AT_COMMAND 0x08
#define WIBEE_TX_REQUEST 0x00
#define WIBEE_FRAME_ID 0xFF
#define WIBEE_START_DELIMITER 0x7E
#define WIBEE_TX_STATUS 0x89
unsigned char WIBEE_Packet_checksum;
unsigned char WIBEE_AT_COMMAND_BUFFER[2];
unsigned char WIBEE_AT_COMMAND_VALUE[20];
unsigned char WIBEE_AT_COMMAND_VALUE_LENGHT;
unsigned char WIBEE_TX_REQUEST_DESTINATION_ADDRESS[8];
unsigned char WIBEE_TX_REQUEST_OPTIONS;
unsigned char WIBEE_TX_REQUEST_RF_DATA[64];
unsigned char i;
// Sending packet to WIBEE network or AT COMMAND to XBEE
// In input : Packet Type => WIBEE_AT_COMMAND
// WIBEE_TX_REQUEST
// In output : operation result WIBEE_PACKET_SEND_SUCCES
// WIBEE_PACKET_SEND_FAILED
unsigned char WIBEE_Send_Packet(unsigned char PacketType)
{
// 1) Init checksum
WIBEE_Packet_checksum = 0xFF - PacketType;
WIBEE_Packet_checksum -= WIBEE_FRAME_ID;
// 2) What type of packet to send ?
// 3) Checksum calculate
// 4) Send packet to Xbee
switch (PacketType)
{
// Commande AT
case WIBEE_AT_COMMAND:
WIBEE_Packet_checksum -= WIBEE_AT_COMMAND_BUFFER[0];
WIBEE_Packet_checksum -= WIBEE_AT_COMMAND_BUFFER[1];
for (i = 0 ; i < WIBEE_AT_COMMAND_VALUE_LENGHT ; i++)
WIBEE_Packet_checksum -= WIBEE_AT_COMMAND_VALUE;
Usart_Write(WIBEE_START_DELIMITER);
Usart_Write(0);
Usart_Write((0x04 + WIBEE_AT_COMMAND_VALUE_LENGHT));
Usart_Write(WIBEE_AT_COMMAND);
Usart_Write(WIBEE_FRAME_ID);
Usart_Write(WIBEE_AT_COMMAND_BUFFER[0]);
Usart_Write(WIBEE_AT_COMMAND_BUFFER[1]);
for (i = 0 ; i < WIBEE_AT_COMMAND_VALUE_LENGHT ; i++)
Usart_Write(WIBEE_AT_COMMAND_VALUE);
break;
// Data packet to transmit
case WIBEE_TX_REQUEST:
for (i = 0 ; i < 8 ; i++)
WIBEE_Packet_checksum -= WIBEE_TX_REQUEST_DESTINATION_ADDRESS;
WIBEE_Packet_checksum -= WIBEE_TX_REQUEST_OPTIONS;
for (i = 0 ; i < 64 ; i++)
WIBEE_Packet_checksum-=WIBEE_TX_REQUEST_RF_DATA;
Usart_Write(WIBEE_START_DELIMITER);
Usart_Write(0);
Usart_Write(75);
Usart_Write(WIBEE_TX_REQUEST);
Usart_Write(WIBEE_FRAME_ID);
for (i = 0 ; i < 8 ; i++)
Usart_Write(WIBEE_TX_REQUEST_DESTINATION_ADDRESS);
Usart_Write(WIBEE_TX_REQUEST_OPTIONS);
for (i = 0 ; i < 64 ; i++)
Usart_Write(WIBEE_TX_REQUEST_RF_DATA);
break;
default:
break;
}
Usart_Write(WIBEE_Packet_checksum);
return 1;
}
void main()
{
// Port C initialization
TRISC = 0x80;
PORTC = 0x00;
LATC = 0x00;
// USART initialization
Usart_Init(9600);
// Clear TX_REQUEST_RF_DATA buffer
for (i = 0 ; i < 64 ; i++)
WIBEE_TX_REQUEST_RF_DATA = 0x00;
// Destination address 000000000000FFFF for broadcast
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[0] = 0x00;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[1] = 0x00;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[2] = 0x00;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[3] = 0x00;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[4] = 0x00;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[5] = 0x00;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[6] = 0xFF;
WIBEE_TX_REQUEST_DESTINATION_ADDRESS[7] = 0xFF;
// No options
WIBEE_TX_REQUEST_OPTIONS = 0x00;
// Send packet to network
WIBEE_Send_Packet(WIBEE_TX_REQUEST);
PORTC.RC0 = 1; // Power on STATUS LED
// Get TX STATUS
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[0] = RCREG;
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[1] = RCREG;
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[2] = RCREG;
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[3] = RCREG;
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[4] = RCREG;
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[5] = RCREG;
while (!Usart_Data_Ready);
WIBEE_TX_REQUEST_RF_DATA[6] = RCREG;
// Send new packet
WIBEE_Send_Packet(WIBEE_TX_REQUEST);
PORTC.RC0 = 0; // POWER OFF STATUS LED
// infinite loop
while (1)
{
}
}
schematic of my board can be found here : http://yoopix.org/thumb/show?WEAUExE-c1
thanks a lot for your help