ATTiny10 C IDE and Improved Device Programmer

Updates: 12/18/2014 - Updated so editor tab now shows c/c++ syntax coloring.

Updates: 9/13/2014 - Updated so editor tab now shows line numbers for code.

While my ATTiny10 Assembly IDE and Device Programmer served it purpose and help me get started working with the ATTny10 series, there were several issues I wanted to fix.  First, I really wanted to program in C, not assembly.  I also wanted the device programmer to be able to reprogram chips that have configured the RESET line as an output line, which is something my original charge pump design didn't seem able to handle.  And, lastly, I wanted to make working with the chip easier by not having to move the ATTiny10 breakout board back and forth between the programmer and circuit where it was being used.  After some experimentation, I came up with a design that seems to handle all these issues.

The New C IDE

Since I work on a Mac, the biggest challenge to working in C was to find a toolchain that supported C compilation on the Mac and also fixed the code generation issues that led me to write my own assembler in the first place.  Fortunately, the guys at Objective Development released an update to the CrossPack toolchain that solved these issues.  In particular, the CrossPack-AVR-20130212 release includes many needed fixes for the ATTiny10 family.  So, the first step in using my new IDE is to download and install the CrossPack-AVR-20130212, or later toolchain.  Once this is done, you can download and install my "ATinyC IDE by downloading and unzipping the ZIP file using the link at the bottom of this page. 

Next, download the ATTiny10 test app named Blink.c, or type in the source code shown next:

#pragma clock 8000000
#pragma chip attiny10

//           +====+
//  PWMA/PB0 |*   | PB3 (RESET)
//       GND |    | Vcc
//  PWMB/PB1 |    | PB2 (CLKO)
//           +====+

#include <avr/io.h>
#include <util/delay.h>

int main (void) {
  // Set clock to 8 MHz
  CCP = 0xD8; // Unprotect CLKPSR reg
  CLKPSR = 0x00; // Divide by 1
  // Calibrate Oscillator
  OSCCAL = 0x58;    // Get value from Osc Cal
  // set PORTD for output
  DDRB = 0x0F;
  while (1) {
    // Blink at 1 Hz Rate
    PORTB = 0x0F;
    PORTB = 0x00;

Then, load the file and select "Build" from the "Actions" menu to compile the C code into assembly language which is automatically displayed in the "Listing" tab.  If all goes well, you're ready to build the new, improved programmer circuit which uses an Arduino Duemilanove, or similar Arduino as the basis of the programmer.  If not, double check the installation of the CrossPack toolchain.

Special "pragma" Options

I added some code to the compile process that looks for special pragma values as a way to set some device-specific features, such as the FUSE bits that control using pin 6 as an input or output by disabling its normal function as a RESET input.  For example, in the code above, the line "#pragma clock 8000000" tells the IDE to pass a value of 8000000 to the compiler which, in turn, is used by the delay.h library to compute the proper loop times for the _delay_ms(50) call.  Likewise, the "#pragma chip attiny10" line tells the compiler to produce code for an ATTiny10, which has 1K of program space.   The compiler, in turn, can then produce a line like this in the "Listing" tab that shows what percentage of memory your code is using:

Program:     138 bytes (13.5% Full)

Finally, the IDE can also tell the device programmer what fuses (configuration options) to set in the special byte the chip uses to enable, or disable special features.  The format is like this:

#pragma fuses ckout, wdton, rstdisbl

Where the values "ckout", "wdton" and "rstdisbl" engage the following features if specified:
  • ckout - Outputs the device's internal clock on pin 4 (PB2)
  • wdton - Watchdog Timer is always on
  • rstdisbl - External Reset disable
However, I recommend that you carefully read the ATTiny10 data sheet before attempting to use any of these features.

The New Device Programmer

Instead of building my own charge pump, I decided to use a commercial chip, the Maxim MAX662ACPA+ as the basis of my new design.  This both simplifies the schematic and increases the 12 volt output to 30 ma, which should be sufficient to reprogram even a ATTiny10 that's had its RESET line setup as on output line.  However, before describing my fancier, in-circuit emulator design, I'll show the basic programming circuit.  This should be simple enough to cobble together on an Arduino prototyping shield once you have the needed parts.  Here's the schematic:

Note: the pins labelled D2-D5 are the Arduino's data pins and 5V is the source of 5 volts on the Arduino shield header.

The code for the ATTiny10ProgrammerEmulator is available in the download section below.  After installing this new sketch into the Arduino IDE, download it to the Ardunio where you have built the programmer circuit.  Then, quit the Arduino IDE and startup the ATinyC IDE (do not run both at the same time or they will compete for the use of the USB, or serial port used to talk to the Arduino.)  Once the programmer is built and programmed, you should be able to select it in the ATinyC "PORTS" selection in the "Settings" menu.  One selected, you can begin using the programmer to download code.  A good first test to see if everything is built and configured properly, is to connect a blank ATTiny10 and try the "Device Signature" option in the "Actions" menu.  If the programmer is working OK, the IDE should switch to the "Programmer" tab and, after a pause, it should display something like this:

Port /dev/tty.usbserial-A500SXU3 opened at 57600 baud

SIG: 0x1E, 0x90, 0x03 - ATTiny10


Adding In-Circuit Programming

To avoid the tedium of having to move the ATTiny10 back and forth between the programmer and the circuit under development, I hit upon a simple idea.  The ATTiny10 has so few pins, I could use a simple switching circuit to mimic what I did when I unplugged the ATTIny10 breakout board from the development circuit and plugged it in the programmer.  Then, once programmed, the ATTIny10 would be automatically switched back into the development circuit and restarted.  And, I could do this by adding two, small DPDT signal relays into the design and using an additional Arduino output pin to contorl the switching.  The circuit needed to do this is very simple, as shown here:

I put all these pieces together onto a small, mini-sheild design, using a 6 conductor FPC cable to connect to a small breakout board that plugs into the circuit under development in place of the ATTiny10, which plugs into a separate socket on the mini shield.  The final result looks like this:

The code in the Arduino app is already coded to use pin D6 to control the delays, so updating my code is now as simple as recompiling and selecting "Program Device" from the "Actions" menu.  The programmer automatically energizes the relays, which disconnects the ATTiny10 from the in-circuit socket and switches it to the Arduino pins that control programming as well as to the 12 volt output from the MAX662A chip.  Once programming is complete, the ATTiny is switched back into the circuit under development where it powers up and begins running with the new code.

The final PCB design looks like this;

Note: the new R2 resistor is for a new feature I have under development that is intended to provide a simple monitor function to read and display values sent from the ATTiny10 code using a small code library I can include with the project.  The PROGRAM socket is were I plug in a real ATTiny10 chip on a breakout header either to program it, or to use it with the in-circuit switch.  The EMULATE socket is where I plug in the FPC cable that connects to the circuit under development.  Note: if you'd like to replicate my design, the Gerber files are available below.  You should be able to upload this file to OSH Park and order a set of three boards for $11.  The relays are NEC model EA2-5NJ, which are available from Mouser for about $2.60, each.  The Maxim MAX662ACPA+ is also available from Mouser for $5.14m each, although you may be able to get one from Maxim as a sample.

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, or later.  To do this, select the 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".
Wayne Holder,
Mar 10, 2013, 6:44 PM
Wayne Holder,
Dec 18, 2014, 5:56 PM
Wayne Holder,
Mar 10, 2013, 10:56 PM