Am I bricking my Atmega 328P?

Hi All,

I'm having a problem with a custom board I made. I intend to use an Atmega 328P-AU (QFP) and program through an ICSP header I provided. What happens is I can read the fuses with avrdude after I first solder the chip in place, but if I try to burn a Lilypad bootloader (8 Mhz internal osc.) I can never reach the board again.

Here is the result when I first solder the chip on:

avrdude -p m328p -c usbtiny -vv -B 32

avrdude: Version 6.0.1, compiled on Dec 16 2013 at 17:26:24
         
--snip --    
         
avrdude: Setting SCK period to 32 usec
CMD: [ac 53 00 00] [ec d2 53 00]
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00sCMD: [30 00 00 00] [00 30 00 1e]
CMD: [30 00 01 00] [00 30 00 95]
Reading | #################                                  | 33% 0.01sCMD: [30 00 02 00] [00 30 00 0f]
Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f

avrdude: safemode: lfuse reads as 62

avrdude: safemode: hfuse reads as D9

avrdude: safemode: efuse reads as 7

avrdude: safemode: lfuse reads as 62

avrdude: safemode: hfuse reads as D9
CMD: [50 08 00 00] [00 50 08 ff]
CMD: [50 08 00 00] [00 50 08 ff]
CMD: [50 08 00 00] [00 50 08 ff]
avrdude: safemode: efuse reads as 7

avrdude: safemode: Fuses OK (H:07, E:D9, L:62)

avrdude done.  Thank you.

And here is the result when I try to do Burn Bootloader:

avrdude -C avrdude.conf -v -patmega328p -cusbtiny -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m 

avrdude: Version 6.0.1, compiled on Apr 14 2015 at 16:30:25
        

         

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: erasing chip
avrdude: Using SCK period of 10 usec
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0x05"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x05:
avrdude: load data efuse data from input file 0x05:
avrdude: input file 0x05 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xDA"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDA:
avrdude: load data hfuse data from input file 0xDA:
avrdude: input file 0xDA contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

avrdude -Cavrdude.conf -v -patmega328p -cusbtiny -Uflash:w:ATmegaBOOT_168_atmega328_pro_8MHz.hex:i -Ulock:w:0x0F:m 

avrdude: Version 6.0.1, compiled on Apr 14 2015 at 16:30:25
        

         Using Port                    : usb
         Using Programmer              : usbtiny
Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.

avrdude: usbdev_open(): Found USBtinyISP, bus:device: 020:028
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Error while burning bootloader.

It looks like it writes the fuse in some way that makes the chip unreachable. It does this:

-v -patmega328p -cusbtiny -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m

Then this:

-v -patmega328p -cusbtiny -Uflash:w:/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex:i -Ulock:w:0x0F:m

What am I doing wrong? I don't have any provision for a crystal on this board.

Thanks.

I had to snip out some of the error messages to fit the post in 9000 characters.

Thanks

Lower 3 bits of the Low Fuse Byte are the clock source.

Calibrated Internal RC Oscillator 0010

From your message: avrdude: safemode: lfuse reads as 62

So that looks correct.

If you then change it to -Ulfuse:w:0xFF:m

Low Power Crystal Oscillator 1111 - 1000 It's expecting an external oscillator.

So you'll need to tack on an external clock somehow to be able to re-program.

See here http://www.gammon.com.au/forum/?id=11635 about 2/3 down for "Alternate clock source"

Thanks Crossroads! I wonder why my Lilypad definition would set the fuses for an external oscilator. Ok. I’ll just set the fuses with avrdude and use the Lilypad board def when I upload through ICSP.

Thanks!

Oh! I see from the schematic, lilypad HAS a crystal! Ooops!

! I wonder why my Lilypad definition would set the fuses for an external oscilator.

All the lilypad schematics that I can find show an external resonator (even for 8MHz), so I'd assume that that's what the bootloader (and boards.txt) is configured for as well. (lilypad seems to run at 8MHz to allow lower voltage operation, not to eliminate the external component.)

I have more than one problem in this project. I’ve just started with a fresh board and a fresh atmega328 and I get the rc=-1 error right from the start. I’ve included the schematic, in case it helps. The board I’m trying to program at the moment only has the AVR on it, but the board follows this schematic. Is it my circuit that is bad?

Thanks for any advice.

Jimmy

Something I've wondered for a while now is why Nick Gammon's board programmer sketch uses the internal oscillator fuse setting for Lilypad. But I suppose if somebody wanted to use the resonator they could program it as an Uno and it would work as a Lilypad anyway because the baud rate would be half that of Uno. And westfw I remember you saying before that is the unofficial and OK way to do that. Anyway, to make a long story shorter, mixographer, Nick Gammon's board programmer sketch provides a clock signal on the programmer Arduino's pin 9, and you can temporarily apply that signal to the XTAL1 pin of your bricked chips as you program the "Lilypad" bootloader. That sketch sets the fuses to internal oscillator when it programs the Lilypad bootloader. Details here: http://www.gammon.com.au/bootloader

I recommend trying that board programmer sketch running on a separate Arduino instead of using the usbtiny and programming it with the IDE burn bootloader function. You can hold a stiff wire or dupont pin on the XTAL1 pin while you program. Try that with one of the boards you bricked, because at least those boards you know for a fact worked and are healthy (since you successfully programmed the fuses). Re-visit the new board that's giving you the rc=-1 error later.

The reason the lilypad has the resonator is probably because the internal oscillator on the 328p is not good enough to reliably work for serial...

Thanks for all the comments and ideas. Djlambert, I took one of those tiny red enamelled wires and was able to stick it to pin 7. My eyes will never be the same, but i got it on there. Then i hooked that up to a function generator I had here. It only goes to 2Mhz, so i set it to one and it worked. I got the fuses set for 8Mhz and an internal osc.

I think I'll make a board definition for 8Mhz internal since it seems that is what I always use.

Thanks!

dmjlambert: Something I've wondered for a while now is why Nick Gammon's board programmer sketch uses the internal oscillator fuse setting for Lilypad.

I'm wondering that too. :)

Maybe there were different Lilypad versions. The ones I looked at used the internal oscillator. Or maybe I just made a mistake. ;)