Teensy 2.0 as AVR ISP programmer

By: breedx

2012-01-12 20:47:50

Intro

Hi. I'm going to try and capture my process of turning the Teensy 2.0 into an AVR ISP programmer. That is, I just want to use the Teensy 2.0 as a means of programming other AVRs (in this case an ATTiny45) via USB. There be dragons. And hopefully we can slay them as I document enough. In my environment, I'm using 64-bit Debian (unstable).

Schematic

Using the Teensy 2.0 pinout: and the ATTiny45 pinout reference: ...we draw the following simple circuit: Please use this table for the connections:
Tiny   Teensy
----   ------
 1      B0
 2      (no connection)
 3      (no connection)
 4      GND
 5      B2
 6      B3
 7      B1
 8      VCC
Some notes:

The Hardware

So then we build it. We pull out a breadboard, connect up power and ground, and add the Teensy and ATTiny45. We then make the above mentioned connections. We think it looks good when it looks something like this:

Trust nothing!

Because we're cynical skeptics, we check all connections with our meter.... Vcc...OK! Ground...OK! SCK...OK! MISO...OK! MOSI....OK! SS/RESET'....OK! Looks ok so far. All 5 connections look to be ok. :)

Initial Environment

udev devices/permissions

Let's set up the environment. We understand that plugging in a Teensy requires us to have some udev rules set up, so we grab the latest version from PJRC:
$ wget http://www.pjrc.com/teensy/49-teensy.rules --2012-01-12 22:10:19-- http://www.pjrc.com/teensy/49-teensy.rules Resolving www.pjrc.com (www.pjrc.com)... 67.19.59.50 Connecting to www.pjrc.com (www.pjrc.com)|67.19.59.50|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1804 (1.8K) [text/plain] Saving to: `49-teensy.rules' 100%[=========================================================================>] 1,804 --.-K/s in 0.001s 2012-01-12 22:10:20 (1.35 MB/s) - `49-teensy.rules' saved [1804/1804] $ sudo mv 49-teensy.rules /etc/udev/rules.d/
Please note that this grants 0666 (global readability/writability) to the device, and may be (an unlikely) security concern in your environment. We then restart udev to make sure it sees the changes:
$ sudo /etc/init.d/udev restart Stopping the hotplug events dispatcher: udevd. Starting the hotplug events dispatcher: udevd.

The Software

Arduino

We need the arduino software, so we go to the arduino site and grab the latest version:
$ wget http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz --2012-01-12 22:21:09-- http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz Resolving arduino.googlecode.com (arduino.googlecode.com)... 74.125.127.82 Connecting to arduino.googlecode.com (arduino.googlecode.com)|74.125.127.82|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 4351508 (4.1M) [application/x-gzip] Saving to: `arduino-1.0-linux64.tgz' 100%[===========================================================================================>] 4,351,508 308K/s in 17s 2012-01-12 22:21:26 (248 KB/s) - `arduino-1.0-linux64.tgz' saved [4351508/4351508]
And then we extract the tarball:
$ tar -xzf arduino-1.0-linux64.tgz

Teensyduino

In order to program for and to program the Teensy, we need Teensyduino, a software add-on to the Arduino IDE. We download the latest version from PJRC:
$ wget http://pjrc.com/teensy/td_107/teensyduino.64bit --2012-01-12 22:27:49-- http://pjrc.com/teensy/td_107/teensyduino.64bit Resolving pjrc.com (pjrc.com)... 67.19.59.50 Connecting to pjrc.com (pjrc.com)|67.19.59.50|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2780140 (2.7M) [text/plain] Saving to: `teensyduino.64bit' 100%[===========================================================================================>] 2,780,140 309K/s in 11s 2012-01-12 22:28:00 (254 KB/s) - `teensyduino.64bit' saved [2780140/2780140]
make it runnable:
$ chmod 755 teensyduino.64bit
and then we install it by running it:
$ ./teensyduino.64bit
sadly it's a graphical installer, so we get to click through some screens: Click next: Enter in the path where you extracted the Arduino IDE (above): Click All (it's small and hard drives are big), then Next: After the progress bars flutter, you should see a screen like this:

Installing the ArduinoISP firmware

Crank up the circuit by plugging a mini USB cable into the Teensy on the breadboard (the other end goes into the computer) Launch the arduino IDE:
$ /home/jason/prog/atmel/arduino-1.0/arduino
And then choose File -> Examples -> ArduinoISP from the menu. Click on the "upload" icon to compile the project and upload the firmware to the Teensy: the ArduinoIDE/Teensyduino will launch the Teensy loader. It will display some stuff (loading/reboot ok) before showing the default loader screen: At this point, the Teensy should now be running the ArduinoISP firmware and should be capable of programming an ATTiny45 (and a bunch of others!) To be very sure, we wire an LED and 3k resistor up to pin 11 (PC6) on the Teensy. When the ArduinoISP firmware is running, it kinda throbs in a slow heartbeat pattern. GREAT SUCCESS! So far we think we're good.

Let's Program the Tiny45 - Take 1

Since the original goal (if you've forgotten by now) was to program the ATTiny45, let's try doing that. We compile a small program for the Tiny45 (using avr-gcc, documented elsewhere) and attempt to upload the .hex file using avrdude:
$ avrdude -p t45 -c arduino -P /dev/ttyACM0 -U flash:w:servo.hex:i avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45 avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.04s 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: please define PAGEL and BS2 signals in the configuration file for part ATtiny45 avrdude: reading input file "servo.hex" avrdude: writing flash (204 bytes): Writing | | 0% 0.00s avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x11 avrdude: stk500_cmd(): programmer is out of sync
The above text in red indicates that we have failed. I wonder if we can read the contents of the Tiny45?
$ avrdude -p t45 -c arduino -P /dev/ttyACM0 -U flash:r:/tmp/dump.hex:i avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45 avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.04s avrdude: Device signature = 0x1e9206 avrdude: reading flash memory: Reading | ################################################## | 100% 6.24s avrdude: writing output file "/tmp/dump.hex" avrdude: safemode: Fuses OK avrdude done. Thank you.
Yes, it appears as though we can read the tiny45 using avrdude just fine (even though the contents of the dump just show that it's been erased). WTF.

Footnotes

TBD

References

http://provideyourown.com/2011/arduino-program-attiny/ http://hlt.media.mit.edu/?p=1229 http://hlt.media.mit.edu/?p=1695 http://code.google.com/p/arduino-tiny/issues/detail?id=34 http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/
Back to archive index