Electronic – Interface of XBee module with ATMEGA 168

atmegacommunicationserialxbeezigbee

I have configured 2 xbee series 1 modules such that one will receive serial data from any other module of same pan ID and the other will send data to the previous mentioned one.

Now when I use a terminal software (XCTU) to check data transmission its fine.
I want to send data serially using a ATMEGA 168 using xbee as transmitter. And another xbee will receive the data and send it to an ATMEGA 2560 based platform. I do not have any platform for atmega 168 so I kinda built a burner (bootloader circuit). The bootloader works.
I have connected pin 3 (TXD of USART0) of atmega 168 with data in (pin 3) of xbee module. I have made necessary power connections as well (Vcc=3.3V & GND ). But the xbee does not seem to send anything. Is there something I am missing ? Please help, as you may already figured out I am a complete newbie.

PS : before reducing my reputation please let me know what I am doing wrong so I may rectify that.

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

void uart0_init(void)
{
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x00;
 UCSR0C = 0x06;
 UBRR0L = 0x5F; //set baud rate lo
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0x98;
}

void init_devices()
{
 cli();              
 uart0_init();  
 sei();              
}


 int main(void)
{
 unsigned char data; 
 init_devices();
 data =1;  

 while(1)
 {
     data =0x21;
     UDR0 = data;
    _delay_ms(2000);
    data =0x55;
     UDR0 = data;
    _delay_ms(2000);


 }

}
}

This is the code I used.

Best Answer

The problem was in the programming. Unless the fuse settings are changed the microcontroller uses its default 8MHz oscillator with a pre-scaler of 8. So effectively you should have a 1 MHz system frequency instead of 12 MHz. So for 9600 baud you have to put:

UBRR0L = 0x06; //set baud rate lo

instead of

UBRR0L = 0x5F; //set baud rate lo

This should take care of the problem. Though I do not know how to configure the fuses or whatever.