Receiving only a single character from XBee...

Hello members,

I have a XBee S1 mounted on Arduino Mega 2560 via XBee Shield. XBee is supposed to send on Hardware Serial Port 1 (for this shield pins are bent so that they don’t insert into hardware serial port 0) of Mega while the debug prints are coming on Hardware Serial 0. Debug prints are coming fine of Port 0. Both hardware ports are configured for double speed, 9600 baud, 1-8-N-1, asychronous clock. Am running Contiki on the mega. Problem is that I only get single character i.e. the 0x7E in some intervals. in the ISR repeatedly. In the start, I have requested the SH and SL command to XBee and expecting those values from XBee in the response. XBee is also configured with same serial parameters and in API=2 mode. What could be the issue, why is the ISR not giving me the complete frame ? For trying, I have added reading 5 bytes in the ISR, but still no success. Please help.

The ISR code is as follows :

ISR(USART1_RX_vect, ISR_BLOCK)
{
uint8_t cnt = 0;
// no frame error
// UCSR1A must be read before UDR1 !!!
if (bit_is_clear(UCSR1A, FE1))
{
/// must read the data in order to clear the interrupt flag
while(cnt <= 5) //Just for trial…
{
volatile unsigned char data = UDR1;
cnt++;

/// calculate the next available ring buffer data bucket index
volatile unsigned char next =
((g_rx_buff.r.head + 1) % SERIAL_RX_RING_SIZE);

/// do not overflow the buffer
if (next != g_rx_buff.r.tail)
{
INTERRUPTDEBUG(data); //Printing this in main loop, always get 0x7E… :frowning:
g_rx_buff.r.ring[g_rx_buff.r.head] = data;
g_rx_buff.r.head = next;
g_rx_buff.stats.ok++;
}
else
{
/// increase the dropped counter
INTERRUPTDEBUG(0);
g_rx_buff.stats.dropped++;
}
}
}
else
{
/// must read the data in order to clear the interrupt flag
INTERRUPTDEBUG(-1);
volatile unsigned char data attribute((unused)) = UDR1;
/// increase the frame error counter
g_rx_buff.stats.frame_error++;
}
}

Thanks and Regards.

Maybe because everything is in the ISR. (I personnally had trouble with wrong usage of an ISR.) A solution is setting a flag or the counter in the ISR and read this flag or counter in a loop to read the buffed data. I believe (in my noob opinion) that the main problem would be that the characters are coming too much quick for the program.