How to program ATtiny2313, given an Arduino Duemillanove

Hi,

Is it possible to program an ATtiny2313 using an Arduino Duemillanove ? Or must I buy a programmer for sure.

Regards,
f74

Hi,

falcon74:
Is it possible to program an ATtiny231[3] using an Arduino Duemillanove ?

Yes.

Or must I buy a programmer for sure?

No.

Thanks. Reading up, I see that Arduino itself can be used as an ISP, but on the ArduinoISP tutorial page it says that this can be done only on another Arduino board, that too when the target is either ATmega168 or ATmega328.

Wondering if this method works for ATtiny2313 (and say ATtiny45 which I am about to order), and on a breadboard ? Most of the articles I found about Arduino and ATtiny2313 are about using Arduino on ATtiny2313, but not much on how to use an Arduino board to program ATtiny2313.

Take a look at this

http://hlt.media.mit.edu/?p=1229

Thanks Erni. That project does seem extremely relevant, but reading through it, and some comments around it, I get the impression that it is for attiny45/85 only, and does not support attiny2313.

Given that in spite of both being from attiny series, they seem to have fair bit of differences in terms of peripheral integration, and of course, no. of pins, I wonder if I shouldn't be looking for instructions pretty specific to attiny2313.

Which Arduino IDE version are you using?

Predominantly Arduino-022, but I also have Arduino-1.0 !

What I was hoping to achieve was --

  1. Use ArduinoISP to program the ATtiny2313 with native C (non-Arduino) programs.
  2. Use ArduinoISP to program the ATtiny2313 with Tiny-Arduino.

Start with these...

Download the Tiny Core and install it under Arduino 0022. Instructions are available in the readme.txt file. Finish by running the Arduino 0022 IDE. Are there board options available for the ATtiny2313 processor?

I think you can program any atmel based part with an Arduino. Works nicely on an attiny13 and I would assume it would work for others.

Thanks. Did that, and yeah, I did mean 'Arduino-tiny'. Following the Readme.txt steps, I find that I have these board options in IDE:-

  • ATtiny2313 @ 8MHz
  • ATtiny2313 @ 1MHz

however, in case of ATtiny85 I see such options, which I don't in case of ATtiny2313, like

  • ATtiny85 @ 16MHz (external crystal; 4.3V BOD)
  • ATtiny85 @ 8MHz (internal oscillator; BOD disabled)
  • ATtiny85 @ 1MHz (internal oscillator; BOD disabled)
  • ATtiny85 (w/UWB Tiny as ISP)
  • ATtiny85 (w/Arduino as ISP)

So, I am guessing that the 2 options I do see for ATtiny2313 translate to the ATtiny2313 with the fuse bits set to use internal oscillator at 8MHz or 1MHz respectively, but not clear if I can use ArduinoISP to program it. If so, how should I do it ? Do I need to edit some configuration files manually ?

Also, how can I (& should I) burn the bootloader on ATtiny2313 ? If so, should it be via 'Arduino as ISP' ?

Thanks

falcon74:
So, I am guessing that the 2 options I do see for ATtiny2313 translate to the ATtiny2313 with the fuse bits set to use internal oscillator at 8MHz or 1MHz respectively

Exactly.

Do I need to edit some configuration files manually ?

Nope.

Also, how can I (& should I) burn the bootloader on ATtiny2313 ?

I have no idea if a bootloader is available for the ATtiny2313. I suggest not bothering with a bootloader for the ATtiny processors.

The next step is to prepare your Duemilanove to act as an In System Programmer (ISP)...

  • Disconnect your Duemilanove from the computer
  • Ensure nothing is connected to your Duemilanove
  • Connect an LED and series resistor to pin 9
  • Connect the Duemilanove to your computer
  • Start the Arduino IDE
  • Load the ArduinoISP sketch from the Files / Examples menu
  • Ensure the correct board and serial port are selected
  • Upload the ArduinoISP sketch to your Duemilanove
  • The LED on pin 9 should fade on then off
  • Disconnect your Duemilanove from the computer
  • Connect a 120 ohm resistor between 5V and RESET
  • Reconnect your Duemilanove to the computer
  • Ensure the LED on pin 9 still fades on then off

Your Duemilanove is now a programmer.

This is the wiring for programming an ATmega328 board or processor...
http://arduino.cc/en/Tutorial/ArduinoISP

Wiring is fairly easy to remember...

MISO to MISO
MOSI to MOSI
SCK to SCK
SS (on the programmer / Duemilanove) to RESET
GND to GND

When I get up tomorrow I'll post some pictures for wiring the ATtiny2313.

Thanks. That's really great. I went ahead and tested the LED fading on pin#9 with ArduinoISP, and also set the resistance between RESET and 5V, and wired up the ATtiny2313 to the Arduino link this --

Arduino ATtiny2313
Pin 13 <==> Pin 19 (SCK)
Pin 12 <==> Pin 18 (MISO)
Pin 11 <==> Pin 17 (MOSI)
Pin 10 <==> Pin 1 (CS / Reset)

However, the ArduinoISP tutorial at arduino.cc goes on the explain how to burn the bootloader, but that is for the ATmega168 assumed.

At that stage, I think Arduino is setup as an ISP for the ATtiny2313 on breadboard, but I'd have to use WinAVR to compile a native-C (not Arduino) ATtiny2313 program, and upload using avrdude. I am planning to try this shortly.

However was wondering if is there a way to program ATtiny2313 using Arduino IDE while using Arduino board as ISP ? While not sure if the current option that I see in IDE i.e. ATtiny2313 @ 8MHz is the one to be used, I went ahead and set it up as the target board, and then did the Burn Bootloader with w/ Arduino as ISP, as mentioned in another post here, to setup the lock bits. Finally I modified the BlinkWithoutDelay sketch to change pin#13 to #1, compiled and uploaded, which seemed to work, because the ArduinoISP 'Heartbeat' pin is continuing to blink slowly, and also another LED I added to pin#7 of Arduino which is supposed to show the programming activity of ArduinoISP, does blink rapidly during upload. I don't get any error messages in IDE, but LED attached to pin#1 of ATtiny2313 (via a 2.2K resistor) doesn't glow or blink.

Okay, got everything working now. My LED (connected to ATtiny2313) wasn't blinking because I was connecting it to the incorrect Pin#1. Once I found the PIN mapping from the pins_arduino.h file, it worked like a charm. Thanks so much 'Coding Badly'.

So just to clarify for people who might face somewhat similar confusion (having read a boat-load of other 'dated' articles) that I had, in case of ATtiny2313, 'Arduino-Tiny' is all that is needed. No manual configuration, file-editing etc.

So, at high level here are the steps:-

  1. Set up Arduino as ArduinoISP as described by 'Coding Badly' in this thread. (The RESET <--> +5V resistance value is critical. Make sure it is between 110-124Ohm. I did mine as 100+10+10=120Ohm. Without that the gig won't work. Again, this was found from another article). At every step, I make sure that the 'heartbeat' LED attached to Arduino board pin#9 (as mentioned by 'Coding Badly') is gently fading-in/fading-out. Also, having a LED connected (via 470R resistor) to pin#7 of Arduino blinks rapidly when ArduinoISP is being used to program the ATtiny2313.
  2. Wire up Arduino and ATtiny2313 using the pin numbering that I provided earlier (which I found from another article)
  3. Now, I wanted to run ATtiny2313 at 8MHz (instead of 1MHz as is the factory default, given the default fuse-bits), so I selected the Board as attiny2313 at 8MHz from within Arduino IDE, and then did Burn Bootloader i.e. w/ Arduino as ISP option. This actually doesn't burn any bootloader, but sets the fusebits to run ATtiny2313 at 8MHz using it's internal oscillator (no crystal mode).
  4. Finally, I loaded the standard Arduino BlinkWithoutDelay sketch, modified ledPin to 1 (from 13), and connected a 470R resistor + 3mm LED to pin#1 (physical pin mapping is presented in my previous post).

And voila. It takes a second or two for the LED connected to ATtiny2313 to start blinking.

Just to make sure everything is working, I remove the ATtiny2313 and take it to another breadboard, just feeding it power/ground, and reconnected just the LED+resistor, and yes, it does continue to blink.

PS> If the step#3 above is skipped, i.e. ATtiny2313 is allowed to run at 1MHz, the blink rate slows down (obviously by a factor of 8). I did try it for confirmation.

kinda offtopic but shouldnt the led blink the same regardless of the clock frequency ?

@putyn, you are right. It certainly should blink at same rate, since the millis() implementation should take the current clock settings into account and report after adjusting. To confirm this, I changed the clock to 1MHz and retested, and the LED does blink same as earlier.

Thanks for correcting.

You are better off using avr-gcc and avrdude directly when programming an attiny.

Excellent! I'm glad you have it working.

smeezekitty:
You are better off using avr-gcc and avrdude directly when programming an attiny.

Why?

@smeezekitty
well you are already using both of them :stuck_out_tongue: cause even if your using arduino ide or other ide youll compile your code with avr-gcc same for avrdude even if you use the bootloder or not you still need avrdude
probably you meant programming the attiny in C but why , as Coding Badly asked, not sure what youll gain :slight_smile:

I wasn't even aware that the Arduino IDE could program non arduino-like boards until recently.
The boards.txt is not very flexible in built parameters.
Also, if you need to program both the Arduino and attiny on a regular basis, that would equate to alot of board switching.