So, I wan't to connect RPi to Atmega32 via UART. I have RPi with minicom, set on 9600 baud rate 8 bit, no parity, 1 stop bit, no flow control hardware/software. Atmega ( working on 3.3v ) - 8Mhz clock 9600 baud 8 bit, no parity, 1 stop bit. Connected RPi's 8 pin (TX) to Atmega's 14 (RX), and RPi's 10 to Atm 15. Fuses - Low ( 0xE4 ) High ( 0xD9 ). Code below. Everytime I start everything, all I'm getting is random chars. What I'm doing wrong ?
Atmega's code:
Code: Select all
#include <avr/io.h>
#include <inttypes.h>
#define F_CPU 8000000UL
#include <util/delay.h>
void USARTInit(uint16_t ubrr_value)
{
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
/*
>> Asynchronous mode
>> No Parity
>> 1 StopBit
>> char size 8
*/
UCSRC=(1<<URSEL)|(3<<UCSZ0);
UCSRB=(1<<RXEN)|(1<<TXEN);
}
char USARTReadChar()
{
while(!(UCSRA & (1<<RXC)))
{
//Do nothing
}
return UDR;
}
void USARTWriteChar(char data)
{
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
UDR=data;
}
void main()
{
char data;
USARTInit(51); //UBRR = 51
while(1)
{
data=USARTReadChar();
USARTWriteChar('data');
}
}