Working With an ATtiny13
I've been wanting to play with 8-pin AVRs for awhile and finally got around to it.
Here's what's involved in downloading code to an ATtiny13 (and other AVR microprocessors for that matter). In this example, the ATtiny13 resides on a solderless breadboard for prototyping.
We'll use In-System Programming (ISP), a feature on all the AVR ATtiny and ATmega MCUs (as far as I know). It's a serial protocol, but unlike RS-232, there's a clock signal along with the TX and RX signals.
Link to more detail on JTAG ICE MkII Pinout
AVR's ISP cables have 6 pins: reset, clock (SCK), data to the chip (MOSI), data from the chip (MISO), as well as Vdd and GND. Here's the header pinout (the top view):
Here's the ATtiny13 pinout reproduced from the datasheet for educational purposes. Every AVR has MISO, MOSI, SCK and RESET pins, and obviously Vdd and GND.
You can use Pololu's inexpensive USB AVR programmer, PGM03A, as I did. It's a great programmer and I used the older version of it for a few years before upgrading. Plug the 6-pin ribbon cable into the programmer, then use jumper wires (I use these jumpers from hacktronics.com) to connect to the ATtiny on the breadboard.
Or, you can buy my ATtiny breakout with AVRISP header which makes prototyping really easy. Just insert the ATtiny on the board, plug in the AVRISP cable, add power and go!
The embedded programming version of hello world, as you probably know, is blinking an LED. We'll cast off the fluffy, protective blanket of Arduino and try this, AVR-style. It's not as easy, but it's not very hard either.
I decided to try AVRstudio 4 for the first time and Pololu has a tutorial on using AVRstudio with their programmer.
Programming the chip was fast and easy once I had powered it with a 9V battery (apparently the Pololu programmer doesn't actually supply Vdd but expects the board to provide Vdd to the programmer). Within half a second I had a blinking LED.
Note that I ran into ocassional glitches programming the ATtiny with the Pololu programmer. It may be some USB gremlins I've been fighting. Don't know. Try keeping the ATtiny13 clock speed up (9.6MHz, maybe even disable CLKDIV8) or reduce the programming speed. Since I happened to have just borrowed an AVR JTAGICE mkII, I quickly gave up on the Pololu programmer for now. The JTAGICE works almost flawlessly.
The ATtiny13 is about as constrained as you can get, with very little program memory or runtime RAM. Still, it's enough to do some simple programs and it does have a timer with PWM modes and a multi-channel ADC. You can do a lot with it. The form factor is, well, tiny, and the 8-pin AVRs are a great addition to the geek arsenal.
I plan to use the ATtiny13 for a simple project related to my newest hobby, RC planes. More on that soon.
Here's what's involved in downloading code to an ATtiny13 (and other AVR microprocessors for that matter). In this example, the ATtiny13 resides on a solderless breadboard for prototyping.
We'll use In-System Programming (ISP), a feature on all the AVR ATtiny and ATmega MCUs (as far as I know). It's a serial protocol, but unlike RS-232, there's a clock signal along with the TX and RX signals.
Link to more detail on JTAG ICE MkII Pinout
AVR's ISP cables have 6 pins: reset, clock (SCK), data to the chip (MOSI), data from the chip (MISO), as well as Vdd and GND. Here's the header pinout (the top view):
Or, you can buy my ATtiny breakout with AVRISP header which makes prototyping really easy. Just insert the ATtiny on the board, plug in the AVRISP cable, add power and go!
The embedded programming version of hello world, as you probably know, is blinking an LED. We'll cast off the fluffy, protective blanket of Arduino and try this, AVR-style. It's not as easy, but it's not very hard either.
#include <avr io.h>
#include <avr interrupt.h>
#include <avr sleep.h>
#include <util delay.h>
/** ATtiny13 hello world; blink LED on Pin 2
*
* Michael Shimniok - http://www.bot-thoughts.com
*/
int main(int argc, char **argv)
{
DDRB |= _BV(3); // PB3 (pin2) as output
while (1) {
PORTB |= _BV(3); // turn on LED
_delay_ms(500);
PORTB &= ~_BV(3); // turn off LED
_delay_ms(500);
}
}
I decided to try AVRstudio 4 for the first time and Pololu has a tutorial on using AVRstudio with their programmer.
Programming the chip was fast and easy once I had powered it with a 9V battery (apparently the Pololu programmer doesn't actually supply Vdd but expects the board to provide Vdd to the programmer). Within half a second I had a blinking LED.
Note that I ran into ocassional glitches programming the ATtiny with the Pololu programmer. It may be some USB gremlins I've been fighting. Don't know. Try keeping the ATtiny13 clock speed up (9.6MHz, maybe even disable CLKDIV8) or reduce the programming speed. Since I happened to have just borrowed an AVR JTAGICE mkII, I quickly gave up on the Pololu programmer for now. The JTAGICE works almost flawlessly.
The ATtiny13 is about as constrained as you can get, with very little program memory or runtime RAM. Still, it's enough to do some simple programs and it does have a timer with PWM modes and a multi-channel ADC. You can do a lot with it. The form factor is, well, tiny, and the 8-pin AVRs are a great addition to the geek arsenal.
I plan to use the ATtiny13 for a simple project related to my newest hobby, RC planes. More on that soon.



No comments:
Post a Comment