Jul 9, 2012

Getting ATTINY45 to work at 8MHz with Arduino-1.0.1 and USBtinyISP

Working on a project to get an IR remote to work with an ATTINY45. The stock '45 comes with fuses set for 1Mhz.
I had a problem with the remote codes not being recognized and needed a way to see exactly what was going on. ATTINY doesn't natively support SoftwareSerial, but you can include the library for that. Problem is, the lib wants to run at 8Mhz or above. There is a way to easily change the fuses so the '45 runs at 8MHz,  using the 1.0.1 IDE and an add-on mentioned by the Hi Low Tech Group of MIT (here).
Make SURE you get a version of the ATTINY download that contains the folders variants and boards.txt and place them in the folders mentioned in the Hi Low blog above. Start arduino-1.0.1.  On my Ubuntu system, I need to run the USBtinyISP under sudo, so I navigate to the folder the arduino program lives in and type in sudo arduino-1.0.1 from the command line to start the IDE. Plug in  the USBtinyISP and set it in Tools\Programmer. Follow the instructions on the blog to "Burn Bootloader" after choosing Tools\Board\ATTINY45 (internal 8MHz clock). This normally won't show the results of the fuse burning command. To verify the fuses are being burned, before running "Burn Bootloader",  under File\Preferences, check the box for "Show verbose output during    upload".
To get the fuses and program burned onto the ATTINY45 chip, I mount the chip on a small breadboard and attach the pins to the USBtinyISP like so (from Maarten Damen's blog):
  • ATtiny Pin 2 to USBTinyISP SCK
  • ATtiny Pin 1 to USBTinyISP MISO
  • ATtiny Pin 0 to USBTinyISP MOSI
  • ATtiny RST pin to USBTinyISP RESET
and +5v to Vcc. GND to GND.
Here are pinouts for the ATTINY45 and the USBtinyISP. The pinout shown is for the ATTINY25, which is the same as the '45/'85.


Attiny25-pinout


Adafruit_usbtinyisp_pinout_6and10pinstd

To show where the *.hex program is located after a compile, check the box in File\Preferences\"Show verbose output during compile". On my Ubuntu system, this is located in /tmp/buildnnn.tmp/program_name.cpp.hex (where nnn = some alpha-numeric identifier). I compile from the command line like so:
user@mybox:/tmp/build3204698977405188542.tmp$ sudo avrdude -c usbtiny -p t45 -U flash:w:program-name.cpp.hex
If everything went well, you should see something like this:
sudo avrdude -c usbtiny -p t45 -U flash:w:attiny45_serial_example.cpp.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9206
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "attiny45_serial_example.cpp.hex"
avrdude: input file attiny45_serial_example.cpp.hex auto detected as Intel Hex
avrdude: writing flash (3894 bytes):
Writing | ################################################## | 100% 11.50s

avrdude: 3894 bytes of flash written
avrdude: verifying flash memory against attiny45_serial_example.cpp.hex:
avrdude: load data flash data from input file attiny45_serial_example.cpp.hex:
avrdude: input file attiny45_serial_example.cpp.hex auto detected as Intel Hex
avrdude: input file attiny45_serial_example.cpp.hex contains 3894 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 7.21s

avrdude: verifying ...
avrdude: 3894 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done.  Thank you.













No comments:

Post a Comment