Help! Set up ArduinoDue as ISP for use with avrdude

Hello, everyone. :3
I'm trying to use my ArduinoDue as programmer for external micronontrollers (attiny2313, to be exact). Technically this chip should be able to work on 3.3V, so I'm using no level translators or voltage converters, which simplifies the task (and I don't know how to do it yet anyway ._.).
I've googled it up and did what I could, but it just doesn't work. And now I'm desperate for help.
The first thing I did is loading the ArduinoISP on the Due, only to see it refusing to compile with errors. So I used modified sketch from this topic, and this time uploading succeeded. I've also connected the output leds, so now I can see it is heartbeating. However, whenever I try to connect to ATTiny2313 with avrdude, I receive following errors:

"avrdude -c avrisp -p t2313 -PCOM3 -b19200" -> "stk500_getsync(): not in sync: resp=0x00"
"avrdude -c arduino -p t2313 -PCOM3 -b19200" -> big delay, blinking leds, then "stk500_getsync(): not in sync: resp=0x00".

When I try to use "arduino" as avrdude programmer (example 2), it seems to be resetting, judging by the blinking pattern. I've also tried both native and programming port, with same results... uh-oh.

Update: when I was writing previous sentence and, in parallel, trying to make this thing work, I suddenly leaped forward. Now, finally, avrdude does succesfully recognizes Due (connected to native port). It doesn't reset, happily sees it as a programmer, but... now it says that my chip has an invalid signature:

Device signature = 0xffffff
Yikes!  Invalid device signature.
Double check connections and try again, or use -F to override
this check.

I thought it was the wiring, but no. All the wires are connected right where they should, if the comment in the ArduinoISP.ino is correct.
What am I supposed to do? Should I use another sketch? Disable the reset somehow? Use some advanced technique of wiring?..
Thank you in advance. :3

P.S. Please, pardon my bad writing and some out-of-place phrases, I just don't know English that well to say things more directly and polite.

:bump:
I waited for a few days, but haven't got any response. Have I done something wrong? :frowning:

I think you will need to connect to the SPI header. I am assuming you connected the attiny VCC to 3.3V?

Yes, exactly! 3.3V should be enough, right? I recall minimum required voltage is about 1.1V or so.
I've also played around with the wires and noticed one strange thing. Sometimes, when I place ATTiny13A instead of 2313 and try to connect, it replies with exactly right signature! But just the next attempt to connect fails just like with 2313 ("Device signature = 0xffffff").
Which SPI header? You mean, one on the Due? Isn't that the one used to program it? Arduino sketch is set to bitbang mode, so... I'm not sure Due will use it's SPI header pins to connect to my microcontroller as a master.

I've also feared that the microcontroller was overloaded by too much current (I don't understand wiring that much, can anyone advise a good book please?) as wires were connected directly, without resistors. But things were the same even after I've connected all the signal wires through 4,7KOm resistors and grabbed a fresh new MC, in case one I've used got fried.

Nick Gammon's hex file program loader.

Gagalabs on programming a 2313 with Arduino, has the 2313 core files.

@deFazer: I have a pull request pending for the ArduinoISP improvements from the thread you mentioned. So with a little luck these changes will make it into an upcoming release of the IDE.

See Improve ArduinoISP sketch by PeterVH · Pull Request #3500 · arduino/Arduino · GitHub
You might want to try it, there is a zip file for windows near the bottom.

If you don't feel like downloading the whole thing, you can also grab just the sketch:

Especially since you post this question, I will add "programming ans attiny2313" to my test suite. I just tested it with a Due and it just works fine.

I tested with linux, windows should work too, but I will test that too as soon is I downloaded it.

I compiled a blink program using CodingBadly's tiny core, and simply downloaded it using the ide 1.6.4.

Which SPI header? You mean, one on the Due? Isn't that the one used to program it?

Yes that one. No it is not used to program it is should be seen as an SPI header for interaction with external peripherals. Use it. Like in th eattiny85 picture here.

ISP (In System Programming) is done through the SPI (Serial Peripheral Interface) port.
Once the chip is bootloaded it can be programmed through serial port 0.

MIT on programming ATtiny45/85 with Arduino.

and here are the core files for the 2313

The 2313 can run at 3.3V, just not at full speed. But will the flash program at 3.3V? Try it.

Otherwise you need to level voltages on either side. You can wire up resistors or transistors or...
look for HCF4050 chips, they can convert 6 lines per chip.

But I would try programming the 2313 at 8MHz 3.3V on a breadboard first

The 2313 can run at 3.3V, just not at full speed. But will the flash program at 3.3V? Try it.

Otherwise you need to level voltages on either side. You can wire up resistors or transistors or...
look for HCF4050 chips, they can convert 6 lines per chip.

But I would try programming the 2313 at 8MHz 3.3V on a breadboard first

Don't unnecessarily add more uncertainty.

A new attiny is programmed to work at 1MHz internal oscillator. It programs fine at 3.3V, with ArduinoISP on the DUE. Just did that yesterday.

@PeterVH, thank you, but I don’t understand what do you mean. I’ve tried though to follow your advice and uploaded that sketch to my Due. But nothing changed, except now heartbeat LED doesn’t even blink.
AVRDude still says my chip has invalid signature, and I don’t follow which IDE are you talking about.
Arduino IDE? But I use it only to compile&upload Arduino sketches, 'cos I’m learning to use assembler and console non-IDE tools. Of course, if it is totally necessary, I’ll go for it, but there must be another way.
As I understand, Arduino board should simply imitate one of the programmers AVRDude already knows, like AVRIsp.
Right now my wiring is like this:
7 - Programming
8 - Error
9 - Heartbeat
10 - Reset
11 - MOSI
12 - MISO
13 - SCLK

However I have strong feeling I’m missing something important here.

EDIT: Also I should mention that I’m using ATTiny13 here, because in my case ATTiny2313 is wired up using SOIC-DIP converter, and it’s kinda uncomfortable to work with (at least while I’m just setting up the environment). There shouldn’t be any difference between connecting these two, should it?

Arduino IDE? But I use it only to compile&upload Arduino sketches, 'cos I’m learning to use assembler and console non-IDE tools.

Well, there are cores that allow you to write sketches for attiny as if it were an arduino, that is what I used to test programming hex files into the attiny2313…

Of course, if it is totally necessary, I’ll go for it, but there must be another way.

Not needed, just continue to use avrdude on the command line, it will work just as fine.

Your wiring is completely wrong. E.g. pin 13 is not the SCK pin on the Due. SCK is on the SPI header, verify that on the due pin diagram. Follow the link I sent you before (ArduinoISP on the Due) and have a look at the picture and the wiring diagram over there.

I have been thinking it may make sense to also support the old/classic style wiring (using pins 11 to 13 instead of the SPI pin header). There are shields around that use this wiring. With following modification, such shield become useable on a Due or Leonardo too.

If the old wiring is more practical for you, you may add following lines to the sketch:

after:

if defined(ARDUINO_ARCH_AVR)

#if SPI_CLOCK > (F_CPU / 128)
#define USE_HARDWARE_SPI
#endif

#endif

add this snippet:

// Uncomment following line to use the old uno style wiring
// (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due...
#define USE_OLD_STYLE_WIRING

#ifdef USE_OLD_STYLE_WIRING
#undef USE_HARDWARE_SPI
#undef MOSI
#undef MISO
#undef SCK
#define MOSI    11
#define MISO    12
#define SCK     13
#endif

I tested it, it works.

O.
My.
Freaky.
Goodness.

IT WORKS! IT FINALLY WORKS!!!
Oh thank you, thank you so much!
hugs @PeterVH really hard

I did compile a little blinky for ATTiny13 using this corrected sketch with hardware SPI, and now I watch in delight at it's beautiful, 5Hz on's and off's.
I don't quite understand some things for now, but it works. Really works! Yeehaw! ^^
Sorry if I'm little off the formal bounds, I'm just very happy.

Also I've discovered that /RESET pin is pulled up internally - so I don't need to power it up externally like I feared.

You should give Peter a karma point. Right Peter?

Uhm, yes. Thanks GoForSmoke, I don't dare to ask that myself.

@deFazer: I recognize the feeling, I still find it exciting.

Now it is a matter of making sure it keeps on working without damage to the Due. I never had problems but I make sure not to change wirings (e.g.connect the target) while powered. A buffer like GoForSmoke suggested would be much safer (and more practical since you can use 5V in the tiny...). I am going to solder one up, myself.

This is where that Nick Gammon hex loader project comes in, but only if you're going to burn chips often enough to make it worth it.

The stand-alone burn hex files from SD programmer.

One thing though. He shows an SD module that costs up to $15 (it says). I got some for less than $2 but I've been warned about the dodgy voltage-leveling. Simple fact is that you can make an adapter out of a micro-SD adapter sleeve that comes with most micro-SD cards. If your rig operates at 3V, you can solder directly to the sleeve contacts otherwise it needs IIRC 4 lines to be leveled which can be done about 6 different ways for less than $1 plus time and swearing... but it's good when it works.

That chip btw is the 74HC4050. I just checked dipmicro where I got some and all they have left are the SOIC (surface mount) packages left. I can't solder that still without burning it up!

There's a leveling trick where you put blocking diodes between the 5V and 3V and then pullups through 4.7K to the 3V side of each line. When the 5V side is HIGH, the 3V side gets 3V and when the 5V side is low it grounds the 3V pullup, voltage is leveled from 5V to 3V. Where you have 3V output to 5V input you can usually go direct.

Uhm, yes. Thanks GoForSmoke, I don't dare to ask that myself.

Never ask for love either, both are poor form. But you deserve one (hell, I'll do it) and the newbie probably hasn't a clue as to what that's about and won't be able to find you once learned.

Down at The Bar one person asked about karma and an old head put it that you can give solid help to 20 members and maybe get 1 point. But I've seen other times with maybe 5 in one week!

GoForSmoke:
You should give Peter a karma point. Right Peter?

PeterVH:
Uhm, yes. Thanks GoForSmoke, I don't dare to ask that myself.

Absolutely! [clicks [add], gives a karma point]
I don't know exactly what it is, but I've noticed the link earlier, and I guess it is sorta of forum reputation.
You totally deserve it.

This is where that Nick Gammon hex loader project comes in...

I am sorry, GoForSmoke, I don't see why that hex loader project would come in: sure you can safely wire up an sd card to a 3V3 mcu, but that mcu would still be connected to the attiny in the same way and you would have to take the the same measures to not damage the due.

Frankly, about that hex uploader (with all due respect to Nick Gammons work, I learned from a lot of his his write ups): I don't understand why you would want to:

1.take the sd card out of the 'programmer'
2.put it in your pc
3.mount it onto the pc (or do the windows equivalent)
4.copy the hex file to it
5.unmount it
6.put it back in the programmer

...each time you recompile the attiny sketch,
instead of just:

  1. hit 'upload sketch' in the ide.

I think that the uploader is more for small production work than prototyping.
I haven't built one yet because I'm still doing 1-offs mainly to test what I can do.

The other ways shown in this thread are okay, they work for us but it's a bit of a chore pulling out all the pieces and re-remembering and re-looking-up details to rebuild what gets used rarely anyway.