Read/Write Fuses on StandAlone ATMega328P

Hello everyone, I'm loosing my mind with this simple problem.

I've been working on project for several months and to speed-up the development and also gain more FLASH space, I started flashing the ATMega328P with an Arduino UNO with Arduino as ISP code loaded on it.

I cannot get the LowPower library (by Rocketscream) to work even when I've been using it on other projects, so I start thinking it could be related to the fuses.

I've read that when using Arduino as ISP to load the code it won't burn the fuses so I needed to burn a bootloader first I've already done this but the problem is still there.

So I read about using avrdude to read/write the fuses but I guess it's not working.

First I'd like to clear a doubt... if I use -c stk500v1 with avrdude command I'll read the fuses of the atmega328 on the Arduino UNO right? And in order to read the fuses of the standalone atmega328 I should use -c arduino, right?

Well this is what I get:

avrdude -c arduino -p m328p -P COM7 -b 19200 -v
LOW 0xFF
HIGH 0xDA
EXT 0x05

avrdude -c arduino -p m328p -P COM7 -b 115200 -v (note I've change baudrate to 115200 this was the only value that worked, don't know why)
LOW 0x00
HIGH 0x00
EXT 0x00

And when I try to write them using:
avrdude -c arduino -p m328p -P COM7 -b 115200 -U lfuse:w:0xFF:m

I get:
avrdude: verification error, first mismatch at byte 0x0000
0xff != 0x00
avrdude: verification error, content mismatch

avrdude: safemode: lfuse changed! Was ff, and now is 0
Would you like this fuse to be changed back?

what is the meaning fuses?

sebasira:
I've read that when using Arduino as ISP to load the code it won't burn the fuses so I needed to burn a bootloader first I've already done this but the problem is still there.

Nonsense. Using Arduino ISP is kind of programming. You can also burn the fuses with this. Just one thing, if the ISP programming is used, the bootloader will be lost since it resides in flash which is erased during programming process.

First I'd like to clear a doubt... if I use -c stk500v1 with avrdude command I'll read the fuses of the atmega328 on the Arduino UNO right? And in order to read the fuses of the standalone atmega328 I should use -c arduino, right?

Well this is what I get:

avrdude -c arduino -p m328p -P COM7 -b 19200 -v
LOW 0xFF
HIGH 0xDA
EXT 0x05

avrdude -c arduino -p m328p -P COM7 -b 115200 -v (note I've change baudrate to 115200 this was the only value that worked, don't know why)
LOW 0x00
HIGH 0x00
EXT 0x00

Arduino ISP has upload speed hard-coded to 19200 baud. It doesn't work at different speed.

Agung14:
what is the meaning fuses?

The fuses is kind of MCU's setup. There are defined things like the clock, its source and speed, boot region etc.

@Augung14

  1. A Fuse Bit, in the context of ATmega328 Microcontroller, can be conceptually visualized as a
    ‘Jumper Wire’ which has two conditions:
    (a) Unbroken (Unprogrammed; Logic value 1)
    (b) Broken (Programmed; Logic value 0)

(2) A Fuse Bit establishes a definite ‘Functional Mode’ of the microcontroller (MCU). For example: the
fuse bit named CKDIV8, when it is programmed, defines that the system clock (clkSYS = clkCPU)
will be equal to ‘Oscillator Frequency/8’, and it is shown in Fig-12. In Fig-12.1 (see the attached
file), the LL (Logic Low = programmed) value of CKDIV8 closes K2 and opens K1.

(3) The attached file may help you a little bit further to understand the meanings and necessities of
the fuse bits of ATmega32.

EXpt12.pdf (495 KB)

Hi Guys!

Thank you all for your replies!

As @Budvar10 said, I know that programming via ISP would erase the bootloader, it's also a desired effect in order to have a little bit more of FLASH space.

I'm struggling here because I don't know if the fuses of the standalone ATMega328 are set, so when I tried to read them with the commands on my first post I get some strange result.

To be a little more specific, here's a diagram of how I have them connected in order:

  • PC
  • UNO with ArduinoISP sketch loaded (let's call this MCU-A)
  • ATMega328 with 8Mhz xtal connected to SPI of MCU-A (let's call this MCU_B)

I'm able to load the code just fine in MCU-B is working okay, but after some digging I don't know if MCU-B has the right fuses, for example, I don't know if it is using the external 8MHz xtal or if it's working with internal osc.

So I was trying to read them. I've seen that there are two commands:

avrdude -c arduino and avrdude -c stk500v1. Which one should I use and why? At what speed?

Thank you!

arduino - but both will work under most circumstances. IIRC, arduino is the same as stk500v1, only with a workaround for some bug.

You do know the values of the fuses on the target MCU, you read them right here:

avrdude -c arduino -p m328p -P COM7 -b 19200 -v
LOW 0xFF
HIGH 0xDA
EXT 0x05

ie, it's using a crystal.

If you were to re-enable autoreset on the programmer MCU,

avrdude -c arduino -p m328p -P COM7 -b 115200 -v

should get you the fuses of the programmer MCU.

Programming over ISP only erases the flash if you pass avrdude the -e parameter. This must be done if you're writing any byte of the flash that was previously written. This is generally done when doing "burn bootloader" (since the command it invokes is structured to support writing a bootloader to the flash - where there's no bootloader, it's typically fed a dummy bootloader)

Not sure why LowPower isn't working - also not sure what the point of that library is, the avr sleep and avr power libraries that come with the compiler don't seem complex enough to justify a wrapper like LowPower around them. Have you read Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors