I programmed my first Atmel ATTiny2313 today. Of course this was a blinking led program.
I used the following code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRB |= 1<<PB0; /* set PB0 to output */
while(1) {
PORTB &= ~(1<<PB0); /* LED on */
_delay_ms(100);
PORTB |= 1<<PB0; /* LED off */
_delay_ms(900);
}
return 0;
}
This will blink a led if it’s connected to PB0 (or pin 12 on the microcontroller).
To program the chip I used the avrdude
program. I use the following
commandline:
avrdude -p t2313 -c avr910 -P /dev/ttyUSB0 -e -U flash:w:blink.hex
The programmer that I used is the MySmartUSB programmer. This works on Linux,
the drivers were already compiled in my kernel. When I connected the
programmer, dmesg
showed me that it worked.
The MySmartUSB programmer has a 10 pin avr connector for programming microcontroller. This means you need an extra board that has the pins for the chip. I created one myself. This is not that hard. The only thing you need is a pinheader (10 pins) a IC foot (I used 20 pins, as I was programming a ATTiny2313) and a few wires.