Projects

ATtiny10 resources

UPDATE: 
A huge thanks to Keri DuPrey, Nat Blundell and others who have been continually improving the code. The latest version is here:
ATtiny4_5_9_10_20_40Programmer.ino
And a useful GUI by Keri is here:
GUI: ATTiny4_5_9_10_20_40_Programmer.jar  

Also, avr-libc 1.7 and newer support ATtiny10! I have not tried it, but I reckon you can now use avr-gcc for the tiny10. However, with only 1kB of program memory, assembly is still useful.

The ATtiny10 is an intriguing little thing. It's the size of a grain of rice and has just 6 little SOT23 pins, but inside lies all the capabilities of an 8-bit AVR microcontroller. Everything from 4 analog input channels to a 16-bit timer with 2 possible pwm outputs to all your basic digital functionality. And at 45 yen a piece, there's little reason not to pick one up to play with. Or two... or ten.

Then once you get home and sit down at your computer, you realize that you are in for a bit more homework than you expected. ICSP doesn't work, common C compilers don't work, hardly anyone online has done DIY stuff with them. 

But hark! Do not forsake hope. I am here to aid you on your journey. First, I will guide you to the references that aided me: (The most useful of these was the last one, but it is in Japanese.)
Hardware
Now let's think about hardware. If you are willing to purchase an AVR programmer, go ahead. It's an easy solution that will definitely work. In that case, you can skip down to the assembly examples.
If you would rather do this the hard way(possibly more educational and satisfying), I'll show you how to program the ATtiny10 with only your Arduino, AVR Studio(or anything that will turn your assembly into a hex file) and a few resistors. Also, if you want to make use of all four I/O pins, you will need a 12V power supply for reprogramming.

Here is the basic hardware setup. Thanks to pcm1723 for this drawing and so much more.
 *                                                *
 * Arduino                 ATtiny10               *
 * ----------+          +----------------         *
 * (SS#)  10 |--[R]-----| 6 (RESET#/PB3)          *
 *           |          |                         *     
 * (MOSI) 11 |--[R]--+--| 1 (TPIDATA/PB0)         *
 *           |       |  |                         *
 * (MISO) 12 |--[R]--+  |                         *
 *           |          |                         *     
 * (SCK)  13 |--[R]-----| 3 (TPICLK/PB1)          *
 * ----------+          +----------------         *
 *                                                *
 *  -[R]-  =  a few killo-Ohm resistor            *
 *                                                *
 * 2011/12/08 by pcm1723                          *
 Really, some of those resistors may be unnecessary, but they don't hurt. You can see that it is making use of the usual SPI pins, and indeed we are going to make use of the SPI library to handle the communication details. Anyway, I got tired of setting up wires on a breadboard, so I just made this little pcb with 2.2kohm resistors that plugs right into the Arduino.  It also has a connector and jumper for applying 12V to the reset pin. This is only necessary if you disable the reset pin for I/O use.
  
Note that pin 1 goes in the top right corner. It faces the same direction as the chip on the arduino. Also note that the ATtiny10 needs to be on an adapter to plug into the DIP socket. I would like the option of using the chips without an adapter, so I want to make something that clamps the chip onto a breakout board without solder. I'll post again if I make something like that.

Software
Well, that was simple enough. Now for the software. 
First, you will need to generate a hex file for your program. One simple and guaranteed to work  method is by using AVR Studio, which is free to download from the Atmel website(here). Set your device to ATtiny10, make a new assembly file project thing, write your code, and click "build solution" in the build menu. Your hex file will be buried in a folder in the AVR Studio projects folder. Look for a folder with your project's name and somewhere inside will be a debug folder. hex is inside of that one.

Then we have to get the program onto the chip.
A big thanks again to pcm1723 for getting me started with the code for the arduino. They posted a simple sketch that uses the TPI interface to read all the memory on the chip and send it via serial to a computer. It was then up to me to extend this code to include all the necessary programming functions. You can find the original code on the fourth link up above. Most of it is included in the code below.

*EDIT* - Thanks to Keri DuPrey for making some nice changes to the code. See the comments below to find a link to the updated code. Changes: supports tiny20 and 40, read,program and verify in one streamlined command, can handle programs larger than 1024 bytes. 

*UPDATE* - Thanks to a commenter for pointing out that the fuse setting and clearing didn't work. With their help I have updated the code and it should work now.

Upload this sketch to an arduino. I ran into a very strange problem where it just wouldn't work right if the sketch size was much larger than 7,000 bytes. It would just hang or reset while programming an ATtiny10. I cannot fathom why this is. There should be more than ample memory on the arduino. If anyone has an idea, please let me know(leave comment on home page). Anyway, this version compiled to 6,996 bytes and worked fine. 
Then power off(unplug) the arduino, connect the ATtiny10 as shown, and power up the arduino again. Open up the serial monitor in the tools menu. Set the serial speed to match the one used by the arduino. The default is 38400. If everything is working so far, you should see the message
  NVM enabled
  ATtiny10 connected
If you don't see this, either you aren't using an ATtiny10 or there could be a hardware problem. After you get this far, you can start using the programming functions. To do this, input the one-character commands described below. Only send one command at a time because some of them require additional input.

Commands:
  • D = dump memory. Displays all current memory on the chip
  • E = erase chip. Erases all program memory
  • R = read program. Sends the program to the arduino. After sending this command  you have 20 seconds to copy and paste the entire contents of a .hex file into the serial monitor and send. You can do the whole file at once. If it was successful, you should see "program received".
  • P = write program. After reading the program with the R command, use this to write the program to the ATtiny10.
  • V = verify. Verifies that the program was written correctly. If not, it will display the errors.
  • F = finish. Not necessary, but this disables further access until the arduino is reset.
  • S = set fuse. Follow the displayed instructions to program one of the three fuses.
  • C = clear fuse. Follow the displayed instructions to UNprogram one of the three fuses.
The 'D' command is quite a useful and harmless way to test your programmer and the chip. It simply reads all the memory on the ATtiny10 and displays it in the serial monitor in an easy to read way. You may want to avoid the 'S' and 'C' commands unless you are sure you want to mess with the fuses. There are only three fuses. One sends the clock signal to a pin, one enables the watchdog timer, and one disables the reset pin so you can use it for I/O. If you disable the reset pin, I hope you have a 12V power supply, because you will need it the next time you want to program the chip.

A little caution: if you want to verify after programming, be sure to press shift+v and not ctrl+v as I have done many times. ctrl+v will probably paste your hex file to the monitor again. If you accidentally send it, you will see a lot of strange behavior as the programmer reads 'C', 'D', 'E', 'F' commands along with a bunch of ignored characters. Don't worry, the worst that could happen is that you will erase your chip and disable further programming until you reset the arduino. Just reset and try again.

Examples
OK, now that you can program the chip the hard part begins. Actually making an interesting program. If you are like me and this is the first time you have used assembly for AVRs, just google "AVR assembly tutorial" and you will find everything you need. It takes a little more work than something like C, so I will give you some simple programs that make use of the various functionality of the chip. They are by no means perfect or interesting, but you can use them as building blocks.
 Good luck.

87 comments:

  1. Great, thank you.

    ReplyDelete
  2. Great! I started using Tiny10 in february 2012, and there was almost nothing about it.
    There is information in avr freak too.
    In addition, if someone hates assembler, another option is to write a C code in CodeVision and copy the asm code in AVRstudio. It is a simple way to avoid asm.

    ReplyDelete
  3. About the crash issue. After Taking a quick look at the source code, It looks like the problem may be all the strings that are being printed, each one takes space in ram. I had a similar problem with a project, kept resetting on me, once I moved all the strings to program space I had no more crashes.

    ReplyDelete
  4. Hi I am having problems programming the attiny10 using the arduino and your code. The arduino accepts the code and programs then upon verification it has not been programed, any suggestions would be helpful.

    ReplyDelete
  5. @Mizotor -
    Thanks for trying my code. Here are some ideas:
    If the serial monitor says "NVM enabled" and then "ATtiny10 connected" at the top, then your connections are good and you are properly communicating with the chip. If you don't see these messages, check connections and voltage(needs 5V to program). Once that is working, try the "D" command to dump chip memory to the monitor. If you see something that looks like your program in the program memory space, then you are successfully writing your program. In this case, take a close look at the HEX file. Look at the 8th number of each line. If it is not '0' or '1'(usually near the beginning or end of the file). then it is a special command line, and my code is not set up to do anything with these lines since they are really not necessary for the attiny10. Try deleting the line entirely.

    If all attempts fail, send me the HEX file and I'll try programming one of mine.
    Good luck.

    ReplyDelete
  6. Hello Again and thanks for the prompt response.

    The arduino replies with NVM enabled and ATtiny10 connected, so as you say i believe the chip is connected correctly. I am using your blink program to test the programming capability and the hex is generated by the atmel studio 6 program and is 5 lines long with the 8th character is either 0/1. This hex is accepted and it states program received, then upon 'P' it states Wrote program 62 of 1024 bytes, this is as i expected but with 'D' it returns FF in all the program memory and as i stated before the verify fails as to be expected with all FF returned. I have put the TPI Data on a scope and it appears to be toggling so i don't think it is held at one.

    This is a very confusing problem and i can only think that the reset is not happening so i tried to do a 12v reset but no change.

    Any ideas?

    Regards Mizotor

    ReplyDelete
  7. Interesting project - I wonder can this be used to reprogram ATtiny20 MPU's?

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. @Mizotor -
    Sorry I didn't reply sooner. I'm afraid I don't have any idea what's wrong. You are able to enter programming mode and read the memory, so I don't know why you can't write to memory. I really hesitate to suggest a problem with the chip, but if you have another one handy, try a different chip.

    If you figure out the problem, please tell me/us about it.

    ReplyDelete
  10. @Keri DuPrey -
    Thanks! Putting the strings in program memory is a big improvement.

    This code could actually work with any ATtiny that uses TPI, but the program size would be limited to 1024 bytes unless you made some significant modification to the code.

    The bug concerns me. I have programmed ATtiny10s numerous times without such a problem. I wonder what's happening.

    ReplyDelete
  11. I figured out what the "Bug" is. The Tiny10/20 use the same write opcode of 0x1D, but its for a different word count, Word/Dword. So the chip wont write unless all the words have been sent.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. @ Keri DuPrey -
    Wow, thanks for that. The programming method is much more streamlined as long as there are no serial buffer issues. I'll update this post to point out your new code.

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Hi there, thanks for all your efforts put into this! I'm attempting to program at ATtiny10 from an Arduino Uno using the methods described and I'm hoping you could offer some troubleshooting tips.

    I have everything wired up and I successfully get the "NVM enabled" and "ATtiny10 connected" when opening the serial monitor. From there, I can send D and it will dump the data from the chip, but will follow the dump with a single "Received unknown command". If I try R, it simply returns with "Received unknown command" twice.

    Any idea what the issue might be? I'm not quite sure where to start my troubleshooting. Thanks.

    ReplyDelete
  16. @Chris -
    Thanks. Are you using my code or the updated version by Keri DuPrey(linked in a comment above)? Also, tell me about your software setup. The "Received unknown command" message appears when any character that is not a command is sent, except when reading in hex data. This includes a newline character. I'm using the current Arduino serial monitor in Windows and I've never seen this problem. I'm wondering if you are automatically sending a newline character. But even then the 'R' command should be accepted.
    Unless you are using Keri DuPrey's code which has slightly different commands. Those are documented at the top of that code.

    ReplyDelete
  17. I could have sworn I read the comments at the top at least a couple times! Turns out that's most of the problem: I am using the updated code and should be using P to program. Also, the automatic newline sending is indeed why I was getting the extra error after normal accepted commands.

    Now I'm successfully able to program it! One last issue I'm running into though: I have to copy/paste the hex file line by line as I think copy / pasting the entire thing incorrectly converts the line endings and only uploads part of the program before outputting a bunch of unknown command errors.

    I am using a mac running 10.7.5, so I'm not sure you would have any suggestions for this sort of issue but I thought couldn't hurt to ask. Copy/paste in general does not seem to work well in the Arduino IDE. What character should each line be separated by?

    ReplyDelete
  18. @Chris -
    Good, I'm glad you got it working. I don't really know much about a mac, but the actual line ending character doesn't matter. Actually, you don't even need one. The line length info is included in the hex code, so the arduino code does not check for line endings and if there is an extra character that is not ':' it is just ignored. However, if there is more than one extra character, it will cause an error. So maybe you are sending more than one character after the line? Maybe a tab or space character?

    ReplyDelete
  19. @Chris -
    The problem for programming the entire flash at one time may be from a serial buffer overrun. Try dropping the speed to 9600, or less, I don't have any 10's to test but they might write/verify slower.

    ReplyDelete
  20. I have dropped the speed down to 9600.

    ReplyDelete
  21. That was it! It gives me one extra "Received unknown command" error after successful programming, but successfully programs none the less.

    Looks like it's time for me to delve into some assembly, thanks for the help getting this working.

    ReplyDelete
  22. Thanks for the programmer code guys, awesome work. I haven't used it yet, but about to as I am making my first ATtiny10 board. I just have a question about the Hex code for the Attiny10, can I use the arduino IDE itself to write a code, compile that code and then use generated HEX to program ATtint10? How about adding information about attiny10 to the arduino board.txt file?

    ReplyDelete
  23. What i mean is somehting like this http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/

    but for ATtiny10/9/5/4 instead of ATtiny13

    ReplyDelete
  24. @Fahad -
    Unfortunately you cannot use the Arduino IDE because the C compiler, avr-gcc, does not support the attiny4/5/8/10 yet. I think the reason is that there are only 16 useable registers while the rest of the attiny series has 32. But with only 1kB or less of program memory, you will probably want to do the coding in assembly anyway.

    On the other hand, if you write only assembly code in the arduino IDE in proper C assembly format you may be able to do it. I think it would be simpler to just use AVRStudio which is free on the Atmel website.

    ReplyDelete
  25. @ME
    That is actually what I am trying to avoid, learning AVR C or Assembly.

    But you are right with such limited device I think assembly is the way to go. Is there any website that you recommend to start learning about programming those tiny mCUs?

    I also found you mosquito code which will help me a lot since I am planing to use an IR receiver as part of my design.
    So thank you twice ;)

    ReplyDelete
  26. @Fahad -
    Get ready for quite a learning experience. Don't rely on your knowledge of other languages because you will need very different techniques with assembly. But don't be discouraged.
    First, download the AVR instruction set here. It will be your manual. Also, this guide has some useful info and examples. Then download my small example files on this page and go over them carefully till you understand what's happening.

    As for the IR stuff, my code is designed to record a signal of unknown protocol and length. If you are using a protocol that you know, you can make it vastly, vaaastly simpler. I bet you could do it in 20 lines rather than several hundred. If you have any questions, let me know.

    ReplyDelete
  27. Thanks a lot.
    I have two questions:
    1- AVR-GCC that comes with AVR Studio 6 has support for attiny10, but the one with arduino doesn't! Don't they both belong to the same project? and both should be GPL and open source? or simply the arduino people are not interested in including the code since they don't use that type mcu?

    2- My project will read IR codes sent from any type of IR remote control (so what you did exactly matches what I need) and will compare that code against a code that is stored in the attiny10. I am interested in matching one code only however, I don't want that code to be hard-coded. I rather want the user to be able to reprogram that code to match any remote control button they want. But the attiny10 doesn't have EEPROM, so can we store data into the flash from the running code itself? or do I need to use another chip like the attiny13a.

    ReplyDelete
  28. @Fahad -
    You're right! avr-libc 1.7 and newer support ATtiny4/5/9/10. Great, this changes everything. Arduino might not come with the latest version of avr-libc(the libraries used by avr-gcc) yet, but I think you could just replace the appropriate files to use the newest version with arduino.

    As for the memory question, I'm sorry to say that there is no way to write to flash memory from running code. You only have access to SRAM and the registers. If you really need this feature, ATtiny13 and others will be a better choice.

    ReplyDelete
  29. Hi,

    first of all: this is a very useful blog, and gives a "nearly" ;-) perfect solution.
    Thanks a lot.

    But did you already set a fuse on a tiny10? I want to see the System clock on PB2, therefore i issued command 'S' followed by 'c'. But nothing changed. The configuration word still says 0xFF 0xFF.
    I think the code for Setting/Clearing the fuses is wrong, as it only writes the LSB.
    The mcu waits for the MSB before it really writes the fuses.

    Greetings

    Mic

    ReplyDelete
  30. @Anonymous -
    You're right! Thanks for telling me. I never tried changing fuses, so I didn't notice, but I actually left out a few important steps including writing the MSB.
    I've updated the code and it should work. I don't have time to test it right now, but if it still doesn't work, let me know.

    Also, this update is only in the file provided on this blog. It is not included in Keri DuPrey's newer code yet.

    ReplyDelete
  31. Hi, thanks for your quick reply, i tried your code fix, and Setting the fuse works now fine.
    Clearing does not. I read the Atmel Manual, and Clearing fuses Needs a SECTION_ERASE instead of WORD_WRITE in NVMCMD Register.

    I changed the code in setConfig
    to:
    setPointer(0x3F40);
    writeIO(NVMCMD, (val ? NVM_WORD_WRITE : NVM_SECTION_ERASE) );

    which works.

    Greetings,
    Mic

    ReplyDelete
  32. @Anonymous -
    Thanks again. I put your fix into the code. I hope there are no more surprises like that. More importantly I hope it hasn't caused too many headaches for people using it.

    ReplyDelete
  33. I've made the changes to the code as well.

    ReplyDelete
  34. This patch for Keri DuPrey's code re-enables the ATtiny after each command. This allows faster iterations of development as you don't need to re-wire the RST line to test.

    Index: ATtiny45910Programmer.ino
    ===================================================================
    --- ATtiny45910Programmer.ino (revision 2)
    +++ ATtiny45910Programmer.ino (working copy)
    @@ -137,6 +137,16 @@
    SPI.setDataMode(SPI_MODE0);
    SPI.setClockDivider(SPI_CLOCK_DIV32);

    + start_tpi();
    +
    + // initialize memory pointer register
    + setPointer(0x0000);
    +
    + timeout = 20000;
    + idChecked = false;
    +} // end setup()
    +
    +void start_tpi() {
    // enter TPI programming mode
    digitalWrite(SS, LOW); // assert RESET on tiny
    delay(1); // t_RST min = 400 ns @ Vcc = 5 V
    @@ -153,13 +163,7 @@
    // wait
    }
    Serial.println(F("NVM enabled"));
    -
    - // initialize memory pointer register
    - setPointer(0x0000);
    -
    - timeout = 20000;
    - idChecked = false;
    -} // end setup()
    +}

    void loop(){
    if(!idChecked){
    @@ -171,6 +175,8 @@
    while(Serial.available() < 1){
    // wait
    }
    + start_tpi();
    +
    // the first byte is a command
    //** 'P' = program the ATtiny using the read program
    //** 'D' = dump memory to serial monitor
    @@ -209,6 +215,8 @@
    default:
    Serial.println(F("Received unknown command"));
    }
    +
    + finish();
    }
    void ERROR_pgmSize(void)
    {
    @@ -552,7 +560,7 @@
    writeCSS(0x00, 0x00);
    SPI.transfer(0xff);
    SPI.transfer(0xff);
    - // digitalWrite(SS, HIGH); // release RESET
    + digitalWrite(SS, HIGH); // release RESET
    delay(1); // t_RST min = 400 ns @ Vcc = 5 V
    }

    ReplyDelete
  35. what arduino did you used?

    ReplyDelete
  36. can i use this software with other programmer wich is capable if ISP? I mean :can I use something different from Arduino ? Something similar into Arduino?

    ReplyDelete
  37. @Anonymous -
    Of course you can use something instead of Arduino. The arduino is essentially just using SPI to act as a TPI programer. Look at the data sheet to see the differences between SPI and TPI, but they are pretty much the same.
    Of course the software I have written is specific to arduino, but I imagine it could easily be ported to whatever SPI capable programmer you are using.

    ReplyDelete
  38. You are awesome!

    It took a bit of fixing to get the tinyblink program to work, but the attiny10programmer.ino worked flawlessly.

    I used tavrasm because it was easier for my setup, and I had to change the call instructions to rcall.

    I still have to make sure I can re-program after disabling RESET, but it's over there blinking away.

    Thank you for your work, and for sharing it with people like me.

    ReplyDelete
  39. @Jimmus -
    I'm glad I could help.
    I haven't tried disabling the reset pin, so good luck.
    Have fun!

    ReplyDelete
  40. I had an erratic issue with the nibbles being swapped when programming, and made a change that seemed to clear up the problem. I also added Nat Blundell's patch to the code.


    ATtiny4_5_9_10_20_40Programmer.ino

    ReplyDelete
  41. @Keri DuPrey-
    Thank for doing that and thanks for keeping this code up to date. I haven't run into that problem, but I'm glad it was easy to fix.
    Also, thanks to Nat Blundell. I think I forgot to thank you for your patch.

    ReplyDelete
  42. Keri,
    sketch : ATtiny4_5_9_10_20_40Programmer.ino

    posted:
    March 17, 2014 at 5:45 AM

    Line 597 is missing an 'else'

    .Causes serial monitor to report TINY and Unknown chip.

    ReplyDelete
  43. I've added the missing else statement and a quick reset option. Also, Added High Voltage Programming, on pin 9, to the code, along with select-able High/low enable, depending on the users design for providing 12v.

    ReplyDelete
  44. I had to mod the quickReset function to get one of my tiny4's to reset.
    I added a SS,HIGH immediately before the existing SS,LOW.
    Another tiny4 reset without it.
    The offender is at the end of 10 inches of ribbon cable -- in case that helps.

    void quickReset()
    {
    digitalWrite(SS,HIGH); //pull /RST high for an instant
    digitalWrite(SS,LOW);
    delay(10);
    digitalWrite(SS,HIGH);
    }

    Before adding the SS,HIGH line, I could short the /RST pin to GND, while the SS output was HIGH and the tiny would reset. I have 1K5 resistors as per the diagram in sketch, so the output was safe.

    ReplyDelete
  45. @Anonymous -
    That's really strange. I'm not sure what flicking the reset line high like that would change. But if it works, great. Thanks for the idea.

    ReplyDelete
  46. I've added the quick send to high for the reset. Thanks for the tip!

    ReplyDelete
  47. So I am back doing a project with my AtTiny10, and I started with a working program, the TinyBlink, of course. I found 2 minor errors, neither of which affects the execution of the small program, but which might affect things if the program is expanded.

    ; not really needed, but keep r16-r18
    push r16
    push r17
    push r18
    ...
    pop r17
    pop r16
    pop r18
    ret

    Yeah, I don't think that's going to work.

    ; variables
    .EQU delayMult1 = 0xff ; the delay is delay3*delaymult2*delaymult1
    .EQU delayMult2 = 0xff
    .EQU delayMult3 = 0x0f

    I looked at the code that uses these variables in the delay, and I don't think that's the right formula. I think it is:

    delayMult3 * 65536 + delayMult2 * 256 + delayMult1

    Which is better anyway because it gives us highly accurate control of this delay loop.

    I considered using the watchdog timer for my timing needs, but with delays accurate to within 5 clock cycles, and programmed this easily, who needs it?

    ReplyDelete
  48. @Jimmus -
    Thank you for checking that. That was my first attempt at assembly code for the ATtiny10. Looking back at it, it is awful. You are right about the "pop" order not working. The math for the delay is also wrong. It was just a poorly written piece of code that happens to work. I should probably update all of those files.

    ReplyDelete
  49. Well, while I was messing with it, I found out some other things. Like how the registers and pins are initially set up. For example, the stack pointer is already set to EndOfRam for us, so we don't really need that code. And all the pins are set to input mode, but if we set one to output mode, it's already off. Not that we care, since we're blinking on and off anyway, but the point is we can remove that code as well. And it works just as well at the default 1 MHz speed if we adjust the timer multipliers, so we could remove that code as well. Which got me to thinking, how small could we really make this blink program? Try this out:

    ;
    ; tinyblink
    ; Blinks an LED on pin 4 (PB2)
    ;
    ; Version 1.05
    ; Taken from http://junkplusarduino.blogspot.jp/p/attiny10-resources.html
    ; and modified by Jimmus

    ; .DEVICE ATtiny10

    .EQU PORTB = 2
    .EQU DDRB = 1
    .EQU PINB = 0

    main:
    sbi DDRB, 2 ; Set LED pin as output

    loop:
    sbi PINB, 2 ; Toggle output

    delayLoop:
    subi r16, 1
    sbci r17, 0
    brne delayLoop
    rjmp loop

    It does blink a little bit faster--about twice a second, and the interval is not configurable. But 6 instructions is pretty small, I think.

    ReplyDelete
  50. Hello,

    Thank you so much for this blog and the source. I've learned a great deal. I had unfortunately quite a few problems getting the programmer to upload consistently due to serial overruns.

    I completely rewrote the source over the weekend and it is working better for me now. I've uploaded my project to github.

    https://github.com/bdpdx/ATtiny10Programmer

    ReplyDelete
  51. @par -
    I'm glad this could be of help. Of course the most educational way is to write your own programmer. Thanks for sharing yours.

    ReplyDelete
  52. Thanks for the web site!
    I made the following changes to the programmer so I didn't have to unplug, remove wires, and plug back in. The finish command just puts everything in high impedance mode and pulls the reset high. Then it goes into an infinite loop until the Arduino reset button is pressed. It isn't too sophisticated, but it seems to work.

    void finish(){
    writeCSS(0x00, 0x00);
    SPI.transfer(0xff);
    SPI.transfer(0xff);

    pinMode(10, OUTPUT);
    pinMode(11, INPUT);
    pinMode(12, INPUT);
    pinMode(13, INPUT);

    digitalWrite(10, HIGH); // release RESET

    delay(1); // t_RST min = 400 ns @ Vcc = 5 V
    while(1) {} // infinite loop until reset
    }

    ReplyDelete
  53. Sorry, I just noticed that Keri DuPrey's version did the same thing ... never mind.

    ReplyDelete
  54. @Anonymous -
    Thanks for contributing. Lots of people have made improvements or different versions. Writing your own is a great way to learn, so keep it up.

    ReplyDelete
  55. A blink program that uses the timer function. It is a bit larger, but the blink rate is fairly accurate.

    http://www.calebengineering.com/attiny10.html

    ReplyDelete
  56. Hi there,

    The procedure you described works for the ATTiny4 (you can take the "possibly" off your header ;) ).

    This is phenomenal, thank you so much for sharing!!

    Léo.

    ReplyDelete
  57. Actually...

    I did the process once and it worked perfectly.

    Now I'm trying to upload some new code, and it's behaving unexpectedly :

    - When a one-letter command is sent, the chip won't answer unless the PB3 (reset, connected to Arduino digital #10) is disconnected from the Arduino. So it seems to read input from the serial monitor but not to be able to send info back to it unless PB3 is unplugged.
    - With PB3 unplugged, E command returns "chip erased" as expected but LED keeps blinking. (LED stops blinking when PB3 is replugged to Arduino #10)
    - Trying then to upload code with PB3 unplugged, works until "V" command that returns:
    "
    program error:
    byte 00AB expected 95 read 00
    "

    for all bytes (all zeros because I have reset in the meantime with E command)

    So basically having PB3 connected seems necessary to be able to upload new code but makes communication impossible... ?

    Thanks for your help
    Léo.

    ReplyDelete
  58. @Leo

    Its been a few years since I looked at the original "ATtiny10Programmer" code, but it sounds like it holds the reset(PB3) low. you may want to try the "ATtiny4_5_9_10_20_40Programmer" releases reset when programming is finished.

    ReplyDelete
  59. Just finished a project, and realized that a GUI interface was needed, So I wrote a generic one, in java, for the ATTiny4_5_9_10_20_40_Programmer.ino

    GUI: ATTiny4_5_9_10_20_40_Programmer.jar

    I've got plans on combining the programmer and a simple digital I/O firmata together to help with testing tiny programs. I may need some encouragement to get going on that as I have no other tiny projects at the moment.

    ReplyDelete
  60. Keri,

    This is great! My ongoing project could totally use all these improvements!

    I just need to make sure it's not making my chips un-overwriteable.

    I'll try that this weekend when I have a moment! Thank you so much for following up !!

    Léo.

    ReplyDelete
  61. @Keri DuPrey -
    Wow. Thank you for continuing to develop this. You are doing a great service to all ATtiny fans. Sadly my life has not allowed me to even pick one up for the last year, but I'm sure many people appreciate your effort.

    ReplyDelete
  62. Hi Keri

    I fail to open the .jar file. It shuts itself down straight away. I'm not sure if it helps that I send you the OS X Console messages?

    Thanks for all your help
    L.

    ReplyDelete
  63. Hi
    Quick update on the initial problem I had with not being able to upload anything else after the initial upload: it was indeed the RESET pin that was not released when finished.

    In void finished(), uncommenting "digitalWrite(SS,HIGH);" does the trick!

    Thanks again
    Léo.

    ReplyDelete
  64. @Leo,
    It may help. You can send it to my email ksdsksd@gmail.com

    ReplyDelete
  65. Great reading. smallest Atmel chip I used was the attiny13, but sizewise nothing beats the attiny10 I guess. May give that a try. I think my last endavours in assembler ate at least 20 years ago for the 8052/51/32/31 Intel chips, but I might be fun to pick it up again for the attiny10.
    Only problem.. not sure if i will be able to solder the little buggers into anything, eyesight isnt what it used to be anymore and if i have to put them on a breakoutboard for a DIL socket I might as well stick to bigger chips. Well, I may give it a try. did you ever find a solution to just clamp the Attiny10 to a programmong board? Maybe just some copperpads and a clothespin would work miracles :-)

    ReplyDelete
  66. Well thank you very much. I followed the instructions dilligently and it "just worked". Can't ask for more than that!

    ReplyDelete
  67. Your use of SPI for the serial connection with the Tiny10 is brilliant! I have written a avr910 compatible TPI programmer for the ATmega328p so it interfaces directly with avrdude. It worked but I was bit banging the TPI ports and couldn't get the performance I wanted. Now I have adopted your SPI routines and my programmer is smoking fast running on an Arduino UNO! Thanks very much.

    ReplyDelete
  68. Many thanks for providing these resources! I'm a complete newcomer to programming MCUs, so some of my problems may be related to that, however I'm having trouble getting my Arduino Uno (with the sketch you provided at the top of the page successfully uploaded) to recognize my ATTINY20. The serial monitor prints out "NVM enabled, unknown chip connected" and when I dump the memory the Device ID is all zeros. A friend successfully got your code working with an earlier version of Arduino IDE, but not with the version current to June 2016. Any idea what might be going on and why the most recent version(s) of the IDE might be causing errors? Any help would be greatly appreciated.

    ReplyDelete
  69. @Julian Kapoor -
    I've never tried an ATtiny20, but supposedly it should work using Keri Duprey's code. Which Arduino code are you using? You should be using the one at the top of the page, ATtiny4_5_9_10_20_40Programmer.ino instead of the older file further down. I don't know what has changed with the new version of Arduino, but if they made changes to the SPI library it might mess things up. Try an older version of Arduino. If that doesn't work, I'm not sure what's going on. If I have time later I'll try an ATtiny10 with the new Arduino.

    ReplyDelete
  70. Hold the press! I was working with a couple of chips that I must have fried somehow. The programmer sketch works great on the ATtiny20 using Arduino IDE 1.6.8 now. Thanks again to you and everyone else who has contributed to this project!

    ReplyDelete
  71. Programming is very interesting and creative thing if you do it with love. Your blog code helps a lot to beginners to learn programming from basic to advance level. I really love this blog because I learn a lot from here and this process is still continuing.
    Love from Pro Programmer

    ReplyDelete
  72. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from Pprogramming

    ReplyDelete
  73. I notice a bug(maybe)

    Flash Words 0x1D CODE_WRITE of ATtiny40 is Qword.
    So, it must be "#define Tiny40 4" I think.

    #define Tiny4_5 10
    #define Tiny9 1
    #define Tiny10 1
    #define Tiny20 2
    //#define Tiny40 3 <- bug
    #define Tiny40 4

    >> if ( currentByte == 2 * words ) { // is the word/Dword/Qword here?

    >> Serial.println(F("Current memory state:"));
    >> if(type != Tiny4_5)
    >> len = 0x400 * type; //the memory length for a 10/20/40 is 1024/2048/4096

    ReplyDelete
  74. This comment has been removed by the author.

    ReplyDelete
  75. I added the standalone programming mode like trinketloader in order to https://codebender.cc/sketch:72538
    Paste the hex code to image.h and you can program without paste the code into serial monitor.
    https://www.dropbox.com/s/dvbn3kv3qbci4ah/ATtiny4_5_9_10_20_40Programmer.zip?dl=0

    ReplyDelete
  76. Hi Keri DuPrey. I am respect on your work.
    How do you think about "#define Tiny40 3 (or 4)" ?

    ReplyDelete
  77. @InoueTaichi
    You are correct, it should be 4. Thanks for finding that, I've applied the change. It's been quite some time since I've done a tiny 20 or 10 project, haven't done a 40 yet.. And even longer since I've actually looked at the programming code.

    ReplyDelete
  78. Hello, great stuff here,

    I did a read out of ATTiny10 i had here, for extracking the program, and i get the data, however, program 4000 and up is just pure 0's, so there is no program on?

    SRAM has code, can i clone this to a hex file? so i can make a copy of the chip?

    The code i get is here:
    http://www.elteq.dk/attiny10.txt

    If anyone can do a hex file for me or tell me how to do so i get a clone of this, would be great :)

    ReplyDelete
  79. @Bo

    Sorry Bo, haven't been on for a while. The file you provided is no longer there. But from what you've described, there is no way to make a copy. The program needs to be there.

    ReplyDelete
  80. Hi!
    Thank you very much for your post, it’s been really helpful and it's working pretty well! I’d like to manipulate lock bits to prevent memory for being read. I’ve been trying to modify the code with no succed :( Please can you help me?
    Thanks!

    ReplyDelete
  81. This comment has been removed by the author.

    ReplyDelete
  82. @Manuel

    I've added a Lock function to the code and republished... Tested on a tiny10.

    ReplyDelete
  83. @Keri Thanks! I'll check it ASAP

    ReplyDelete
  84. Thank you very much for your post, it’s really helpful and successfuly working well.......
    actually we are working on ATTiny20..... and this post also useful for ATTiny20 also......
    $
    $
    $
    Thank you very much........

    ReplyDelete
  85. Please guide me that my blink eg. on attiny10 doesn't work, even though the Arduino detect it as "NVM enabled, ATtiny10 connected" on serial monitor. But on upload it say "avrboy" is not meant for your version of windows. My OS is Window 10 pro.

    ReplyDelete
  86. This comment has been removed by the author.

    ReplyDelete