02 October 2008

My ATtiny2313 said "Hello World" !

Yes! Yes! Yes! What was I doing wrong?

I could initially program a HEX file into the chip, but that code was downloaded from Internet and probably meant for the older AT90S2313. I had rewritten and recompiled the same code with BASCOM-AVR for the ATtiny2313 but somehow I couldn't get the program into the chip: everything completed correctly, I could change fuse settings, but the CODE memory wasn't updated.

So I tried a -e (erase chip) round with avreal32. Reading the uC content resulted in a lot of F's: the chip was blank.

Then I wrote the code back and ... magic! The LED flashed. Remember: the ATtiny2313 (probably) comes pre-programmed to use the internal 8 MHz clock divided down by 8 to 1 MHz, so you don't need any external component.

This is the BASCOM-AVR code. Don't forget to play with GUI settings to set the proper chip.


Config Portb = Output 'set port B as output

Do ' eternal loop
Portb.0 = 1 ' make portB.0 high
Waitms 500 ' wait 500ms
Portb.0 = 0 ' make Portb.0 Low
Waitms 500 'wait 500ms
Loop


Press F7 to compile. Take the .hex file and feed it to avreal32 (see previous post for the command line string).

The circuit? PortB.0 is pin 12 on ATtiny2313. Wire as follows:
  • pin 20 to +5V
  • pin 10 to ground
  • pin 12 to a LED cathode
  • LED anode to 270 ohm resistor (or 220, or 330 or 100+100+100 ohm, you got the pointt)
  • the other resistor terminal to +5V
Ready for the smoke test? :-)