Tech Support > Computer Hardware > Microprocessors > Incorrect AVR UART Frequency
Incorrect AVR UART Frequency
Posted by Andy Greensted on August 1st, 2003


Hi All,

I'm trying to set up the UART on a ATMega128L. Problem is the output
frequency isn't write.

I've got an 8Mhz AVR Clock. The AVR is set up in normal Async mode. UBRR is
zero, so the ouput bps should be 0.5MHz (A bit period of 2us). But I'm
getting a bit period of (16.5us).

Any ideas? Does Fosc mean the main chip clock?

Thanks All
Andy

Here's the code:

..include "m128def.inc"

..def w = R16 ; Define a working register
..def data = R17

; Set UBRR for 500kbps
; UBRR = 0

ldi w, 0x00
sts UBRR0H, w

ldi w, 0x00
out UBRR0L, w

; Enable Transmitter
ldi w, 1<<TXEN0
out UCSR0B, w

; Set 8 bits data width
ldi w, (1<<USBS)|(1<<UCSZ0)
sts UCSR0C, w

; Set data
ldi data, 0xCB

UART_TX:
sbis UCSR0A, UDRE0 ; Skip if Set
rjmp UART_TX

out UDR0, data ; Ouptut data

rjmp UART_TX


Posted by Dave Hansen on August 1st, 2003


On Fri, 01 Aug 2003 17:03:13 +0100, Andy Greensted <ajg112@york.ac.uk>
wrote:

What are your clock fuses set to? Are you using the internal (1 MHz?)
oscillator?

Regards,

-=Dave
--
Change is inevitable, progress is not.

Posted by Andy Greensted on August 6th, 2003


That did the trick. The default fuse settings set the clock source to the
internally generated 1MHz clock.

Nice one, thanks Dave

Andy

Dave Hansen wrote:


Posted by Dave Hansen on August 7th, 2003


On Wed, 06 Aug 2003 12:30:44 +0100, Andy Greensted <ajg112@york.ac.uk>
wrote:

You're welcome.

This usually bites people the other way -- They take a working system
and inadvertently program the clock fuses to a (non-existent) external
oscillator. After which, the chip doesn't work and cannot be
programmed serially unless an until an external clock is applied.
Time to pull the chip and use parallel mode, or replace it entirely if
the pulling didn't go well...

Regards,

-=Dave
--
Change is inevitable, progress is not.

Posted by Brian Dean on August 8th, 2003


On Thu, 07 Aug 2003 13:46:50 -0400, Dave Hansen wrote:

Occasionally this happens to one of my customers and I find myself talking
them through this procedure. It'd be real cool if there was some magic
sequence that could be applied to the ISP pins of an AVR just out of reset
where the whole chip could be set back to factory defaults, regardless of
the current fuse bit settings.

-Brian
--
Brian Dean, bsd@bdmicro.com
BDMICRO - Maker of the MAVRIC ATmega128 Dev Board
http://www.bdmicro.com/


Similar Posts