Electronic – Problem with Atmega 168 USART receive interrupt ,while communicating with Xbee

atmegaatmel-studioavrserialxbee

Before decreasing my reputation please let me know what I have done wrong. Bear with me as I am a newbie.

I have written a program so that a receiver radio module sends 1 when it receives an 1 from a broadcaster module.I am using XCTU with a Xbee as the broadcaster.Here is the code.

#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>

unsigned char data; //to store received data from UDR0



//Function To Initialize UART0
// desired baud rate:9600
// actual baud rate:
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x00;
 UCSR0C = 0x06;
 UBRR0L = 0x06; //set baud rate lo
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0x98;
}


SIGNAL(SIG_USART0_RECV)         // ISR for receive complete interrupt
{
    data = UDR0;  //making copy of data from UDR0 in 'data' variable 
    if(data == 0x31)
    UDR0 = data;                //echo data back to PC

}


//Function To Initialize all The Devices
void init_devices()
{
 cli(); //Clears the global interrupts
 uart0_init(); //Initailize UART1 for serial communiaction
 sei();   //Enables the global interrupts
}

//Main Function
int main(void)
{
init_devices();
    while(1);
}

Now the problem is that when I send an 1 we do not get any response from the receiver. We tried the same thing with an Atmega 2560 based devboard as the receiver and the program worked like charm. But when we try it with Atmega 168 nothing happens.
Well with Atmega 168 we use internal crystal of 8MHz with 8 prescaler ie 1MHz system clock so I have used

 UBRR0L = 0x06; //set baud rate lo

Used for dev-board

 UBRR0L = 0x5F; //set baud rate lo

to get 9600 baud. But no matter what I do the interrupt just isn't working. We tried running a toggling cycle in the main program to see it that is working or not and that worked too. But when ever I transmit a signal via XCTU (terminal software) the receiver does not go to ISR like it is supposed to.

Please help. Ask me back if anything I need to clarify.

Best Answer

You are using the old format for interrupts, I wonder if this is the cause of the problem.

Please refer to avr/interrupt.h

The interrupt handler should be like

ISR(USART0_RX_vect)
{

}