Incorrect AVR UART Frequency

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

Reply to
Andy Greensted
Loading thread data ...

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

Regards,

-=Dave

--
Change is inevitable, progress is not.
Reply to
Dave Hansen

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:

Reply to
Andy Greensted

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.
Reply to
Dave Hansen

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/
Reply to
Brian Dean

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.