Issues using MegaCore as ISP

Hi all,

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:

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.

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:

  1. I have a 10 uF cap between reset and ground on my programmer (An Uno)

  2. My wiring is sound, as A. It works the first time; and then fails.
    B. I verified connectivity with a multimeter.

  3. I have tried closing the arduino.exe, reseting my computer, and pressing reset prior to programming.

  4. 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.

  5. 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.

Thanks!

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.

I have just reinstalled a processor, and bootloaded with a 100% probability that it is indeed 1 MHz internal.

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):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd6:
avrdude: load data hfuse data from input file 0xd6:
avrdude: input file 0xd6 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0x62"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0x62:
avrdude: load data lfuse data from input file 0x62:
avrdude: input file 0x62 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.


avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "D:\Programs\Arduino\hardware\MegaCore-master\avr/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega1281
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    131072  256    512  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9704 (probably m1281)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "D:\Programs\Arduino\hardware\MegaCore-master\avr/bootloaders/optiboot_flash/atmega1281/optiboot_flash_atmega1281_9600_1000000L.hex"
avrdude: writing flash (131072 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 131072 bytes of flash written
avrdude: verifying flash memory against D:\Programs\Arduino\hardware\MegaCore-master\avr/bootloaders/optiboot_flash/atmega1281/optiboot_flash_atmega1281_9600_1000000L.hex:
avrdude: load data flash data from input file D:\Programs\Arduino\hardware\MegaCore-master\avr/bootloaders/optiboot_flash/atmega1281/optiboot_flash_atmega1281_9600_1000000L.hex:
avrdude: input file D:\Programs\Arduino\hardware\MegaCore-master\avr/bootloaders/optiboot_flash/atmega1281/optiboot_flash_atmega1281_9600_1000000L.hex contains 131072 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% -0.00s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x1fc00
         0x00 != 0x01
avrdude: verification error; content mismatch

avrdude done.  Thank you.

Error while burning bootloader.

Also, looking at the warning for Efuse, it is indeed supposed to be 0xfe; as per [AVR Fuse Calculator.](http://AVR Fuse Calculator.)

P.S before I uninstalled the 1281, I did probe the SCK, TX, and RX lines.

SCK is clocking

RX is held high

TX is slightly above reference. :confused:

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 :slight_smile:

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. :confused:

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?