Standard Fuse Settings for 16Mhz ATMega328p

I've finally got myself a virgin ATMega328p and without uploading a bootloader, I've uploaded a simple variation of Blink and thought it was broken until I realised that because I hadn't set the fuses, the MCU was just using internal clock and running at 1MHz intead of 16MHz (I've included a crystal on my board).

So I'm thinking that if I set my fuses to the same as my ATMega328p Uno then I should be OK.

But I can't find what the bytes should be - could someone tell me please (I've given up trying to read them out from my Uno :frowning: )

And of course, if the fuses should be different for a non-bootloader 16Mhz crystal clocked ATMega328p than my Uno, could I have those instead :slight_smile:

regards
Simon

I had exactly the same issue when I programmed my first 328! You can work out the fuse settings you need at http://www.engbedded.com/fusecalc.

PS - If you just want the same ones as used in a standard Arduino, you can find them in the boards.txt file:

uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05

1 Like

boards.txt

Ta :slight_smile:
I used the values in there and used my little USBasp programmer with

avrdude -c usbasp -p m328p -C ../etc/avrdude.conf -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0x05:m

and my project imeidiately started running at the correct speed :slight_smile:

Simon

How about these:

Fuse calculator: http://www.engbedded.com/fusecalc/
Arduino Default Fuses: http://www.codingwithcody.com/2011/04/arduino-default-fuse-settings/

Don

Hi,

These setting did it for me too... 16mhz atmega328p.

lfuse = 0xff
hfuse = 0xde
efuse = 0x05

Thanks.

Have you heard of the phrase "a day late and a dollar short" out there in zeroland?

What has this post (to a stale thread) added that wasn't already said in the very first reply?

Don

dc42:
I had exactly the same issue when I programmed my first 328! You can work out the fuse settings you need at http://www.engbedded.com/fusecalc.

PS - If you just want the same ones as used in a standard Arduino, you can find them in the boards.txt file:

uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05

Hi dc42.

I am getting similar issues as this with a 328p-au..
I've tried alsorts but am a bit stuck:

http://arduino.cc/forum/index.php/topic,129740.0.html

Any ideas?

Thanks in advance.

I've tried alsorts but am a bit stuck:

Have you tried either the default values or the values recommended in this thread?

Don

When I use the Arduino IDE to flash the bootloader it always sets the proper fuses without any interaction on my behalf.

I've been doing the same - burn a Uno bootloader to set the fuses.Then upload my sketch via File :Upload Using programmer.

clivemist:
Hi dc42.

I am getting similar issues as this with a 328p-au..
I've tried alsorts but am a bit stuck:

http://arduino.cc/forum/index.php/topic,129740.0.html

Any ideas?

Thanks in advance.

Looking at your post #7 in that thread, you are setting the baud rate to 300 on the mcu but then you have to set the PC to 2400 to communicate with it. So the UART in the mcu is running 8x faster than it should be. This isn't a problem with the CLKSEL fuse bit, that would cause the mcu to run 8x slower instead.

Are you sure that you have F_CPU set correctly in the boards.txt file you are using? Do you also find that delay and delayMicroseconds calls also execute 8x faster than they should?

1 Like

dc42:

clivemist:
Hi dc42.

I am getting similar issues as this with a 328p-au..
I've tried alsorts but am a bit stuck:

http://arduino.cc/forum/index.php/topic,129740.0.html

Any ideas?

Thanks in advance.

Looking at your post #7 in that thread, you are setting the baud rate to 300 on the mcu but then you have to set the PC to 2400 to communicate with it. So the UART in the mcu is running 8x faster than it should be. This isn't a problem with the CLKSEL fuse bit, that would cause the mcu to run 8x slower instead.

Are you sure that you have F_CPU set correctly in the boards.txt file you are using? Do you also find that delay and delayMicroseconds calls also execute 8x faster than they should?

Thanks for getting back to me Don.

From using the calculator I managed to get the baud correct with:

lfuse:w:0x77:m
(I know this is probably incorrect).
..and from messing about trying to set the fuses again I am back to the same issue of the baud reading out incorrectly and chasing my tail..

The board.txt is set to:


##############################################################

uno.name=Arduino Uno

uno.upload.protocol=arduino

uno.upload.maximum_size=32256

uno.upload.speed=115200

uno.bootloader.low_fuses=0xff

uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
uno.build.variant=standard


The following worked when I had the baud reading at the correct rate:

  • IDE does not upload
  • AVRDude upload via Arduino ISP works
  • Upload in IDE via Arduino ISP works
  • Serial feedback (TX-RX loop) works [328 bypassed]
  • Serial feedback via 328P works
  • Holding reset at various times before/during/on upload no dice
  • f_cpu=16000000L

I've double checked all my schematics, including the pull down 1k, 100nf cap between the 8u2 and the reset on the 328P-AU.
I have also removed and resoldered these components.

Could this be an issue with the 8u2?
I have managed to run the DFU many times with the same code I uploaded on to my R3 and this still uploads and works.

Thanks in advance for any suggestions!

So do delay() calls in sketches you upload delay for the correct amount of time or not?

dc42:
So do delay() calls in sketches you upload delay for the correct amount of time or not?

Sorry, got my last post incorrect..

A delay(1000) posts at roughly 1 second. However the baud is mismatched.

clivemist:

dc42:
So do delay() calls in sketches you upload delay for the correct amount of time or not?

If you mean in a main body of code, they are not, also my baud is mismatching again..

Do they take too long? or not enough time? By what factor are they wrong?

dc42:

clivemist:

dc42:
So do delay() calls in sketches you upload delay for the correct amount of time or not?

If you mean in a main body of code, they are not, also my baud is mismatching again..

Do they take too long? or not enough time? By what factor are they wrong?

Sorry, I tried that again.

A delay(1000) posts roughly every second. The baud is mismatched..

Is the baud rate mismatched only when you are uploading a program through the bootloader, or it is also mismatched when you do a Serial.begin followed by a Serial.print ?

My head is spinning a little so please excuse me if I have missunderstood you here, but..

This is the sketch I am using:


void setup()
{
Serial.begin(300);

void loop()
{
Serial.println("Hello world!");
delay(1000);
}

When I bring up the serial monitor it posts at baud 2400 every second.

In summary:

  1. Delay calls execute in the correct amount of time. So the clock is almost certainly running at the right speed.

  2. To communicate with the serial port of the device, you have to set the PC to a baud rate 8x higher than the device is supposedly set to.

Therefore, either the PC software is at fault and is running at a baud rate 8x lower than you ask for, or the UART in your 328p-au is running at a baud rate 8x higher than you ask for. Can you connect to a standard Arduino at 2400 baud using the same board setting, to verify that the PC software is operating correctly?

I've just tried to communicate with my Arduino Uno at 300 baud, and it doesn't work. It works at higher baud rates. Maybe a bug in the Arduino software? Try a higher baud rate.

You might also like to upload the following sketch to see what the UART baud rate divisor is set to:

void setup()
{
  Serial.begin(2400);
}

void loop()
{
  Serial.print((int)UBRR0H, HEX);
  Serial.write(',');
  Serial.print((int)UBRR0L, HEX);
  Serial.write(',');
  Serial.println((int)UCSR0A, HEX);
  delay(1000);
}