I want to send data to atmega 2560 from my laptop using two Xbee S2C.
- The first Xbee , let's label it A , is to be interfaced with the laptop.
- The second Xbee , let's label it B , is to be interfaced with the atmega 2560.
I want to know how to configure these Xbees to communicate with each other. I am a beginner , I know only few things :
- The Xbee A will be interfaced with the laptop using Xbee usb adapter , which will facilitate the UART communication between Laptop and Xbee A.
- The Xbee B will be interfaced with the Atmega2560 by providing Xbee B with power and connecting Tx and Rx of the micro controller to that of Xbee B.These two will then communicate via UART.
I am also not clear that the controller's Tx and Rx pin will connect to Xbee B's Tx and Rx pin respectively or the other way around. Please guide.
Here's the code I am burning to Atmega 2560 , initially for turning a led on/off on PB6
#define F_CPU 14745600
#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
unsigned char data; //to store received data from UDR1
//Function to initialize ports
void port_init()
{
DDRB = 0x40;
}
//Function To Initialize UART0
// desired baud rate:9600
// actual baud rate:9600 (error 0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
// UBRR0L = 0x47; //11059200 Hz
UBRR0L = 0x5F; // 14745600 Hzset baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x98;
}
ISR(_VECTOR(26)) // ISR for receive complete interrupt
{
data = UDR0; //making copy of data from UDR0 in 'data' variable
UDR0 = data; //echo data back to PC
if(data == 0x37)
PORTB = 0x00;
if(data == 0x39)
PORTB = 0x40;
}
//Function To Initialize all The Devices
void init_devices()
{
cli(); //Clears the global interrupts
port_init(); //Initializes all the ports
uart0_init(); //Initailize UART0 for serial communiaction
sei(); //Enables the global interrupts
}
//Main Function
int main(void)
{
init_devices();
while(1);
}