I've been using a ATMEGA 1281 on a custom PCB to control some other IC's for an education project.
To program the ATMEGA I've been using the MegaCore repository here.
I've seen uniform success in bootloading the 1281, and programming it the first time. After that I hit a snag. When I try to program the board a second time I'll get verification errors; such as:
avrdude: verification error, first mismatch at byte 0x0000
0x62 != 0x0c
avrdude: verification error; content mismatch
Okay, no biggy right? Various forums say to just reflash the bootloader, and try again. If I try to reflash the 1281 responds with nothing:
All future communication to the 1281 after trying to reflash the bootloader responses with the aforementioned Device signature = 0x000000.
This occurrence would not be atypical if it happened intermittently, but it occurs every time I upload a second program. I have replaced the 1281 3 times and it's happened in this order each time. I was hoping someone would have insight as to what could be causing this behavior.
For a quick check list:
I have a 10 uF cap between reset and ground on my programmer (An Uno)
My wiring is sound, as A. It works the first time; and then fails.
B. I verified connectivity with a multimeter.
I have tried closing the arduino.exe, reseting my computer, and pressing reset prior to programming.
Yes the PCB has steady power, verified with a oscilloscope. It's stable at 3.28V. Note the system needs 5V if it is trying to run an external clock at 16 MHz, I'm using the internal crystal.
My PCB should not be shorting anything to ground, as none of the I/O are shorted. I will verify this using a Voltage source with Amperage display shortly.
I've seen uniform success in bootloading the 1281, and programming it the first time. After that I hit a snag. When I try to program the board a second time I'll get verification errors; such as:
Are you selecting 8Mhz internal from the IDE tools/clock and burning the bootloader using the IDE?
I am using 1MHz Internal, as per recommendation of the MegaCore repository. Although yes, I am using the Arduino IDE.
There might be some issues related to the internal oscillator. It's factory calibrated, but may be a little "off" depending on the calibration, ambient temperature and operating voltage. If uploading failes while using the 8 MHz internal oscillator you have three options:
Edit the baudrate line in the boards.txt file, and choose either 115200, 57600, 38400 or 19200 baud.
Upload the code using a programmer (USBasp, USBtinyISP etc.) or skip the bootloader
Use the 1 MHz option instead
Is there any possibility the first time you burn the bootloader the !6Mhz clock is selected instead of the 1Mhz?
The reason I ask, is because when I pull up the mega1281 the first time, the 16Mhz clock is the one selected and with the chip bootloaded and fuses burned for an external crystal, the next time you try , it will fail.
Well, I've managed to brick it again. It's possible that I'm writing the wrong fuse bits. Both 1 and 8 MHz internal fail. I'll let y'all know if I find the issue.
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xfe"
avrdude: writing efuse (1 bytes):
Writing | ***failed;
################################################## | 100% 0.09s
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xfe:
avrdude: load data efuse data from input file 0xfe:
avrdude: input file 0xfe contains 1 bytes
avrdude: reading on-chip efuse data:
Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: WARNING: invalid value for unused bits in fuse "efuse", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xf6 instead of 0xfe (double check with your datasheet first).
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xd6"
avrdude: writing hfuse (1 bytes):
Then after writing again:
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
For future plagued programmers, I looked at all of the signals for the ISP with an oscilloscope and noticed my NRESET was not rebounding very quickly. I replaced the 10K resistor with a 4.7K. Seems to work
Yeah; so, it worked for a little while, and then decided that it no longer wanted to. Without changing any wires, or messing with the code I've gine back to square one. The board device signature keeps mocking me with 0x000000.
I am running internal 8MHz Clk. Should the pin XTAL 2 be oscillating? It is not.
Also, could my problem be the Arduino as ISP? Would getting an AVR ISP tool help with resolving the intermittent failures?