I got a PCB made up that uses the ATMEGA328 chip (the same as the Arduino Pro Mini) for a project. I am trying to install the bootloader using the AVR pocket programmer https://www.sparkfun.com/products/9825 with no luck. I keep getting this error:
"avrdude: initialization failed, rc=-1 Double check connections and try again, or use -F to override this check."
I have looked at all the forums, and i cannot see any issues with my wiring. I have also read that it can be a software issue.
The board is basically a bare bones board without any voltage regulator that will be used with a 3.7V Lipo battery. It has no crystal or resonator.
Can anyone please suggest how this can be bootloaded using the AVR pocket programmer.
Is that an out of the box chip or has anyone already changed its fuses? Maybe they are set to external osc, which may be the reason it isn't starting up.
Is that an out of the box chip or has anyone already changed its fuses? Maybe they are set to external osc, which may be the reason it isn't starting up.
This is an out of the box chip that has never been used. It is a Atmega328P.
I tried using the boards.txt file with '8 MHz internal clock' with no success. I have hoping it is just a settings problem.
Do you have the power switch on your pocket AVR programmer set to Power Target? Or are you powering the target m328P some other way? Keep in mind the pocket AVR programmer is operating at 5V USB power. So you will need to power your target m328P at 5V.
Most m328P have factory default for internal 1MHz clock (8MHz/8). However there are some that come pre-programmed with a bootloader and set for external clock. In this case you may need to add a crystal and caps in order to re-program it for internal clock.
Do you have the power switch on your pocket AVR programmer set to Power Target?
Yes
Most m328P have factory default for internal 1MHz clock (8MHz/8). However there are some that come pre-programmed with a bootloader and set for external clock. In this case you may need to add a crystal and caps in order to re-program it for internal clock.
I’m not sure about this part, i will need to dig a little deeper. I might not be able to add a crystal and cap at this stage also.
Do you have the XTAL1 pin broken out anywhere on your board?
If you have an extra Uno or Pro-mini then you could set the fuse bit to output the (CLKO) clock out signal on pin D8. Then connect this pin D8 and GND to your board XTAL1 and GND pins. This should supply an external clock signal to the m328P so you can reprogram it. Assuming of course that this is the problem.
Do you have the XTAL1 pin broken out anywhere on your board?
No i don't. Worst case is that i just hold a wire on this chip pin.
If you have an extra Uno or Pro-mini then you could set the fuse bit to output the (CLKO) clock out signal on pin D8. Then connect this pin D8 and GND to your board XTAL1 and GND pins. This should supply an external clock signal to the m328P so you can reprogram it. Assuming of course that this is the problem.
Ok, i managed to get the CLKO out of the the Arduino Uno. I connected the grounds of my target board and the Uno together. I connected the CLKO to XTAL1 temporarily by holding it at that pin. I also changed the boards.txt file under "Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ATmega386" to
pro328.bootloader.low_fuses=0xE2
The low fuse is set to 0xE2
The high fuse is set to 0xDA
The extended fuse is set to 0x05
I tried to bootload it again but i got a different error. After pressing the bootload button and waiting for some time, i eventually got this error:
avrdude: verification error, first mismatch at byte 0x7800 0x0c != 0xff avrdude: verification error; content mismatch
I couldn't find much about this error. But it looks like i'm heading in the right direction.
When you burn bootloader it has two stages. Sounds like it got past the first stage of setting the fuses, but failing on the second part of writing the bootloader. This could be if the pin you are holding is making intermittent contact. However, if we assume the fuse bits got changed then it may be running on internal 8MHz clock. Then you don't need the external clock anymore. How many times did you try?
However, if we assume the fuse bits got changed then it may be running on internal 8MHz clock. Then you don't need the external clock anymore. How many times did you try?
I have tried at least 5 times. I currently still get the same error
avrdude: verification error, first mismatch at byte 0x7800 0x0c != 0xff avrdude: verification error; content ismatch
but i do not need to add the external clock anymore.
I also tried using 'Upload using Programmer' and i get this error:
avrdude: verification error, first mismatch at byte 0x7880 0x05 != 0x02 avrdude: verification error; content ismatch
but the numbers change each time i try this.
Is there another setting that needs to be changed?
Well, verification errors usually point to some kind of wiring or connection problem. Can you verify your programmer's ribbon cable has good connectivity? I've had a bad crimp on a ribbon cable that drove me nuts until I replaced the cable. It was not obvious and lead me down the wrong path until I figured out it was just the cable. (BTW, it was the same pocket programmer from SparkFun that had a bad cable)
Hopefully you have at least a DMM test meter? You can do continuity checks from the programmer 10-pin to your board ICSP 6-pin header.
One other thing, do you have anything else connected to the board that could be loading down the pins?
Can you verify your programmer's ribbon cable has good connectivity?
I checked this out using the meter and it seemed ok. I made my own cable anyway and it WORKED! I could bootload the chip and upload. However, i am still getting the 'verification error' more times than i get it working. I have tried just uploading the program to the chips without installing the bootloader using 'Upload Using Programmer' and this has also varied with success. Is there a more reliable device out there to upload a sketch? For every 5 attempts, it works about 1-2 times for bootloading and uploading.
One other thing, do you have anything else connected to the board that could be loading down the pins?
One of the boards i has a nrf24l01+ connected to pins 12 and 11 also. I tried using uploading the simple blink example with no problems. But when i tried to use the nrf24l01+ part of the board which uses the iBoardRF24 library, i have not been able to successfully upload this. Is there something that needs to be changed/ added to allow me to use this library?
The ICSP header uses pins D11 and D12. The nrf24 board is probably interfering with the uploads and causing the verification errors. You will need a way to disconnect the nrf24 board when you program the m328p mcu.