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.
- ATtiny10Programmer.ino(Better yet, use Keri DuPrey's code at the top of the page.)
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.
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.
- tinyblink.asm - blinking LED uses delay and digital output
- pwm.asm - pulse width modulation uses timer
- interrupts.asm - uses three different types of interrupts
- analog.asm - uses the analog to digital converter
Great, thank you.
ReplyDeleteGreat! I started using Tiny10 in february 2012, and there was almost nothing about it.
ReplyDeleteThere 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.
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.
ReplyDeleteHi 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@Mizotor -
ReplyDeleteThanks 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.
Hello Again and thanks for the prompt response.
ReplyDeleteThe 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
Interesting project - I wonder can this be used to reprogram ATtiny20 MPU's?
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@Mizotor -
ReplyDeleteSorry 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.
@Keri DuPrey -
ReplyDeleteThanks! 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.
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.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@ Keri DuPrey -
ReplyDeleteWow, 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.
This comment has been removed by the author.
ReplyDeleteHi 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.
ReplyDeleteI 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.
@Chris -
ReplyDeleteThanks. 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.
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.
ReplyDeleteNow 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?
@Chris -
ReplyDeleteGood, 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?
@Chris -
ReplyDeleteThe 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.
I have dropped the speed down to 9600.
ReplyDeleteThat was it! It gives me one extra "Received unknown command" error after successful programming, but successfully programs none the less.
ReplyDeleteLooks like it's time for me to delve into some assembly, thanks for the help getting this working.
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?
ReplyDeleteWhat i mean is somehting like this http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/
ReplyDeletebut for ATtiny10/9/5/4 instead of ATtiny13
@Fahad -
ReplyDeleteUnfortunately 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.
@ME
ReplyDeleteThat 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 ;)
@Fahad -
ReplyDeleteGet 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.
Thanks a lot.
ReplyDeleteI 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.
@Fahad -
ReplyDeleteYou'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.
Hi,
ReplyDeletefirst 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
@Anonymous -
ReplyDeleteYou'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.
Hi, thanks for your quick reply, i tried your code fix, and Setting the fuse works now fine.
ReplyDeleteClearing 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
@Anonymous -
ReplyDeleteThanks 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.
I've made the changes to the code as well.
ReplyDeleteThis 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.
ReplyDeleteIndex: 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
}
what arduino did you used?
ReplyDeletecan 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@Anonymous -
ReplyDeleteOf 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.
You are awesome!
ReplyDeleteIt 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.
@Jimmus -
ReplyDeleteI'm glad I could help.
I haven't tried disabling the reset pin, so good luck.
Have fun!
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.
ReplyDeleteATtiny4_5_9_10_20_40Programmer.ino
@Keri DuPrey-
ReplyDeleteThank 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.
Keri,
ReplyDeletesketch : 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.
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.
ReplyDeleteI had to mod the quickReset function to get one of my tiny4's to reset.
ReplyDeleteI 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.
@Anonymous -
ReplyDeleteThat'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.
I've added the quick send to high for the reset. Thanks for the tip!
ReplyDeleteSo 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.
ReplyDelete; 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?
@Jimmus -
ReplyDeleteThank 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.
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:
ReplyDelete;
; 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.
Hello,
ReplyDeleteThank 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
@par -
ReplyDeleteI'm glad this could be of help. Of course the most educational way is to write your own programmer. Thanks for sharing yours.
Thanks for the web site!
ReplyDeleteI 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
}
Sorry, I just noticed that Keri DuPrey's version did the same thing ... never mind.
ReplyDelete@Anonymous -
ReplyDeleteThanks for contributing. Lots of people have made improvements or different versions. Writing your own is a great way to learn, so keep it up.
A blink program that uses the timer function. It is a bit larger, but the blink rate is fairly accurate.
ReplyDeletehttp://www.calebengineering.com/attiny10.html
Hi there,
ReplyDeleteThe 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.
Actually...
ReplyDeleteI 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.
@Leo
ReplyDeleteIts 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.
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
ReplyDeleteGUI: 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.
Keri,
ReplyDeleteThis 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.
@Keri DuPrey -
ReplyDeleteWow. 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.
Hi Keri
ReplyDeleteI 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.
Hi
ReplyDeleteQuick 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.
@Leo,
ReplyDeleteIt may help. You can send it to my email ksdsksd@gmail.com
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.
ReplyDeleteOnly 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 :-)
Well thank you very much. I followed the instructions dilligently and it "just worked". Can't ask for more than that!
ReplyDeleteYour 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.
ReplyDeleteMany 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@Julian Kapoor -
ReplyDeleteI'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.
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!
ReplyDeleteProgramming 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.
ReplyDeleteLove from Pro Programmer
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.
ReplyDeleteLove from Pprogramming
I notice a bug(maybe)
ReplyDeleteFlash 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
This comment has been removed by the author.
ReplyDeleteI added the standalone programming mode like trinketloader in order to https://codebender.cc/sketch:72538
ReplyDeletePaste 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
@InoueTaichi
ReplyDeleteNice catch.
Hi Keri DuPrey. I am respect on your work.
ReplyDeleteHow do you think about "#define Tiny40 3 (or 4)" ?
@InoueTaichi
ReplyDeleteYou 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.
Hello, great stuff here,
ReplyDeleteI 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 :)
@Bo
ReplyDeleteSorry 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.
Hi!
ReplyDeleteThank 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!
This comment has been removed by the author.
ReplyDelete@Manuel
ReplyDeleteI've added a Lock function to the code and republished... Tested on a tiny10.
@Keri Thanks! I'll check it ASAP
ReplyDeleteThank you very much for your post, it’s really helpful and successfuly working well.......
ReplyDeleteactually we are working on ATTiny20..... and this post also useful for ATTiny20 also......
$
$
$
Thank you very much........
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.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete