- AVR, UART
- Posted by Umpa on May 12th, 2004
Hello,
I have got AVR ATmega16.
I attached 11059000 Hz oscilator
to XTAL1 and XTAL2 (+capacitors).
I can send data to the processor (UART) but
got wrong characters.
Probably, I haven`t set frequency
parameters correctly.
Do I have to set some extra things
in the code to use external oscilator
for UART?
What to do to make AVR's UART
working with 11,059MHz oscilator?
Piece of the code:
UART.h:
----------
#ifndef _UART_H_
#define _UART_H_
enum {
RECVBUF_MAX = 16,
FCPU = 11059000,
VUART = 57600,
VUBRR = FCPU / (VUART * 16) - 1
};
void initUART(void);
#endif
UART.c:
----------
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <string.h>
#include "uart.h"
void initUART(void)
{
UBRRH = (unsigned char)(VUBRR >> 8);
UBRRL = (unsigned char)VUBRR;
UCSRB = (1 << RXCIE) | (1 << TXCIE) | (1 << RXEN);
/* 8, 1 stop */
UCSRC = (1 << UCSZ1) || (1 << UCSZ0);
sei();
}
char recvBuf[RECVBUF_USER_MAX] = "\0";
volatile char *recvBufPtr = recvBuf;
volatile int flagaaa = 0;
SIGNAL (SIG_UART_RECV)
{
if (recvBufPtr - recvBuf < RECVBUF_MAX)
*recvBufPtr++ = UDR;
}
- Posted by Phill Harvey-Smith on May 13th, 2004
"Umpa" <¹¿æó@umpaumpalala.com> wrote in news:c7tot0$nf7$1
@atlantis.news.tpi.pl:
Have you set the fuses to use an external XTAL ? if you have not you will
still be using the internal 1MHz RC-oscilator (as that's how Mega16's
come out of the factory
).
Note when setting the fuses be carefull to set them for external XTAL and
*NOT* external oscilator.
Hope that helps.
Phill.
- Posted by Umpa on May 13th, 2004
fuses for XTAL: XTAL<0.4MHz, XTAL 0.4-0.9 MHz,
XTAL 0.9-3 MHz, XTAL 3-8 MHz.
I have got about 11 MHz oscilator which is faster than the fasters
fuse XTAL 3-8 MHz. I don`t know what to set.
Umpa.
- Posted by Meindert Sprang on May 13th, 2004
"Umpa" <¹¿æó@umpaumpalala.com> wrote in message
news:c7vap2$n7e$1@atlantis.news.tpi.pl...
Do yourself a favour and download the most recent version of AVRStudio at
www.atmel.com
Meindert