I am trying to do UART communication between atmega128 and arduino UNO. Both are running at 9600 baud rate( checked both by doing serial communication with laptop using xbee radios from zigbee),but i am not receiving data properly. The data is following some pattern but i am not able to understand the relation.The lower four bits are always correct but upper four bits follow some weird pattern.
should receive---------actual received
1------------------------9
2------------------------A or 8
3------------------------B or 9
4------------------------8 or A
5------------------------9 or B
my atmega128 and arduino code are as follow: arduino sends one value and atmega128 displays the recieved value on array of 8leds on PORTA.
Arduino code
void setup()
{
Serial.begin(9600);
Serial.write(33);
}
void loop()
{
}
Atmega128 code:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
volatile unsigned char tdata, rdata;
void USARTInit()
{
UBRR0L = 0X67;
UBRR0H =0x00;
UCSR0C= ((1<<UCSZ00)|(1<< UCSZ01));
UCSR0B=(1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0);
}
ISR(USART0_RX_vect)
{
rdata = UDR0;
PORTA = rdata;
}
void init_devices()
{
cli();
DDRA =0xff;
USARTInit();
sei();
rdata=0;
}
int main(void)
{
init_devices();
while(1)
{
}
}
should receive---------actual received
1------------------------9
2------------------------A or 8
3------------------------B or 9
4------------------------8 or A
5------------------------9 or B
my atmega128 and arduino code are as follow: arduino sends one value and atmega128 displays the recieved value on array of 8leds on PORTA.
Arduino code
void setup()
{
Serial.begin(9600);
Serial.write(33);
}
void loop()
{
}
Atmega128 code:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
volatile unsigned char tdata, rdata;
void USARTInit()
{
UBRR0L = 0X67;
UBRR0H =0x00;
UCSR0C= ((1<<UCSZ00)|(1<< UCSZ01));
UCSR0B=(1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0);
}
ISR(USART0_RX_vect)
{
rdata = UDR0;
PORTA = rdata;
}
void init_devices()
{
cli();
DDRA =0xff;
USARTInit();
sei();
rdata=0;
}
int main(void)
{
init_devices();
while(1)
{
}
}