Tag Archives: arduinoISP

Programming ATtiny13 using Arduino ISP (and all the hacking involved!)

I recently came across MIT’s high low tech lab and was immediately drawn into their tutorial that allowed using Arduino Uno (and older versions) to be used to program ATtiny boards. The steps were simple and they had already updated their tutorial for Arduino 1.0 release (making it even more simpler). I couldn’t wait to try this out (especially since a lot of my projects barely require more than a couple of pins) and immediately went to sparkfun to order the ATtiny85 that they support.

I was already eyeing the Magic Chassis (discussion for another post) for some time and decided I would club them together. The Magic Chassis was quickly running out and ATtiny85 were already in backorder. Being an impatient person, I decided to order the ATtiny13 and try and hack the existing setup to make it work.

With the Arduino 1.0 IDE out, the new tutorial on the website is all the more simpler and only required modifying 2 files. You can access these changes from the github https://github.com/tekstop/attiny/tree/Arduino1 (Arduino1 branch).

The instructions are the same as those on the MIT high-low tech lab’s tutorials and the only real change required was adding this board to the boards.txt file. To do this, all I needed to do was look into a couple of datasheets and understand what the different settings really meant. This was the first time, I was really going into fuses and clk registers and it was pretty interesting and straight forward. My methodology in hacking this was:

Check the value of the fuse bytes in boards.txt for an existing mcu and find the values of the actual bits by going through the datasheet. The next part was just insuring that I set similar bit values for the ATtiny13 mcu. This was quite interesting especially with choosing the internal clock (9.6 Mhz) and prescaler options available.

Because the internal clock of the ATtiny13 is quite different from ATtiny85, the Software Serial library (only supports 8,16 or 20 MHz) will not work with ATtiny13 (9.6 MHz clock).

The pins_arduino.h file did not need to be touched as the pinouts for the tiny8 are the same.

With just these changes, I was ready to test my Arduino programmer.

1) Programmed the ArduinoISP sketch on my Arduino Duemilanove.
2) Copied the Github into the Arduino Sketch folder
3) Choose my Board from the IDE, selected the programmer as Arduino and connected pins as explained in the tutorials.
4) Burn the boot loader (one time). {It worked, gave some benign BS2 warning that can be safely ignored}
(At this point I was giddy with excitement, because nothing works on the first go, right!!!)
5) Chose the Blink sketch and wham uploaded it on to the board (success!)

And then reality struck! My LED didn’t blink! It just stayed on!. I reversed my commands and now saw that the LED stayed off, which gave me hope that at least something was being programmed correctly.

20111230-012614.jpg

My experiments showed that there was something wrong with the delay/millis commands. Normal read/write operations were running fine. Ofcourse, this prompted me to check my fuse values for the Clock [which seemed correct and changing them had no effect].

At this point, I started investigating the actual C code for delay and mills functions. Looking at the code in hardware/arduino/cores/arduino/wiring.c, I saw this line in code that seemed suspicious.


#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
SIGNAL(TIM0_OVF_vect)
#else
SIGNAL(TIMER0_OVF_vect)
#endif

I then further dug into the actual header file for the attiny13 (iotn13.h) to find that the interrupt macro for timer overflow for attiny13 was TIM0_OVF_vect and not TIMER0_OVF_vect. My Timer was not reporting the overflow and hence my timing functions were not working (This seems like an actual bug in the arduino 1.0 IDE). The fix is just adding an additional OR condition:


#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || (__AVR_ATtiny13__)
SIGNAL(TIM0_OVF_vect)
#else
SIGNAL(TIMER0_OVF_vect)
#endif

This shouldn’t affect anything else and making that fix has my LED blinking correctly!

20111230-012837.jpg