Incorrect AVR UART Frequency

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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



Re: Incorrect AVR UART Frequency

Quoted text here. Click to load it

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

Regards,

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

Re: Incorrect AVR UART Frequency
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:

Quoted text here. Click to load it


Re: Incorrect AVR UART Frequency

Quoted text here. Click to load it

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.

Re: Incorrect AVR UART Frequency

Quoted text here. Click to load it

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, snipped-for-privacy@bdmicro.com
BDMICRO - Maker of the MAVRIC ATmega128 Dev Board
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline