Go Down

Topic: [SOLVED] atmega328p: Switching between 8Mhz and 1Mhz (Read 322 times) previous topic - next topic


Hi all,
I am trying to understand if it is enough to change low_fuses from 0xe2 to 0x62 to switch atmega328p from 1Mhz internal oscillator to 8Mhz internal oscillator?

I am using MiniCore to compile binary for custom board, I have no bootloader.

My standard configuration:

I am trying to use OneWireHub to emulate DS18B20 sensor and library told me that

That's why I am trying to use internal 8Mhz clock, cause when I am compiling using this MiniCore settings no warning appears.

Is it enough to compile appropriate firmware and program it using Arduino as ISP?


Oct 18, 2018, 06:41 pm Last Edit: Oct 18, 2018, 06:43 pm by DrAzzy
Is it enough to compile appropriate firmware and program it using Arduino as ISP?
No, you must first choose "burn bootloader" if you want to set fuses (or set them manually with AVRDude - and yes, changing lfuse from 0xe2 to 0x62 is all that's needed). This is necessary even if not using a bootloader - for several reasons, involving limitations of the IDE as well as the precedent set by the official core, third party cores do not set the fuses when uploading a sketch via ISP even for boards with no bootloader.

"Burn bootloader/Set Fuses" would be a more accurate name for that menu option, but it would confuse people new to programming (many arduino users) who only know of "fuses" as the thing that blows when something goes wrong, and people new to AVR who know "fuses" as the one-time-programmable e-fuses featured on many processors and used to secure code.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy


Oct 19, 2018, 10:49 am Last Edit: Oct 19, 2018, 10:52 am by kosmo_de
set them manually with AVRDude - and yes, changing lfuse from 0xe2 to 0x62 is all that's needed
Many thanks! I've found some sample code in avrdude documentation:
!WARNING! Use it on your own risk, it could brick your controller.

1. I have used following command to enter terminal mode of avr dude
Code: [Select]
"%ProgramFiles(x86)%\Arduino\hardware\tools\avr\bin\avrdude" -C"%ProgramFiles(x86)%\Arduino\hardware\tools\avr\etc\avrdude.conf" -v -p m328p -u -c avrisp -b 19200 -P COM4 -t
Main parameters for that -u - for turning off security for fuses write (without it requires either read or write 3 times to commit your changes to fuses) and -t - turns terminal mode on.

To find out what parameters are used by arduino IDE to program your controller you can turn on verbose output for compilation and upload; upload your project via IDE and you will see in output log avrdude command executed for upload

2. use d command to read fuses (could be lfuse, efuse and hfuse)
Code: [Select]
avrdude> d lfuse
>>> d lfuse
0000  62

3. from MiniCore boards.txt we can find out what lfuses should be used for 1Mhz internal and for 8Mhz internal settings.
Code: [Select]
328.menu.clock.8MHz_internal=8 MHz internal

328.menu.clock.1MHz_internal=1 MHz internal

4. Now we write lfuse to change it value to 0xe2, read it to assure everything is fine and quit avrdude:

Code: [Select]
avrdude> write lfuse 0 0xe2
>>> write lfuse 0 0xe2

avrdude> d lfuse
>>> d lfuse
0000  e2

avrdude> quit
>>> quit

avrdude done.  Thank you.

Now our controller runs using 8Mhz internal oscillator!


I've found out another - more convenient - option to flash fuses: I just add following to my avrdude command string:
Code: [Select]
-U lfuse:w:0x62:m
for 1Mhz internal clock
Code: [Select]
-U lfuse:w:0xE2:m
for 8Mhz internal clock

You can also replace lfuse with any other fuse you need to set. You can set multiple fuses just chaining all commands for different fuses as above together



You can just use MiniCore as intended. Select Bootloader: No, choose between 8 MHz internal or 1 MHz internal and hit Burn Bootloader.

No bootloader will be written, but the fuses will be sat correctly according to the options you've selected. The program that's already on the microcontroller will be erased though.

The options that MiniCore provides is there so you don't need to interface with AVRdude directly. Most users find this easier.
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535

MiniCore - ATmega8, mega48, mega88, mega168, mega328

Go Up