I bought an online deal which had 10x ATmega328p with bootloader installed. I thought I can erase the bootloader once I got the order (I want to write custom task without a bootloader) but my programmer does not seem to find the ATmega328p. I know it is the problem of the microcontroller because I have another ATmega328p which works fine and I can upload code to it. Is there a flag or switch I am missing when trying to overwrite the bootloader on the microcontroller?
Here are the components I am using:
- ATmega328p with bootloader
- SparkFun Pocket AVR Programmer (usbtiny)
Here are the commands I am using:
- To compile:
avr-gcc -std=c11 -mmcu=atmega328 -O -o main.o main.c
- To generate hex:
avr-objcopy -O ihex main.o main.hex
- To upload:
sudo avrdude -c usbtiny -p m328p -U flash:w:main.hex
Here is the output of the avrdude
command:
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.
Anyone encountered similar situation before? How did youu managed to fix it? I appreciate any help :)
Thank you
Edit #1 I tried setting the -B
flag to various values but nothing seems to solve the problem.
Edit #2 Here is the circuit I am using while programming the ATmega328p
- 2x Capacitors 22pf
- 1x Crystal oscillator 16Mhz
- 1x Resistor 10K ohm
- 1x ATmega328p
- 1x SparkFun Pocket AVR Programmer
-
Maybe you need to provide a specific clock input to the chip...Majenko– Majenko2017年07月20日 00:01:21 +00:00Commented Jul 20, 2017 at 0:01
-
Thanks @Majenko for your comment, I should have mentioned that I tried using the -B flag with low, medium and high values but nothing did workCOMP– COMP2017年07月20日 00:09:38 +00:00Commented Jul 20, 2017 at 0:09
-
This is almost certainly not a bootloader problem but either a programmer, wiring, power, clock, or fuses one. Or you could have switching power supply chips re-printed to look like ATmega328p's (though those were QFP, and I suspect yours are DIP).Chris Stratton– Chris Stratton2017年07月20日 00:20:21 +00:00Commented Jul 20, 2017 at 0:20
-
Your post should include a schematic diagram of how your powered and clocked these. Would also be good to include a photo of the chips themselves. Have you tried this process/programmer with any chips from a reputable source yet?Chris Stratton– Chris Stratton2017年07月20日 00:23:03 +00:00Commented Jul 20, 2017 at 0:23
-
@ChrisStratton thanks for your suggestions, I added an image showing the circuit I am using.COMP– COMP2017年07月20日 00:29:03 +00:00Commented Jul 20, 2017 at 0:29
1 Answer 1
Your connections to the ATmega328p are incomplete.
You are missing the connection of ground to pin 22, and you must supply power to AVCC on pin 20.
You should also place the capacitors much closer to the crystal with a very direct route to ground, and try to place the crystal itself closer to the chip.
Additionally you should use supply bypass capacitors.
Please see the minimum wiring at Arduino on a Breadboard, however this document itself is erroneous as it neglects to show the high frequency 0.1 uF bypass capacitors you should have directly across each pair of power pins.
That's not to say that there may not be additional issues as well - but you need to fix the circuit problems first.