Unable to set fuses on ATMEGA328P using avrdude in Command Prompt (Windows)

Dear all,

I am trying to set fuses in my ATMEGA328P chip (on breadboard) using Arduino Mega 2560 as an ISP. I have seen some tutorials online using command prompt in Windows. Unfortunately I receive an error as follows,

C:\Users\FlexGuest>avrdude -c avrisp -p m328p -P com6 -b 19200 -U lfuse:r:-:i -v
'avrdude' is not recognized as an internal or external command,
operable program or batch file.

I got the command from this tutorial

Did any of you faced this issue and solved it, or knows what I am doing wrong? I appreciate your help greatly.

Many thanks,
Raj

Is Arduino IDE installed in the system?
Run the IDE, go to the Preferences and make sure that both checkboxes "Show verbose output..." are set


Restart the IDE, than try to compile and upload any sketch - you can see the avrdude command line and path in the output in the low part of IDE window

But the easiest way to write the fuses to the atmega328 chip is uploading the bootloader via Tools menu in the Arduino IDE. The fuses will updated automatically. There are a lot of tutorials in the net regarding the subject.

Thanks for your prompt response. I have the Arduino IDE installed and verbose output during compilation turned on.

I have found the path for avrdude on my device and the command prompt responds to the path as follows:

I did try uploading the '3.3V 8MHz' bootloader for the 'Arduino Pro or Pro Mini' board to my ATMEGA328P chip expecting it to run on a 3.3V power supply from an Arduino Uno. I tried uploading the Blink sketch, it runs on 5V but not on 3.3V. I suspect it is the BOD fuse that's not set correctly and hence the chip's not responding to voltages below 4.7V ? So I wanted to turn off the BOD completely to check if it will run on 3.3V.

Do you have any guidance on this, please?

Many thanks.

What is the clock option of the chip? Do you use an external oscillator or internal clock?

I was using an external 16MHz clock. But now I am able to use the internal 8MHz clock.

I will explain it in detail so others may benefit from it.

I was trying to execute the commands I saw from tutorials online For example,

avrdude -c usbtiny -p m328p -U efuse:w:0x07:m

When I tried pasting this in my Command Prompt application, it failed.

Thanks to using the verbose script while uploading, as suggested by @b707 , I could see what commands are being used by avrdude, (see image).

I simply copy-pasted the avrdude commands in my notes when uploading multiple sketches and observed a pattern. There was an essential command line that kept repeating no matter what program tried to upload. I called it the "Essential Bit". Which for me looked as follows:

C:\Users\FlexGuest\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\FlexGuest\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM4 -b19200 

Note: This is specific to my use case with Arduino Mega 2560 as ISP to program a bare ATMEGA328P chip on the breadboard connected to my PC. It will be different for other individuals.

Then I copy-pasted this Essential Bit before every command I wanted to execute from the tutorials. Below are some examples

For brown-out disable from this forum:

avrdude -c usbtiny -p m328p -U efuse:w:0x07:m

became

C:\Users\FlexGuest\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\FlexGuest\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM4 -b19200 -U efuse:w:0x07:m

For using Internal 8MHz clock from the same forum:

avrdude -c usbtiny -p m328p -U lfuse:w:0xE2:m

became

C:\Users\FlexGuest\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\FlexGuest\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM4 -b19200 -U lfuse:w:0xE2:m

Note: I had burned the bootloader of my ATMEGA328P to that of 'Arduino Pro or Pro Mini' at '3.3V 8MHz' using Mega 2560 as ISP through Arduino IDE. This was done before executing commands in Command Prompt. Not sure if that changes anything.

Hope it helps all.

Kind regards,
Raj

Sincere apologies, my post that I marked as a solution is not robust in essence. I think I have bricked my chip. I get the following error:

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

I tried looking at other forums to find some common issues but I could not find what exactly did I do wrong. Below is exactly what I did.

  • Upload sketch to Arduino Mega

  • Changed the board, processor and programmer as follows
    GetImage (2)

  • Burned bootloader

  • Uploaded Blink sketch using programmer
    GetImage (3)

This ran perfectly on 5V but I wanted it to run on 3.3V so I changed the fuses to use the 8MHz internal oscillator and disable brown-out detection (BOD) as mentioned in my last post. The BOD disable command did have some warning regarding "efuse". The outputs for both are as follows:

To use 8MHz internal clock
avrdude -c usbtiny -p m328p -U lfuse:w:0xE2:m

To disable BOD
-U efuse:w:0x07:m

Your guidance will help me not damage chips in the future. Heartiest thanks in advance!

Raj

I found a better way to achieve the same using just the Arduino IDE as mentioned in this article. It uses Minicore board by MCUdude to programme the chip at 5V with a 16 MHz external oscillator.

I am using the same circuit as described in my previous post.

Do the following to use the chip's internal oscillator:

  1. Make these selections and burn bootloader

This will inform the chip to use the 8MHz internal oscillator, set BOD to 1.8 V so that it runs on 3.3V input.

  1. Once the bootloader is successfully burned, select Tools> "no bootloader" and upload the blinky sketch using programmer.

    This will program the ATMEGA328P chip with the blinky sketch.

After the sketch is uploaded your LED should start to blink. Now disconnect the power supply, remove the external oscillator and capacitors from the XTAL pins, and reconnect the power supply at 3.3V. The LED should continue to blink as before.

Note: I am not sure about the following:

  1. Should I reconnect external 16 MHz oscillator and 22pF capacitors for reprogramming my custom board?
  2. Should I use a 5V power supply or 3.3V would do for reprogramming?

I do not have a spare chip, otherwise would have tried it. Perhaps, I might have bricked it earlier by doing just this.

Hope it helps, suggestions and advice are welcome.

Thanks,
Raj

Now I'm sure about the following:

  1. Should I reconnect external 16 MHz oscillator and 22pF capacitors for reprogramming my custom board?

A: No, because the chip now has a bootloader which instructs it to use the internal 8MHz oscillator, the same will be used for programming too. I have tried uploading the blinky sketch by changing delays in consequent sketches, it changes the delay as programmed. So tested OK.

  1. Should I use a 5V power supply or 3.3V would do for reprogramming?

A: I believe yes. Although the chip runs the programmed sketch on 3.3 V, it throws the following error if tried to programme with 3.3V supply instead of 5V. So I would connect the Vcc pin of the ICSP header on my custom board to 5V supply for programming purposes. I believe this shouldn't be a concern if someone's using an FTDI cable which would always have a output 5V.

Conclusion: While designing a custom board for 3.3V using 8MHz internal oscillator, you can omit the oscillator circuit. I tried burning bootloader without having the oscillator circuit, it works fine.

Any suggestions/advice is welcome.

Thanks,
Raj

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.