Arduino as ISP - strange behavior (?)

Windows 10 and the newest Arduino 1.6.13 (avrdude.conf copied to the bin directory to avoid using -C parameter).

I want to program an ATmega328P chip using Arduino Uno. I have an IC that is most likely in the default factory configuration (there is a slight chance it was used or is bricked, but I think it doesn't matter for the problem I am facing now). I have connected everything according to the bottom left image here: https://www.arduino.cc/en/Tutorial/ArduinoISP. I have opened ArduinoISP project, compiled it, uploaded - everything went fine. Then I tried to run avrdude just to check if everything is OK:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -c arduino -p m328p -P COM6 -b 115200 -v

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         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    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 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: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0

avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

Device signature looks OK, fuses look strange - no idea why, first problem. But, 115200 is too fast for programming the chip, the recommended baud rate is 19200. So I modified the code, recompiled it, uploaded (again everything goes OK), tried to run avrdude again with a lower baudrate:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -c arduino -p m328p -P COM6 -b 19200 -v

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         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    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 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.01s

avrdude: Device signature = 0x0fffff
avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.

Not only the device signature is now off, also some of the parameters listed by the avrdude have changed. It is my understanding that the baud rate is just for the PC<->Arduino communication and doesn't matter for the Arduino<->programmed processor communication, so the result of just reading the data should give the same result. Yet that's not the case. Also, if the processor was bricked I would expect the device signature to be off in both cases - but it looks OK when I am using 115200.

What am I missing? What to check?

Arduino as ISP sketch works at 19200 baud. Not only because it is hard coded. The communication is as slow because each instruction have to be processed with Adrduino which is in programmer role, but the main overheat is caused by LED indication at the beginning of the loop(). It runs reliably up to 57600 without this, for me.
You can obtain an output to byte level details with -vvvv parameter or by switching it on in the Prefereces.
However, the most cases of problems is bad wiring.

BTW: Bricked MCU doesn't respond at all. You should obtain only zeros in such case.
This situation should be solved by connecting the clock source to the XTAL1 pin or crystal. Simple modification of the ISP sketch can produce 8MHz clock signal on UNO's pin 9 if you have no crystal.

I know Arduino as ISP requires 19200 for programming, I stated it clearly in my post. I tried different speeds when I wasn't able to get it to work at 19200.

What I am not getting is why Arduino connected at 115200 seems to be reading the correct device signature. Does it choose this correct value out of 2^24 possibilities just to confuse me?

I am recommending to stay with original ISP sketch version and to check your wiring carefully. This is the first.
Show your wiring to be able to check it whether is correct or not.

Not a really complicated one, see the attachment. Yellow cables go in parallel (it is a bit tricky to see, as they blend together) from pins 13/12/11 to legs 17/18/19, green goes from pin 10 to the reset pin of the programmed chip (as I said earlier, this is a copy of the circuit given on the Arduino ISP tutorial page; I can be wrong, but as far as I can tell the circuit is OK; I have already tried to move cables, plug/unplug to check if the connections work OK; I have also measured the voltage on the bottom breadboard rail, it reads 5 V all the time).

I understand I will need to add a capacitor (RESET/GND) to program the chip - but my understanding is it is there to get rid of the RESET signal, which is not used when just reading the memory/fuses.

I have no crystal as I planned to rely on the internal generator. You have mentioned using pin 9 for XTAL1 - do I understand correctly that you mean using the same Arduino UNO that is working as a programmer to provide clock for the programmed chip? Somehow I can't find any information other than how to use an external generator.

Sorry, have no time for detailed help. Here is clock generator for UNO:

	pinMode(9, OUTPUT);

	OCR1A  = 0;
	ICR1   = 1;
	TCCR1A = _BV(WGM11) | _BV(COM1A1);				
	TCCR1B = _BV(WGM13) | _BV(WGM12) |_BV(CS10);

Add this snippet at the end of setup(). There will be 8MHz on pin 9 in result.

RB

Thanks, that helped enormously :slight_smile: It was bricked.

To everyone interested: Budvar's snippet configures internal timer to set the pin 9 of Arduino UNO to produce 8 MHz. Connect pin 9th of the Arduino to the XTAL1 on the processor (that means leg 9 for ATmega328P) and (unless the processor is bricked hard) there is a chance it will get back to life.

One thing more: I know what have happened. Actually the processor wasn't bricked, it was just configured differently than I expected. When you burn the bootloader using IDE it changes fusebits to configure it to use external clock source. So, if you plan to use the internal clock, you need to either burn bootloader using avrdude and not touching fusebits, or to first burn bootloader using IDE and then to use avrdude to set fusebits to the required value using an external clock source.

Nice to hear that it works. :slight_smile:
This extension of ISP sketch is well known here on forum and the problem with the fuses also. Yes, the MCU is bricked because of setting of the fuses. The MCU doesn't start after reset since the external clock signal or crystal is expecting.
However, one thing which confuses me is that you was able to read signature bytes correctly in one case at least. It should read only zeroes because the MCU couldn't respond, according my experience. It is new for me.

P.S.: I appreciate that your willingness to announce the solution which helped you. Have a karma for this. Your first. :slight_smile:

Budvar10:
one thing which confuses me is that you was able to read signature bytes correctly in one case at least. It should read only zeroes because the MCU couldn't respond, according my experience. It is new for me.

That's what confused me as well. If it were not working regardless of the baud rate the situation would be much more clear.