Atmega USART Problems

Thread Starter

crazyengineer

Joined Dec 29, 2010
156
Okay, so I thought I had this working, earlier, but lately I've been having difficulty setting this up again. So I'm trying to do simple USART communication but it seems like nothing is writing to the terminal. Here's the code

Rich (BB code):
#include <avr/io.h>
#include <util/delay.h>
#define FOSC 8000000 // Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1



void USART_Init( unsigned int ubrr)
{
/*Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00)| (;
}


int main( void )
{

	USART_Init(MYUBRR);
	while(1)
	{

		while ( !( UCSR0A & (1<<UDRE0)) )
;
/* Put data into buffer, sends the data */
		UDR0 ='d';


	}
	return 0;
}
I'm using the internal clock of the atmega328p. Also, I'm using a USB to serial converter.

 
Top