After Upload fail, initialization failed

Hello,

i have a USPasp and tried to Programm my Atmega328p while uploading i got this:

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file “.pioenvs\328p16m\firmware.hex”
avrdude: writing flash (930 bytes):
Writing | ################################################## | 100% 0.96s
avrdude: 930 bytes of flash written
avrdude: verifying flash memory against .pioenvs\328p16m\firmware.hex:
avrdude: load data flash data from input file .pioenvs\328p16m\firmware.hex:
avrdude: input file .pioenvs\328p16m\firmware.hex contains 930 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.54s
avrdude: verifying …
avrdude: verification error, first mismatch at byte 0x0006
0x04 != 0x6e
avrdude: verification error; content mismatch
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)
avrdude done. Thank you.
*** [upload] Error 1

On the next try i got:
avrdude: error: program enable: target doesn’t answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
*** [upload] Error 1

Is the chip dead? Can i somehow fix it?

Any loose connections, or no common ground?

Also add capacitors and pullups according to arduino ide - avrdude: verification error, first mismatch at byte 0x0000 : 0x00 != 0x16 using USBasp - Arduino Stack Exchange.

1 Like

No, connections all fine checked multiple times.

Cap & Pullup allready existing.

I doint found the 328p16m in the boards.txt. But can it be that it switched the fuse fore crystal oscillator on and not for the “swing” crystal? I doint have a crystal oscillator to check this

What exact board = .. are you using? 328p16m?

That config assumes a 16MHz crystal oscillator on the ATMega. Your hardware is different?

1 Like

yes 328p16m.
I have a 16MHZ swing crystal (the one with 2 Pins)

Does the problem still occur when using “Upload via Programmer” in the Arduino IDE with the same board settings?

The error
avrdude: error: program enable: target doesn’t answer. 1
avrdude: initialization failed, rc=-1

is the same, no differents in platformio / Arduino / avrdude -p m328p -c usbasp

So you can’t access the chip anymore? Power-cycle also doesn’t help?

If you mean with Power-cycle - turn it off and on again. Then yes it doint help.

What do you mean by “swing crystal”? There are ‘standard’ two pin crystal oscillators, and then there are three pin ceramic resonators. 328p16m just expects a to a 16Mhz oscilator… whether it be a crystal with load capacitors, or a three pin ceramic resonator.

A minimum, your circuit should have a 10K pullup to V+. Something like a 100nF capacitor on V+ and GND near the atmega328 pins would be good, but not critical. Also, don’t forget to put load capacitors between the crystal and ground! And probably a good idea to also connect the analog V+ and GND pins also…

with swing crysal i mean the “standart” two pin crystal.

My layout is like you picture (+ 100nf cap)

The first Upload was failed (Error Message at post 1) and after that i cant anymore excess the chip (Error message at post 1 + 7).

Your fuse settings haven’t been set properly from the looks of that… that combination is for the Internal 8Mhz RC oscillator, not for the crystal. Pull the crystal out, and try programming it again, but use the ‘Upload with programmer’ setting, and see if the fuses are set to

E:05, H:DE, L:FF

which are the Arduino defaults for the atmega328p. You can find out what the settings mean if you put them into the fuse calculator here, but it basically instructs the chip to use a crystal oscillator of 8Mhz or greater, instead of the internal clock.

Depending on what platform you are on, you can use avrdude natively, or use this nice GUI for it to set the fuse settings. You made also need to fiddle with the bit clock speed for your programmer to get the chip to respond. You’ll know if it’ll work if it auto-detects the chip when you click the ‘detect’ button :wink:

1 Like

Hello,
after some more testing nothing Workes. I buyed a other usbasp, with a Low clock speed jumper (instand of Automatic).
With this new Programmer i got the Chip to respond more often. After Some more trying i found out that the Socket i was using for the Chip didnt connect good in the Breadbord, so i trow it out and got more often responds from the chip (old programmer still nothing).

With PlatformIO i mostly get avrdude: verification error, first mismatch at byte XXXX
with the AVRDUDESS (& extra installed avrdude, not the one that comes with platformIO) it works 98% of the times.
So thanks for you help i got it working :))

Can i just replace Avrdudes files in platformIO with the extra installed ?

Hello,
I have got similar problem.I have a USPasp and tried to Programm my Atmega328p while uploading i got:

avrdude: verification error, first mismatch at byte XXXXX

But when I put in terminal pio run -t program it works well.
Additionally, when i try to upload this same hex file, it pass the verification. But when I change the code, another hex file gives verification error.

What is going on ? What is the difference between uploading with icon and the ‘program’ command?

USBasp i have with latest firmware.

Did you try using the ‘upload with programmer’ option - there are two separate menu options.

As Ivan pointed out in another thread where you mentioned this, for this target the primary difference is the use of the erase flag. For this target the Upload option/command primarily adds the -D for “don’t auto erase” parameter to the programming command, which is the same as is used by the Arduino IDE. This is because when you’re uploading, with some boards this could result in the bootloader being erase… which makes life a bit hard if you try to erase the bootloader WHILE IT IS RUNNING, especially when the upload fails and means you needed a ISCP to reflash the bootloader/program the board. The Upload with Programmer option / program target has no qualms about letting auto-erase occur, as since you’re using a programmer, the whole chip can be erased.