Go Down

Topic: Mega 2560 as ISP for ATTiny (Read 6323 times) previous topic - next topic

kwilson68

For the past few days, I have been trying unsuccessfully to program an ATTiny45 AVR using an Arduino Mega 2560 as the ISP. All of the tutorials I have seen for using the Arduino as an ISP use the Uno and the Duemilanove. None of them mention the Mega2560.

I was wondering if something in the wiring or programming needed to be changed when using the Mega2560. For example, is a capacitor used between reset and ground? Or should a resistor connect reset to 5V? Before I started posting my specific error messages, I thought I would check to see if the problem was a simple difference between Uno/Duemilanove and Mega2560 setup.

Nick Gammon

Now this sounds familiar. Try reading this:

http://arduino.cc/forum/index.php/topic,99432.0.html
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

kwilson68

#2
Apr 05, 2012, 09:43 am Last Edit: Apr 05, 2012, 08:59 pm by kwilson68 Reason: 1
Thanks for pointing me in that direction. I had searched the forums for an answer all last week, but didn't post my question until this week. In the intervening time, that other thread answered my main question.

I have changed the MISO, MOSI, etc. to the correct pins for the Mega2560. This improved the situation to a degree. At least now the error messages are consistent.

When I try to burn the bootloader to the ATTiny45 @ 8 MHz, I get the error stk500_initialize(): programmer not in sync, resp=0x15. The same error occurs trying to burn the bootloader as an ATTiny45 @ 1 MHz. When I try to upload a sketch with the board set to the ATTiny at either 1 MHz or 8 MHz, I again get the same error.

I have tried changing the baud rate from 19200 to 9600, but that hasn't helped.

I am using the ArduinoISP for the programmer, and I have a 10uF capacitor between +5V RESET and GND to stop the Arduino from resetting.

Any thoughts on what might be causing this?

Coding Badly

#3
Apr 05, 2012, 10:13 am Last Edit: Apr 05, 2012, 07:14 pm by Coding Badly Reason: 1
Any thoughts on what might be causing this?


Yup...

Quote
I am using the ArduinoISP for the programmer, and I have a 10uF capacitor between +5V and GND to stop the Arduino from resetting.


Capacitor is connected to RESET and +5V (not GND) and GND.  Be sure to get the polarity correct.

kwilson68

Sorry, I meant to say that I had the capacitor between RESET and GND.

Are you sure that the capacitor should be between RESET and +5V? The tutorials I have seen have said that the capacitor goes from RESET to GND. Some also suggest that a 120ohm resistor between RESET and +5V would work as well. One thread on the old forum even mentioned connecting both.

This is why I was unsure about the wiring for using the Arduino as an ISP. Can you confirm that the capacitor should go from +5V to RESET? You also mentioned getting the polarity correct. I would assume the negative lead goes to RESET, but correct me if I am wrong.

I appreciate your help. I have a lot of experience with programming, but I am new to playing with electronics.

Coding Badly

Sorry, I meant to say that I had the capacitor between RESET and GND.


Oh rats!  The capacitor goes between RESET and GND.  I apologize for the mistake.

Quote
Some also suggest that a 120ohm resistor between RESET and +5V would work as well. One thread on the old forum even mentioned connecting both.


I've read those things as well.  I suggest trying: capacitor, resistor, then both.  The goal is to disable auto-reset.  If it looks like the board resets when an upload starts then try a different method.

I also suggest an LED (and series resistor) on pin 9.  A "heartbeat" should always be present.

kwilson68

I have now added a 110ohm resistor between +5V and RESET and a 10uF capacitor between RESET and GND. With this configuration, I still get the message:

Quote
avrdude: stk500_initialize(): programmer not in sync, resp=0x15
avrdude: initialization failed, rc=-1


Despite this error, the IDE says that it has finished uploading. Before, the bar above the serial window in the IDE was turning orange and reporting an error, so I am counting this as a small step in the right direction. But I still get that error when trying to burn a bootloader (i.e., set the clock fuses) on the ATTiny45.

I have had a heartbeat on Pin 9 the whole time, and it is pulsing fine. It continues pulsing through the entire process of uploading the script. I just added error and communication LEDs on 8 and 7 respectively. They pulse twice when ArduinoISP is started (or reset), but do not come on at all during the programming of the ATtiny45.

Here is the initial avrdude output, in case that tells you something:


Code: [Select]
         Using Port                    : \\.\COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 9600
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
         AVR Part                      : ATtiny45
         Chip Erase delay              : 4500 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         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                 :


Just to see what would happen, I removed the wires connecting the MOSI and MISO on the Mega2560 with those on the ATTiny45. I got the exact same error as before, so I suspect the Mega is not even getting to the point of communicating with the ATTiny45.

Thanks for your help.

Nick Gammon

It looks to me like it received the part number, so, so far so good.

Is the ArduinoISP designed for the Attiny45? I don't know for sure whether it is or not.

For around $22 you could order the USBtinyISP device and use that. It might save some pain.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Coding Badly

Is the ArduinoISP designed for the Attiny45?


I can confirm that it works with ATtiny45 processors.

Coding Badly

Quote
Overriding Baud Rate          : 9600


Did you change the ArduinoISP sketch to 9600 baud?

kwilson68

Did you change the ArduinoISP sketch to 9600 baud?


Yes. One of the tutorials said the Arduino IDE 1.0 reduced the buffer size and recommended reducing the baud as well to avoid overflowing the buffer.

For around $22 you could order the USBtinyISP device and use that. It might save some pain.


Believe me, I have seriously considered it at several points. But given that the Arduino is supposed to be able to do this and a number of people have gotten it to work, I'm determined to make it work myself.

Nick Gammon

Try using avrdude with -vvvv option to see just how far through it gets.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

kwilson68

#12
Apr 06, 2012, 02:11 am Last Edit: Apr 06, 2012, 02:14 am by kwilson68 Reason: 1
Here is the output with it set to verbose:

Code: [Select]
Binary sketch size: 756 bytes (of a 4096 byte maximum)
C:\Program Files (x86)\arduino-1.0\hardware/tools/avr/bin/avrdude -CC:\Program Files (x86)\arduino-1.0\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pattiny45 -cstk500v1 -P\\.\COM3 -b9600 -Uflash:w:C:\Users\Kevin\AppData\Local\Temp\build6208833073255571373.tmp\ModifiedBlink.cpp.hex:i

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
        Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
        Copyright (c) 2007-2009 Joerg Wunsch

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

        Using Port                    : \\.\COM3
        Using Programmer              : stk500v1
        Overriding Baud Rate          : 9600
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
        AVR Part                      : ATtiny45
        Chip Erase delay              : 4500 us
        PAGEL                         : P00
        BS2                           : P00
        RESET disposition             : possible i/o
        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     6     4    0 no        256    4      0  4000  4500 0xff 0xff
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          flash         65     6    32    0 yes      4096   64     64  4500  4500 0xff 0xff
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                 Block Poll               Page                       Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

        Programmer Type : STK500
        Description     : Atmel STK500 Version 1.x firmware
avrdude: Send: A [41] . [80]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [02]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [81]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [98]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
        Hardware Version: 2
        Firmware Version: 1.18
        Topcard         : Unknown
avrdude: Send: A [41] . [84]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [85]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [86]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [87]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [89]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
        Vtarget         : 0.0 V
        Varef           : 0.0 V
        Oscillator      : Off
        SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [01] . [00] . [00] . [00] . [10] . [00]   [20]
avrdude: Recv: . [15]
avrdude: stk500_initialize(): programmer not in sync, resp=0x15
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [01] . [00] . [00] . [00] . [10] . [00]   [20]
avrdude: Recv: . [15]
avrdude: stk500_initialize(): programmer not in sync, resp=0x15

**********[deleted]**********

avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [01] . [00] . [00] . [00] . [10] . [00]   [20]
avrdude: Recv: . [15]
avrdude: stk500_initialize(): programmer not in sync, resp=0x15
avrdude: initialization failed, rc=-1
        Double check connections and try again, or use -F to override
        this check.

avrdude: Send: Q [51]   [20]
avrdude: Recv: . [15]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: Q [51]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]

avrdude done.  Thank you.


The [deleted] section above merely repeats
Code: [Select]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [01] . [00] . [00] . [00] . [10] . [00]   [20]
avrdude: Recv: . [15]
avrdude: stk500_initialize(): programmer not in sync, resp=0x15

over and over again (roughly 30 times), until it eventually spits out initialization failed, rc=-1 and gives up.



Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Coding Badly

Code: [Select]
        Hardware Version: 2
        Firmware Version: 1.18


That is a response from ArduinoISP.  Up to that point, everything is in good order.

If auto-reset was firing, the bootloader would run and potentially respond (but probably not at 9600 baud).  We would expect something like this for a response...

Code: [Select]
        Hardware Version: 3
        Firmware Version: 3.3



Code: [Select]
avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [01] . [00] . [00] . [00] . [10] . [00]   [20]
avrdude: Recv: . [15]


Everything up to that point appears to be correct.  fill consumes the 20 bytes and then checks for a space (0x20).  It blocks until a character arrives.  As far as I can tell, there are only two possibilities: 1. The space was corrupted; 2. The two sides are hopelessly out of synchronization.  Unfortunately, the evidence indicates that neither is true.


It's time for black-box probing: How does it behave when the baud rate is 19200?

Go Up