ATmega328P with USBAsp on Ubuntu: can no longer program an ATmega328P with USBAsp

Hi everyone,

It's my first time with a standalone ATmega328P. I once tried to use MPLAB X IDE (with XC8 compiler) to generate .hex files and then use Avrdude in the Terminal (I managed to learn it somehow through some tutorials). My first try was a blink program on pin PD7. It worked but was slow... Then i tried the function:

#define F_CPU 16000000UL (because I intend to use a 16MHz crystal oscillator)

At first I wasn't aware of the importance of the "fuse bits" stuff. I would just go on to obtain a .hex file with MPLAB X and flash it right away on the microcontroller through USBAsp. It seemed to work well... Only to realize the true problem later.
Then, after careful assessing, I decided instead to use the Arduino IDE for my project in order to simplify things (assuming that I'm not yet ready enough to go beyond as I realized that I still don't have enough of the required skills to bridge the huge gap), so I planned to flash my ATmega328P with an Arduino Uno bootloader through the Arduino IDE. Now appears the following error:

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.

-Checked the connections multiple times: nothing wrong
-Tried the -F option: only to get additional errors (the "expected signature" error, and with the microcontroller's signature changing whenever i try this -F option)
-Tried the -B option with various numbers: changed nothing
-Tried to use the "MiniCore" in Arduino IDE: changed nothing

Meanwhile, as long as the ATmega328P is powered, the previous PD7 pin blink program is still and always running.

-Tried to use "Arduino as ISP" as a programmer (I have an Arduino Mega 2650): only to get the "not in sync" error
-Tried to once again flash the last .hex program from MPLAB X into it through USBAsp: changed nothing, still the same error
-Tried to short the JP3 jumper on USBAsp: changed nothing
-Tried to update USBAsp firmware (the german one): changed nothing
-Tried to use another USBAsp with the original chinese firmware: changed nothing
(Anyway, there is no need of any driver in order to use USBAsp on Linux, which makes my case different from Windows users)

Then, after further Internet browsing, I became aware of the importance of the "fuse bits" stuff

-Tried to remove the 16MHz external oscillator with the associated capacitors: changed nothing
-Tried to put back the 16MHz external oscillator with the associated capacitors: changed nothing
-Tried to reset the fuse bits from avrdude: changed nothing
-Tried to erase the microcontroller: changed nothing

And as usual, as long as the ATmega328P is powered on, the previous PD7 pin blink program is still and always running.


I spent several days trying to solve this issue, but I haven't yet found any solution to get out of this situation. I just can no longer program the microcontroller. So I am wondering:

-Is my ATMega328p dead? (then why is it still endlessly running the previous PD7 pin blink program as long as it is powered on?)
-Does it have anything to do with the MPLAB X IDE that I used earlier?
-Is there still a way to save it? To reset the "fuse bits"? To flash the Arduino bootloader into it?
-Is there anything wrong with the USBAsp?

If my current microcontroller is really hopeless and nothing can be done to save it, I still have one new remaining ATMega328p as a spare. I don't want to waste it with any of my previous mistakes so I want to fully understand what did I do wrong and what should I've done instead from the beginning

And one more thing: once the Arduino bootloader is flashed, can I still use the USBAsp to upload Arduino sketches into my ATmega328p microcontroller? If I can, then how should I proceed? (Considering it's the only way that I currently have to program my microcontroller on the breadboard)

Any help about my case would be greatly appreciated

/MaverickRF

(My setup: Ubuntu Mate 18.04, MPLAB X IDE v5.45 (XC8 v2.31), Arduino IDE 1.8.9, Avrdude 6.3-4, USBAsp_V3, ATmega328P PDIP variant)

It needs a clock signal.
You also have to connect all the GND pins to GND and all the (A)VCC pins to 5V, there should be decoupling capacitors.

This has an option for an alternate clock source: https://www.gammon.com.au/bootloader.

An extra option is the High Voltage programming via the RESET pin.

I think it is still possible to "brick" the ATmega, so that it can no longer be used.

Hi Koepel,
Well, I'll try to figure out a way to solve this problem. Anyway, I want to thank you already for the link... The content is very helpful.