ATTiny10 Assembly IDE and Device Programmer

Caution: this project is still in the Alpha stage and I make no guarantees about how easily you'll be able to reproduce my work, or actually do anything useful with it.  I present it here as a work in progress that may, or may not be useful to you.

Update1: The assembler now support simple expressions, such as 1 << 2, label + 2, etc., as well as comma separated lists of  values in .dw and .dw expressions

Update2: I've found cases where the programmer can no longer program a device after PB3/RESET (pin 6) is configured as an output pin.  It seems to work fine to use PB3 as an input, however.  So, until I get this resolved, I recommend that you don't use PB3 as an output.

Update3: New version of ATinyIDE.app.zip (replaces ATinyIDE.app) to fix a reported problem with app not running on OSX Lion.

Update4: Fixed errors in programmer schematic to show correct connections to Arduino (A1-A5.)

Update5: New versions of ATinyIDE.app.zip and ATTiny10ProgrammerHV_PCB.pde (download below) include an automatic way to calibrate the ATTiny10's internal clock.  Details on how this works added in new "Automatic Clock Calibration" section.

Update6: If you are unable to select a serial port please try the suggestion in the "32/64 Bit Issues" section near the bottom of this page.

This project creates a complete IDE for coding in assembly language for the ATTiny10 and then programming it.  The complete system consists of the following components:
  • Stand alone assembly language IDE written in Java and bundled as a Mac OSX application, which includes:
    • One pass assembler (very minimal implementation, but usable)
    • Device programmer module (talks to programmer software running on the Arduino)
  • Arduino code for the programming shield
  • Hardware PCB for programming shield (does HV programming, so it can program all features and fuses.)
Why Would You Care About This?

Well, the ATTiny10 and it's siblings, the ATTiny 4,5 & 9, are the smallest and cheapest members of the AVR 8 Bit family.  The chips are enclosed in an SOT-23-6 package, which means they are really, really tiny.  And, purchased in units of 10, the little brother of the set, the ATTiny4, is only $.73.  That means they're so cheap you can almost sprinkle them around in your projects.  Need an LED that blinks in Morse code, use an ATTiny4 to drive it.  The ATTIny10, at $1.10 in units of 10, is still pretty cheap and you get twice as much program space as the ATTiny4 (1024 vs 512) and a 4 channel ADC, to boot.

Programmer Circuit

The programming circuit is adapted from my ATTiny Fuse Reset with 12 Volt Charge Pump project (note: Arduino connections are different, however, so the software from that project will not work with this board) but adds a 6 pin socket for plugging in an ATTiny10 device mounted on a SOT-23 to 6 pin DIP adapter board. The schematic for this adapter is shown next:


The parts list for this circuit (excluding the pin strips needed to plug the board into the Arduino) is, as follows:

 Description Quan Mouser Part #
 Price ea 
 Extd
 1N4148 Diode
4
771-1N4148,133
$.02$.08
 0.22 uFd Ceramic Cap
3
810-FK14X7R1H224K$.26
$.78
 2.2 ufd Ceramic Cap 1810-FK14Y5V1E225Z
$.25$.25
 10K 1/8 Watt resistor 1 299-10K-RC$.09
$.09
 1K 1/8 Watt resistor 5 299-1K-RC$.09
$.45
 510K 1/8 Watt resistor 1 299-510K-RC$.09$.09
 100K 1/8 Watt resistor 1 299-100K-RC$.09$.09
 2N3904 Transistor 1 512-2N3904TAR$.07$.07
 8 pin socket 1 649-DILB8P223TLF$.12$.12
 6 pin socket 1575-113306$.61
$.61
   Total 
 $2.60

The PCB layout for this circuit as shown next:


The circuit is simple enough to construct on an Arduino prototyping shield, but it's simpler to use the PCB I designed and which you can order directly from Sparkfun's BatchPCB service, using this link: ATTiny10Programmer.  The cost is $8, but it will take a few weeks to get, as the BatchPCB service is a "produce on demand" service where the board are fabbed in China and then sent as a batch to Sparkfun which, in turn, mails your portion of the order to you.

When assembled and attached to an Arduino, the finished PCB will look like this (notice the 6 pin DIP to SOT-23 adapter containing the ATTiny10 chip plugged into the 6 pin socket):

Note: the tiny black speck underneath the letters "ETT" is the ATTiny10

Special Notes:
  • When assembling the board, pay careful attention to the orientation of the 1N4148 diodes, as the cathode (side with the stripe) alternates with each diode placed.
  • Also, as newly manufactured PCBs can sometimes contain shorted, or open circuits, such as a short to the ground plane, I strongly suggest that you use the continuity tester function on a volt meter to check the board before assembling it.
  • The programmer is designed to work with a 5 volt Arduino, such as the Duemilanova, Diecimila, or Uno and not with the 3.3 volt variants.  This is because the ATTiny10 series requires 5 volt power for programming.
Arduino Code: the complete Arduino source code for the programmer is available here, or from the attachment section below.

ATTiny10 IDE and Assembler

The IDE I created to work with the programmer is a Java application packaged as an Mac OSX app which, when run, creates a window like this:


My idea was to create a simple way to type in ATTiny10 assembly code into the "Source Code" window, then using options in the "Actions" menu to build the code and then program it directly into a device plugged into the programming circuit.  However, before you can do this, you need to first do the following steps:
  1. Build the programmer circuit shown above and connect the shield to an available Arduino
  2. Launch the Arduino IDE, load the programmer code and download it into the Arduino
  3. Quit the Arduino IDE
  4. Download the ATTiny10 IDE (see attachments below)
Next, to program an ATTiny device, follow these steps (note: these instructions assume you have a working version of the Arduino 022 IDE already installed and working):
  1. Download and launch the ATTiny10 IDE (see ATinyIDE.app in attachments section)
  2. Attach the programmer shield to the Arduino (if not already attached)
  3. Select the Arduino board in the "Ports" submenu in the "Settings" menu
  4. Make sure 57600 is selected as the "Baud Rate" submenu in the "Settings" menu
  5. Insert an ATTiny10 device (mounted on an SOT-23 to 6 pin DIP adapter board) into the 6 pin socket
  6. Select the "Device Signature" option from the "Actions" menu to verify that the programmer sees the device (if not, see the troubleshooting section)
  7. Load the Blink.asm test program (see attachments below) into the IDE using the "Load" command in the "File" menu.
  8. Select "Build" from the "Actions" menu (this should select the "Listing" tab and display the assembled code, intermixed with HEX output
  9. If desired, click the "Hex Output" or the "Symbols" tabs to see this information
  10. Select "Program Device" in the "Actions" menu to write the code into the ATTiny10 device
  11. Remove the ATTiny10 header board from the programmer and put it on a breadboard where you have connected pin 2 to ground, pin 5 to a 3.3 volt power source, an LED anode to pin 4 and the other end of the LED to GND.  If the device was programmed successfully, the LED should blink rapidly.
Automatic Clock Calibration

The IDE now contains a "Calibrate Clock" option in the "Actions" menu.  To use this feature, you must have an Arduino with the programming shield attached connected (see above) and an ATTiny10 in the programming socket.  Then, simply select  "Calibrate Clock" and wait while the IDE download a small clock calibration program onto the ATTiny10 and runs a calibration sequence to determine the correct clock offset value.  When done, the calibration process will have printed text like this into the "Programmer" tab's text area:

Port /dev/tty.usbserial-A70064QX opened at 57600 baud
.......Done
Measuring clock........
Recommended Clock Offset: 0x95

The Recommended Clock Offset value is the value you can then use to adjust this particular ATTiny10's clock to as close to 8 MHz as the clock tweaking process will permit.  However, before this will wrk, you will need to add code to your ATTiny program's startup sequence to set this value using code like this:

ldi  r16, 0x95  ; Offset value
out  CCP, r16

Note: the calibration process will overwrite whatever code you have installed on the ATTiny10.  Also, the accuracy of the calibration process is dependent upon the accuracy of the Arduino's 16 MHz oscillator, so you may get better results using the clock calibration process I describe here.  Also, be aware that the calibration process needs to be repeated for each individual ATTiny10 IC, as the value needed to tweak the clock will vary from chip to chip.

Assembler Limitations

The assembler I wrote for the IDE is fairly crude, brute force affair and has a lot of limitations, but it's getting better with time.
  • Supports only a limited number of directives, such as:
    • .device attiny10 (must be attiny10, as IDE does not yet handle attiny4, attiny5, or attiny9 directives)
    • .fuses xx (where xx is a comma separated list containing "ckout", "wdton", or "rstdisbl")
    • .BYTE nn (where nn can be a hex, or decimal value)
    • .db nn
    • .dw nn
    • .CSEG
    • .DESG
    • .def temp = R16
    • .org 0
To test the assembler, I created a file that contains instructions for all the opcodes the assembler can process.  You can download this file, ATTiny10Asm.asm, in the attachments section below and examine the contents to see examples of the syntax it can handle.  Note: the assembler can easily be used for the other 3 devices in the ATTiny10 family, the ATTiny 4, 5 or 9, but the assembler will not warn you when you attempt to use features not supported by those chips.

In Circuit Programming?

Most of my work has been directed toward getting to know the capabilities of the ATTiny10 series, so working with the chips mounted on adapter boards (which I then plug into various breadboard for testing) has worked fine for me.  In theory, my design could be used as in circuit programmer as long as the needed pins can be made available.  However, this is tricky, as 12 volts will be applied to the RESET line (pin 6) during programming, so your circuit would need to be protected from this.  And, the prorgammer will need to be able to freely toggle pins 1 and 3, as well as raise and lower the Vcc line.  So, this imposes a heck of a lot of limitations on the circuit you would need to design for your board.  I'd be curious to hear your experiences if you try it, but I don't recommend using my design in this fashion.

Troubleshooting

As always, start by double checking everything, especially the orientation of the 4 diodes.  If even one is put in wrong, the circuit won't generate 12 volts and the programmer code won't be able to read the device signature, or program the device.  It's probably a bit late to mention this but, as I mentioned before, traces can be shorted on new PCBs, so it's wise to use the continuity tester function on a volt meter to check for short, or opens before assembling the PCB.  If you didn't of this, it's not too late, as most of the circuit is connected by capacitors, so you can still check for many shorts after the fact.  If all this fails, try reloading the code into the Arduino.

If you run into trouble with the assembler, make sure your not trying to do something my feeble minded assembler just can't do, such as parse expressions, or deal with anything other than basic assembler instructions, or the limited set of directives I coded into it.  Carefully check the Listing pane to see if there are any errors reported (note, my assembler is a deficient in error reporting category, too, so you may have to look carefully for things like skipped instructions, etc.)

Why Did I Create This?

One thing I obsess over is tiny things.  I'm a bit of a minimalist at heart, so when I first saw the new ATTiny 10 series, I wanted to work with them.  Build things with them.  But I quickly became frustrated, as all of Atmel's tools seemed to fall short.  For one thing, Atmel previously had a part called the ATTiny10 that, as far as I can tell, was never produced.  This caused me no end of confusion when I was trying to find software to work with these new ATTiny devices.  In addition, the ATTiny10 series changed the format of certain instructions (specifically, the LDS and STS instructions, which are only 2 bytes long on the ATTiny10, vs 4 bytes on other ATTiny devices) to fit better with the limited Flash memory and this makes the code incompatible with most other ATTiny chips.  So, I decided to create my own tools to I could at least have a chance to fix them if they failed to do what I wanted them to do.

Future Plans

I'd like to put out a Windows and Linux version at some point, but it's just not high up on my list of priorities right now.  Actually,if you're clever with Java, you might be able to extract and run the IDE on Windows, or Linux, if you extract the .class files from the ATTinyIDE.app file (in OSX, simply select "Show Package Contents" then open the path Contents->Resources->Java to get at the .class files.)  One hitch is that IDE uses the RXTX serial libraries to talk to the Arduino and my code may not work with the Windows or Linux versions of RXTX.  I profess to not having a lot of knowledge about how to integrate my code with RXTX on those platforms.  It was actually hard enough to get this all packaged up for OSX.

Eventually, I'd like to replace my lame assembler with something cooler, such as a real AVR assembler, or even a C compiler, if GCC ever happens to support the ATTiny 4,5,9 and 10 series chips (perhaps is does now on other platforms, but it doesn't seem to on the Mac.)  Note: as of 12/2/2012, I have a C compiler working with a modified version of this IDE.  Stay tuned for more details.

32/64 Bit Issues

With recent changes to the Java environment, you may need to run this IDE in 32 bit mode if you are using a recent version of OSX, such as Mountain Lion.  To do this, select the ATTinyIDE.app and then select "Get Info" from the "File" menu.  Then click the checkbox marked "Open in 32-bit mode" then close the dialog box.

If you have any suggestions, or questions about this project, contact me at "wayne dot holder at gmail dot com".
Č
ċ
ď
ATTiny10Asm.asm
(4k)
Wayne Holder,
Sep 11, 2011, 6:50 PM
ċ
ď
ATTiny10ProgrammerHV_PCB.pde
(12k)
Wayne Holder,
Jul 15, 2012, 3:13 PM
ċ
ď
Wayne Holder,
Jul 15, 2012, 3:12 PM
ċ
ď
Blink.asm
(1k)
Wayne Holder,
Sep 12, 2011, 7:40 AM