Electrical – clock frequency confusion

atmegaavravr-gccserialuart

I am using an atmega16 micro controller with a 12MHz external crystal oscillator. But I came to know that the internal clock frequency is 1MHz

I need to calculate UBRR value for serial communication. I need a baud rate of 115200.

If I am using 1MHz in UBRR value calculation by using the formula (F_CPU/(16*baud))-1 then I am getting a negative number greater than -1.
What should be the value of F_CPU?

please do help me as I not an electronics guy.
Thanks in advanced for any help…

Best Answer

The default fuse settings for an ATMega are to use the 8MHz internal oscillator (INTOSC) divided by 8 (CLKDIV8). This means the default clock frequency is 1MHz as you are seeing. Correction: for the ATMega16 it seems that there is no CLKDIV8 fuse, it is part of the clock source selection fuse bits - but the default is still 1MHz.

In order to use the external 12MHz clock signal, you need to program the fuse settings to correctly select the clock source and disable division by 8.

"Engbedded" have a really useful free calculator which helps you determine the fuse settings required for AVRs. The calculator can be found here. For you it seems something along the lines of Low:0xE0, High:0xD0 should do, though you will have to check yourself as there are other things like the bootloader reset vector and brown out detection which are set by the fuses.

Related Topic