Autor Tema: Usando la usart con atmega88 y winavr->Solucionado  (Leído 2365 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado kain589

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 324
Usando la usart con atmega88 y winavr->Solucionado
« en: 17 de Marzo de 2009, 18:54:50 »
Saludos! Estoy empezando con los microncontroladores atmel, y despues del famoso parpadeo del led he pasado al uso de la usart. El lenguaje que empleo es winavr, y tras mirar codigos he adaptado el siguiente codigo, pero no consigo hacerlo funcionar:

Código: [Seleccionar]
#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);Este es para otros micros
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;
}
}

¿Alguna idea de que puede estar mal?

Edito-> Pues ya va, fue un problema al seleccionar los fuses, queria poner el rango de 3-8mhz y puse de 0.9 a 3.0mhz
« Última modificación: 18 de Marzo de 2009, 14:05:19 por kain589 »
Saludos desde Córdoba, españa