eray81
Junior Member level 3
Hi,
I want to send data with attiny2313 to atmega32 mc. I use code below, but it doesnt work. when attiny2313 sends data to atmega32 , i cant see the right data on LCD connected to atmega32. what may the problem be?
I want to send data with attiny2313 to atmega32 mc. I use code below, but it doesnt work. when attiny2313 sends data to atmega32 , i cant see the right data on LCD connected to atmega32. what may the problem be?
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define F_CPU 4000000
//#define BAUDRATE 9600
//#define BAUD_CALC ((F_CPU/(BAUDRATE*16))-1)
#define BAUD_CALC 25
int main (void)
{
unsigned char data=0;
UBRRH = (unsigned char)(BAUD_CALC>>8);//Set baud rate
UBRRL = (unsigned char)BAUD_CALC;//Set baud rate
UCSRB = _BV(TXEN) | _BV(RXEN) | _BV(RXCIE);
UCSRC = (0<<USBS)|(1<<UCSZ0)|(1<<UCSZ1)|(0<<UCSZ2)|(0<<UMSEL);//Set frame format
for (;;){
USARTWriteChar(0x01);
_delay_ms(1000);
USARTWriteChar(0x02);
_delay_ms(1000);
USARTWriteChar(0x03);
_delay_ms(1000);
}
}
void USARTWriteChar(char data)
{
//Wait until the transmitter is ready
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
//Now write the data to USART buffer
UDR=data;
}