Saludos! No se cuantos por aqui usaran atmel, pero estoy iniciandome con estos micros y he probado a hacer/adaptar un codigo para la usart. Os pongo aqui el codigo a ver si me podeis ayudar a hacerlo funcionar, gracias de antemano
Código:
#include <stdlib.h>
#include <avr/io.h>
#define F_CPU 4000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
int main (void)
{ //Variables
char ReceivedByte;
// Turn on the transmission and reception circuitry:
UCSR0B |= (1 << RXEN0) | (1 << TXEN0);
// Use 8-bit character sizes:
//UCSR0C |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
UCSR0C |= (1 << UCSZ00) | (1 << UCSZ01);
// Load lower 8-bits of the baud rate value into the low byte
// of the UBRR register:
UBRR0L = BAUD_PRESCALE;
// Load upper 8-bits of the baud rate value into the high byte
// of the UBRR register:
UBRR0H = (BAUD_PRESCALE >> 8);
for (;;) // Loop forever
{
// Do nothing until data have been recieved and is ready
// to be read from the UDR register:
while ((UCSR0A & (1 << RXC0)) == 0) {};
// Fetch the recieved byte value into the variable
// called "ByteReceived":
ReceivedByte = UDR0;
// Do nothing until UDR is ready for more data to be
// written to it:
while ((UCSR0A & (1 << UDRE0)) == 0) {};
// Echo back the received byte back to the computer:
UDR0 = ReceivedByte;
}
}