Arduino ISP (In System Programming) and stand-alone circuits

By on March 14, 2012

We use an Arduino to program other ATmega without bootloader . This technique allows you to use all flash memory for code and make boards using new ATmega, cheaper than those with bootloader.

The qualities that have made the success of Arduino are undoubtedly the open-source software, many libraries, a good hardware and a virtually infinite Reference that explains each possible use of the platform.

But if we use Arduino for a specific use, we can integrate it into a specific circuit and program the micro in a way that performs a single firmware. We may so remove the bootloader and leave to the firmware the entire program memory.

The ATmega328 has 32 Kbytes of flash, that when the chip is mounted on Arduino are not all available, as a portion is reserved to the bootloader, the purpose of which is to communicate with the IDE Arduino to load programs (sketch) to be performed. The same bootloader, on each power on or reset of Arduino, verifies the presence of a sketch in flash memory and executes it. The bootloader occupies a space of 512 bytes, in the case of Arduino UNO.

Well, in a stand-alone application the bootloader no longer needed.

The configuration of the micro ATmega328P needs, in addition to the power (+5 VDC to pins 7 and 20, GND to pins 8 and 22), a 16-MHz crystal between pins 9 and 10, two 22 pF ceramic capacitors from between these pins and GND, a 10 k Ω resistor between pin 1 and +5 VDC for pull-up the reset line.

 

Programming ATMEGA in stand-alone

Anyone knows that it is necessary program Arduino uploading a sketch via USB, using the software called IDE and the operation is quite simple.

We can see a screenshot of the IDE with an Arduino sketch loaded and UNO during the receipt of the sketch (notice the yellow LED on).

The technique will test allows the use of a board Arduino as ISP Programmer.

We start with the list of required materials:

•               Arduino UNO / Duemilanove (will be used as a programmer);

•               ATmega328P chip (chip to be programmed);

•               Breadboard and jumper;

•               a crystal of 16 MHz, two ceramic capacitors from 22 pF, a resistance of 10 K Ω 1/4 W, a resistance of 560 Ω 1/4 W LED 3 or 5 mm;

•               seven male-male jumper wires.

A resistance of 120 Ω 1/4 of watts, and an electrolytic capacitor or tantalum from 10 uF 10 ÷ 16 volts.


Now we prepare our target circuit and first of all insert the chip on the Breadboard, these are the connections to make:

•               through the jumper to be Breadboard connect pins 7 and 20 of the chip to the positive supply line (+5 volts);

•               in the same way we connect the pins 8 and 22 of the chip to the ground line supply (GND);

•               connect pin 1 of the chip to the +5 V line through the resistor of 10 k Ω;

•               insert the crystal to the pins 9 and 10 of the chip;

•               insert the two 22 pF ceramic capacitors; both must have a leg connected to GND, while the other will serve to connect a capacitor to pin 9 and the other to pin 10 of the chip;

•               insert one end of resistor 560 Ω at the pin 19 and the other end into an empty spot on the breadboard, and to this end we connect the anode LED(the longer pin) , whose other end (cathode) goes to GND;

 

At this point we can connect to the Arduino Breadboard using jumper cables under the following matches:

•               Arduino pin 10 goes to pin 1 of the chip;

•               Arduino pin 11 goes to pin 17 of the chip;

•               pin 12 of Arduino is connected to pin 18 of the chip;

•               pin 13 to Arduino pin 19 goes on the chip;

•               the +5 V pins of Arduino goes to the positive supply line of the breadboard;

•               any of the three GND pin of Arduino goes to the ground line of the breadboard.

 

Now look the software to reveal the “trick” that sends a sketch, using the IDE, to the chip on the Breadboard, bypassing Arduino that will play the role of Programmer ISP.

What we need to do is create a virtual board, starting from the original (corresponding to the model we are using Arduino) and making some simple but essential changes. We must first locate the file that is boards.txt containing all information relating to the various boards that the IDE shows us when we execute the command Tools->Board. Typically this file is located in the folder of the IDE software, the path X: \ mypath \ arduino-xxx \ hardware \ arduino, where X is the letter that indicates the logical drive and myPath the folder or location containing the program (xxx indicates the version of the program).

Now open the file with Notepad and see a long series of lines arranged in groups separated by a line consisting of a repetition of the symbol ”#”,each group representing a different board. The lines are identified by the initial code, the same for all, but different for the board, the name that will appear in the submenu Tools->Board is inserted in the first row in the group.

The code is represented by the word “uno” which is at the beginning of each line.

The line containing the word “name” (usually the first) is followed by “=” and then the name that the board will have in the IDE.

Other information that concern us are:

uno.upload.maximum_size = 32256: Sets the maximum capacity of flash memory that we can use in practice from 32 Kbytes of Flash which has the total ATmega328P we must subtract the space occupied by the bootloader, for the Arduino UNO is 512 byte;

uno.bootloader.low_fuses = 0xffuno.bootloader.high_fuses = 0xdeuno.bootloader.extended_fuses = 0×05; these three lines are the “fuse”, are used to set the behavior of the chip and are expressed with hexadecimal values;

uno.build.f_cpu = 16000000L: This line must correspond to the clock frequency for which the chip has been set, by means of the fused, expressed in Hz, 1 Hz 6,000,000 correspond to 16 MHz, precisely the frequency of the quartz or, more precisely, the present external oscillator to Arduino UNO; this value is used as a reference for timing controls of the software, such as delay () and millis ().

 

And now we create our own virtual board, writing these lines of code:

 

atmsa16.name=ATmega in Stand Alone (w/ Arduino as ISP)
atmsa16.upload.protocol=stk500
atmsa16.upload.maximum_size=32768
atmsa16.upload.speed=115200
atmsa16.upload.using=arduino:arduinoisp
atmsa16.bootloader.low_fuses=0xff
atmsa16.bootloader.high_fuses=0xdf
atmsa16.bootloader.extended_fuses=0x05
#### atmsa16.bootloader.extended_fuses=0x07
atmsa16.bootloader.path=optiboot
atmsa16.bootloader.file=optiboot_atmega328.hex
atmsa16.bootloader.unlock_bits=0x3F
atmsa16.bootloader.lock_bits=0x0F
atmsa16.build.mcu=atmega328p
atmsa16.build.f_cpu=16000000L
atmsa16.build.core=arduino

 

Following the approach of the file will separate this group of lines to those of other boards, inserting a line of ”#”.The end result should be:

We note that are varied: the code (atmsa16 instead of uno), the maximum_size (brought to its maximum capabilities of Flash, since we do not reserve space for the bootloader), then there a new line (atmsa16.upload.using = arduino: arduinoisp) that allows us to understand the IDE that will program the chip in stand-alone and not on the Arduino. Another new line is preceded by some “# # # #” that disables it, the reason is easily explained: the extended_fuses is set to 0×05, and in some special cases, during the transfer of the sketch could be an error bound the setting of this value.As we shall see later, simply change the following two lines of code:

 <em># # # # Atmsa16.bootloader.extended_fuses = 0x05</em>
<em>atmsa16.bootloader.extended_fuses = 0x0</em>7

thus activating the value 0×07 instead of 0×05, it will work out. Of course, this change should not be made before, but only if you get the error.

 

Program the micro

At this point we are ready for the final step: send our sketches to the chip mounted on the breadboard and then will test the operation separating it from Arduino.


To read the new board in the file, the IDE must be restarted, so if this program was open, when editing the file boards.txt must close it and restart it. To verify that our modification is successful, it is sufficient now run the command Tools->Board and check if there is now our “stand-alone” board, otherwise we should close the IDE and check the file boards.txt, because certainly we made ​​a mistake.

The technique used to send the sketch to the chip in stand-alone mode is very simple: First select the Arduino board that we are using as a programmer (eg Arduino Duemilanove or UNO) , just as we do for normal use of Arduino. Then select the Arduino serial port (the COM for Windows users) and recall from the IDE the sketch ArduinoISP, execute this command by clicking the Upload button on the IDE. After several seconds of the three flashing LEDs and Arduino to the breadboard of course (at the moment is physically connected to pin 13 of Arduino that, as we know, check out one of the three LEDs on the board) on the IDE will come the message “done uploading “.

Arduino is ready to play the role of Programmer ISP, select, now, our board IDE “ATmega Stand Alone (w / Arduino as ISP)“, without changing the COM.

We load the sketch “blink” and execute it again by clicking the Upload button on the IDE: LEDs and Arduino breadboard flash again, this time for a much shorter period, after which the IDE will show the message again “Done uploading”.

So our ATmega328P chip was programmed without having to physically fit on Arduino and now lives its own life. It is then ready to be mounted in the circuit which it is intended.

Of course, the chip can be reprogrammed at will with any kind of sketch.

 

Troubleshooting

At this point we have to solve three types of problem that may occur when we send the sketch to the chip stand-alone. The problems of’extended_fuses and of autoreset may occur on either Arduino Duemilanove or Arduino UNO, without that you can establish a certain rule.We must also emphasize that the remedies that will illustrate to 100% solve the problems, but must be applied only if the problem occurs.

We start from the situation that may occur if we use a blank chip, the Atmel set the fuse to make the chip work at 1 MHz with the internal oscillator. If we send a sketch directly, happens that the chip in stand-alone ignores the external crystal and times will be staggered: for example, the LED blink with the sketch will last about 16 seconds instead of 1 second. Simply, we set the fuse, the operation can be done easily by loading the bootloader on the chip before sending the sketch.

Before explaining this simple maneuver quickly clarify two points: the bootloader is sent once a chip virgin and will only serve to set the fuse, then it will become useless and the sketch overwrite it, if we had to first load the sketch, noticing the error, and then load the bootloader, no problem: the chip is set and we just have to resubmit the sketch. The simple steps that are going to describe will return very useful for cases where we wanted to prepare a blank chip to work directly on Arduino; is a good idea to have in the house a spare chip with bootloader of our board, so if you were unfortunately damaged the original, a simple substitution solves this problem immediately.

Here are the steps to follow:

•               prepare and connect the Breadboard Arduino as discussed previously;

•               We open the IDE and select the model we are using Arduino and port to which it is connected;

•               upload the sketch ArduinoISP to Arduino;

•               now execute the command Tools->Burn Bootloader w / Arduino as ISP;

•               After about a minute we loaded into the stand-alone chip the bootloader of Arduino boards (you may have noticed that in the IDE we’ve set our Arduino board).

 

As mentioned, the chip can be quickly mounted to receive the Arduino sketch, or leave it on the breadboard and repeat/execute the operation of sending the sketch stand-alone, this time the Blink will work perfectly.

Of course, other errors may occur, do not worry, keep reading this section and of course everything will be resolved.

So let the problem of ’extended_fuses: the rows of our virtual board we expected a double value for this cast, because it can happen (even though it is quite rare) that some boards do not succeed in this program merged with the value 0×05. During the upload of the sketch on the chip with stand-alone mode, the IDE will display an error message (written in red on a black background) that will indicate the need to use the value 0×07, if it appears that in practice warning means that we must close the IDE, open the file boards.txt and activate the relevant line, simultaneously disabling the other (with 0×05), as explained above. At this point we can repeat the test. We clarify that if the error occurs on a given board will always occur on this board, so the variation of the files should be done only once and permanently.

And now we see the problem, more frequent, about autoreset. When the serial chip (FT232RL on Duemilanove or ATmega8U2 of UNO) receives a signal from the USB port, sends the reset pulse to ATmega328, who then prepares itself to receive Data. This operation corresponds to the one you make every time you press the button “RESET” on the Arduino.

If the data do not arrive or if the reset was made manually, the sketches in flash memory chip ATmega328 is executed. When Arduino is used as ISP Programmer can happen that, if the autoreset is sent too early, the upload operation fails. In this case the IDE returns the following error: ”avrdude:stk500_getsync (): not in sync: resp = 0×15“.

The problem is solved by blocking the Autoreset. The 120 ohm resistance must be connected between the RESET pin of Arduino and +5 V, while the 10µF capacitor is connected with the positive pole to the RESET of Arduino and negative to GND.

With a jumper cable connect on Breadboard the RESET signal of Arduino.

The methods described should be used only if absolutely necessary.

Important note: the need to connect these components only when needed, is dictated by the fact that to load a sketch on the Arduino should autoreset, otherwise the upload will fail and we will get the error avrdude: stk500_getsync (): not in sync: resp = 0×00 – avrdude: stk500_disable (): protocol error, expect = 0×14, resp = 0×51, so if you see this error, know that you just have to “liberate” the pin “RESET” Arduino from the link with the Anti- autoreset.

[Thanks to Michele Menniti]

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.
  • Duncan

    Is there any reason why an Arduino Pro-Mini with a USB adaptor couldn’t be used for this project?

    I have those and want to program some ATMEGA 328s for instant start up of program code (i.e. without the bootloader delay)

    Thanks

  • Pingback: Arduino ISP (In System Programming) and stand-alone circuits | Open Electronics | Michal Vondráček

  • http://www.michelemenniti.it Michele Menniti

    Hello,
    You can use Arduino Pro Mini with a USB-Serial ISP Programmer for the function. But Arduino Pro-Mini must work at 5V and 16MHz. If you need help please ask.

  • Duncan

    Thanks

    I have a 5V/16MHz Pro-Mini…

    My idea was to build it into a small box with a ZIF socket on the top and a lead for in-circuit programming (If I can ever locate the 3×2 IDC connectors!!!)

    If I encounter problems I’ll be in touch and I’ll send you a photo when it’s built.

    Thanks again

    Duncan

  • http://www.michelemenniti.it Michele Menniti

    You can follow these instructions for connections to the ZIF:
    - connect pins 7 and 20 of the ZIF to the positive supply line (+5 volts) of your Arduino PRO-mini
    - in the same way we connect the pins 8 and 22 of the ZIF to the ground line supply (GND);
    - connect pin 1 of the ZIF to the +5 V line through the resistor of 10 k Ω;
    - insert the 16MHz crystal to the pins 9 and 10 of the ZIF;
    - insert the two 22 pF ceramic capacitors; both must have a leg connected to GND, while the other will serve to connect a capacitor to pin 9 and the other to pin 10 of the ZIF.
    At this point you can make your ISP connection with 6 wires:
    - pin 10 of Arduino goes to pin 1 of the ZIF;
    - pin 11 of Arduino goes to pin 17 of the ZIF;
    - pin 12 of Arduino is connected to pin 18 of the ZIF;
    - pin 13 to Arduino pin 19 goes on the ZIF;
    Now read carefully this article and the instructions for software

    Good luck! ;-)

    Prof. Michele Menniti

    PS: The Magazine “Elettronica In” in the current issue, has presented an excellent project for the construction of an ISP Programmer for Atmel mcu:

  • Duncan

    I read through the article earlier – presumably I need to use a different piece of code for the Pro-Mini rather than the examples that begin “uno.—”?

    I have to admit to being a little confused at this point – but it may become clearer when I actually have everything ready and have my brain aligned with Arduino again (I only “play” with it now and again).

    Duncan

  • 7Usam

    Great Work , but :/

    i have atmega168v and 8MHz crystal and arduino ide ver 1.0

    my change in board.txt

    atmsa16.name=ATmega in Stand Alone (w/ Arduino as ISP)
    atmsa16.upload.protocol=stk500
    atmsa16.upload.maximum_size=14336
    atmsa16.upload.speed=115200
    atmsa16.upload.using=arduino:arduinoisp
    atmsa16.bootloader.low_fuses=0xff
    atmsa16.bootloader.high_fuses=0xde
    atmsa16.bootloader.extended_fuses=0×05
    atmsa16.bootloader.path=optiboot
    atmsa16.bootloader.file=optiboot_atmega168_8.hex
    atmsa16.bootloader.unlock_bits=0x3F
    atmsa16.bootloader.lock_bits=0x0F
    atmsa16.build.mcu=atmega168
    atmsa16.build.f_cpu=8000000L
    atmsa16.build.core=arduino

    and start burn bootloader then output is

    avrdude: stk500_paged_write(): (a) protocol error, expect=0×14, resp=0×64
    avrdude: stk500_cmd(): programmer is out of sync

    what is the problem ?

  • http://www.michelemenniti.it Michele Menniti

    Hi 7Usam,
    IDE 1.0 has a ArduinoISP defective, the new versions (1.0.1-rc1 & rc2) should solve the problem, but they are still beta versions. If you can do a test with IDE 002 or 0023.
    A note on your virtual board: you have to set HFuse = “DD” and eFuse = “FC” or “04″. You can also work without 8MHZ crystal, with the internal oscillator: E2 = LF, HF = DD, EF = FC (or 04). Let me know the news.

  • 7Usam

    Hi Michele i just remove the resistor and led from pin 19 then burn bootloader using ide ver 22
    then work it :) , can i burn bootloader of usbasp to my stander alone chip using same method ? , i test other chip that have not a bootloader of arduino …. just for test uploading simple program like blink then uploading is done ! and the blink is work in that chip but slow , so why we burn bootloader on chip ?

  • http://www.michelemenniti.it Michele Menniti

    EXCELLENT! :D if you use a resistor with value 680ohm or greater, you can also leave the LED on pin 19.
    By way ISPs can program any MCU AVRDUDE.COND recognized by the IDE, but you need the “core” for his family.
    If you burn bootloader, you’ll also change the fuses on the MCU, and set the exact frequency. After this you can schedule a firmware and you’ll see that the LED flashes properly.
    If you program a MCU, without setting the fuse with burn bootloader, the oscillator works badly.
    Unfortunately I do not know USBASP.

  • 7Usam

    Thanks ;)

  • Pingback: electronique | Pearltrees

  • NukeTheMoon

    Hi,
    I got an error when i try to program my controler on breadboard with blink example.
    C:\Users\Maxime\Desktop\arduino-1.0.1-windows (1)\arduino-1.0.1\hardware\arduino\cores\arduino/Arduino.h:213:26: error: pins_arduino.h: No such file or directory
    Here is my board code:

    uno.name=Arduino Uno
    uno.upload.protocol=arduino
    uno.upload.maximum_size=32256
    uno.upload.speed=115200
    uno.bootloader.low_fuses=0xff
    uno.bootloader.high_fuses=0xde
    uno.bootloader.extended_fuses=0×05
    uno.bootloader.path=optiboot
    uno.bootloader.file=optiboot_atmega328.hex
    uno.bootloader.unlock_bits=0x3F
    uno.bootloader.lock_bits=0x0F
    uno.build.mcu=atmega328p
    uno.build.f_cpu=16000000L
    uno.build.core=arduino
    uno.build.variant=standard
    ##############################################################
    atmsa16.name=ATmega in Stand Alone (w/ Arduino as ISP)
    atmsa16.upload.protocol=stk500
    atmsa16.upload.maximum_size=32768
    atmsa16.upload.speed=115200
    atmsa16.upload.using=arduino:arduinoisp
    atmsa16.bootloader.low_fuses=0xff
    atmsa16.bootloader.high_fuses=0xdf
    atmsa16.bootloader.extended_fuses=0×05
    atmsa16.bootloader.path=optiboot
    atmsa16.bootloader.file=optiboot_atmega328.hex
    atmsa16.bootloader.unlock_bits=0x3F
    atmsa16.bootloader.lock_bits=0x0F
    atmsa16.build.mcu=atmega328p
    atmsa16.build.f_cpu=16000000L
    atmsa16.build.core=arduino

    I first tried:

    atmsa16.name=ATmega in Stand Alone (w/ Arduino as ISP)
    atmsa16.upload.protocol=arduino
    uno.upload.maximum_size=32768
    atmsa16.upload.speed=115200
    atmsa16.upload.using=arduino:arduinoisp
    atmsa16.bootloader.low_fuses=0xff
    atmsa16.bootloader.high_fuses=0xdf
    atmsa16.bootloader.extended_fuses=0×05
    atmsa16.bootloader.path=optiboot
    atmsa16.bootloader.file=optiboot_atmega328.hex
    atmsa16.bootloader.unlock_bits=0x3F
    atmsa16.bootloader.lock_bits=0x0F
    atmsa16.build.mcu=atmega328p
    atmsa16.build.f_cpu=16000000L
    atmsa16.build.core=arduino

    Have any idea on what could be the problem ? :S

  • http://www.michelemenniti.it Michele Menniti

    Hello, I have always worked with IDE 0022. In ArduinoISP IDE 1.0 did not work, but IDE 1.0.1 should work properly even if the procedure is different. Tomorrow I install IDE 1.0.1 on my PC, I’ll give you some tests and news.

  • http://www.michelemenniti.it Michele Menniti

    Now I noticed that, in your board, the “x” in the extended fuse byte is not x but a different character, why?
    Also on the board you have previously used the line:
    uno.upload.maximum_size = 32768
    must be
    atmsa16.upload.maximum_size = 32768

  • NukeTheMoon

    The different character was an error from a copy paste, I have no idea why the character changed.
    Also I’m new to the arduino environement, I used to program PICs controlers but I wanted to try arduino for it’s vast variety of shields and libraries so forgive my stupid mistake.

    I forgot to use the line atmsa16.build.variant=standard, that my code seems to need to work which yours doesn’t#, maybe because of the version.

    I’d like to thank you for your quick answer and the great tutorial.

  • NukeTheMoon

    I thought the whole ISP programmation was working but i just realised it doesn’t. When i launch a code to program on the stant alone controler (after i programmed the UNO in ARDUINO ISP) it program the UNO and not the controler on breadboard.

    I passed the whole day trying to figure out the problem…
    I’m using those board config:

    atmsa16.name=ATmega in Stand Alone (w/ Arduino as ISP)
    atmsa16.upload.protocol=arduino
    atmsa16.upload.maximum_size=32768
    atmsa16.upload.speed=115200
    atmsa16.upload.using=arduino:arduinoisp
    atmsa16.bootloader.low_fuses=0xff
    atmsa16.bootloader.high_fuses=0xdf
    atmsa16.bootloader.extended_fuses=0×05
    atmsa16.bootloader.path=optiboot
    atmsa16.bootloader.file=optiboot_atmega328.hex
    atmsa16.bootloader.unlock_bits=0x3F
    atmsa16.bootloader.lock_bits=0x0F
    atmsa16.build.mcu=atmega328p
    atmsa16.build.f_cpu=16000000L
    atmsa16.build.core=arduino
    atmsa16.build.variant=standard

    So when I use ATmega in Stand Alone (w/ Arduino as ISP) board in tools to program i still program the UNO. Any idea why?

  • http://www.michelemenniti.it Michele Menniti

    Hi, IDE 1.0.1 works differently than IDE 0022, it provides directly to program Arduino via ISP, so you should NOT add the line “arduinoisp”, but you must refer to the original board dell’IDE1 .0.1. Yesterday I did not test because I thought you had solved the problem. Tomorrow I will do some tests and I hope to show you the solution. Stay tuned;-)

  • http://www.diegotecnology.es Diego

    Hi! in first place, congratulation for your work!

    I need you to help me, i am working with atmega2313 and i connect my microcontroler according the datasheet and the pins (MISO, MOSI, SCK).
    I conect all the conexions, i think that all is correct.

    Also i burn the Arduino Isp in my board Arduino Uno and i downloaded a archive with boards.txt and cores, i change the fuses in the boards.txt, i think that its wrong.

    I need help becouse i don’t know to do yet for this microcontroler works.

    I’m sorry for my English becouse i’m spanish.

    Thanks in advance.

  • http://www.michelemenniti..it Michele Menniti

    Hello Diego, Thanks!
    You also connected to pin 10 of Arduino reset pin of 2313?
    You have connected the 10K resistor between pin and GND reset 2313?
    At what clock frequency you want to work on 2313?
    If the chip is a virgin before I suggest you try the original fuses (Low = 64, DF = High, = Extended FF), without using the crystal and external capacitors.
    If you do not have a bootloader for the 2313 test you by sending it directly to the sketch, but this can not change the values ​​of the cast, which is why you must use the original ones.
    Hola!
    PS: I am Italian, your English is fine as well, is like mine :-)

  • http://www.michelemenniti..it Michele Menniti

    @ NukeTheMoon
    Hello,
    I’m sorry but these days I had to work hard and I could not do the tests that I have promised. As soon as I can to make sure you write it here for updates.

  • http://www.diegotecnology.es Diego

    yes, i also connect the pin 10 and the resistor of 10k is between Vcc and Reset of 2313.

    If the resistor is between ground and reset the burn is bad.

    i copy you the boards.txt referent a attiny2313, maybe something is bad.

    attiny2313at8.name=ATtiny2313 @ 8 MHz (Oscilador interno)

    # The following do NOT work…
    # attiny2313at8.upload.using=avrispv2
    # attiny2313at8.upload.using=Pololu USB AVR Programmer

    # The following DO work (pick one)…
    # attiny2313at8.upload.using=arduino:arduinoisp
    # attiny2313at8.upload.protocol=avrispv2
    # attiny2313at8.upload.using=pololu

    attiny2313at8.upload.maximum_size=2048

    # Default clock (slowly rising power; long delay to clock; 8 MHz internal)
    # Int. RC Osc. 8 MHz; Start-up time: 14 CK + 65 ms; [CKSEL=0100 SUT=10]; default value
    # Brown-out detection disabled; [BODLEVEL=111]
    # Serial program downloading (SPI) enabled; [SPIEN=0]
    # Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]

    attiny2313at8.bootloader.low_fuses=0×64
    attiny2313at8.bootloader.high_fuses=0xdf
    attiny2313at8.bootloader.extended_fuses=0xff
    attiny2313at8.bootloader.path=empty
    attiny2313at8.bootloader.file=empty2313at8.hex

    attiny2313at8.build.mcu=attiny2313
    attiny2313at8.build.f_cpu=8000000L
    attiny2313at8.build.core=tiny

  • http://www.michelemenniti..it Michele Menniti

    You’re right, I made a mistake in his haste, the r10k goes between reset and Vcc.
    You also connected to pin 10 of Arduino reset pin of 2313?
    Your board is completely wrong!
    If your tiny2313 is a virgin and if you’re using Arduino as programmer uses this board:

    ###############################################################################################
    attiny2313at1.name ATtiny2313 = @ 1 MHz (internal oscillator; BOD disabled)
    attiny2313at1.upload.using = arduino: arduinoisp
    attiny2313at1.upload.maximum_size = 2048
    attiny2313at1.bootloader.low_fuses = 0×64
    attiny2313at1.bootloader.high_fuses = 0xDF
    attiny2313at1.bootloader.extended_fuses = 0xFF
    attiny2313at1.bootloader.path = empty
    attiny2313at1.bootloader.file = empty2313at1.hex
    attiny2313at1.bootloader.unlock_bits = 0xFF
    attiny2313at1.bootloader.lock_bits = 0xFF
    attiny2313at1.build.mcu = ATtiny2313
    attiny2313at1.build.f_cpu = 1000000L
    attiny2313at1.build.core = tiny

    You burn tiny2313 directly without bootloader, it does not exist for this MCU.
    Let me know.

  • http://www.diegotecnology.es Diego

    My board was downloaded of http://code.google.com/p/arduino-tiny/downloads/list

    Your code give me a lot of mistakes.
    I don’t know that is the reason for it doesn’t work.

    i give you more information:

    - Software Arduino 1.0.1
    - Sketch that i try to burn: Blink
    - Pin 10 of Arduino to pin 1 of attiny2313
    - With my board, the burn was succesful without mistakes but doesn’t work

    I hope that you can help me! this is a puzzle! jeje

  • http://www.michelemenniti.it Michele Menniti

    OK, then use the last board of the core but WITHOUT replacing anything.
    My suggestions are for the 0022 IDE, as I said the other user I have not done tests with IDE 1.0.1
    Tiny2313 on the digital pin 13 corresponds to the physical pin 16, that’s where you connect the led through a R330-560ohm

  • http://www.diegotecnology.es Diego

    mmmm okei, i test your suggesion and i tell you with something.

    certainly, where do you see the digital pin assigned a phisical pin??
    Mayby, i can change the pin assigned.

    Thanks!

  • http://www.michelemenniti.it Michele Menniti

    Inside the tiny folder \ cores \ tiny here is the file that contains the pins.arduino.c pinature of tiny2313; values ​​”dxx” represent the digital pins, connecting the LED to a pin and uses in its digital pin blink.

  • http://www.diegotecnology.es Diego

    hi michele!! my attiny works yet!!! you have reason! the pins was the problem!! you are fantastic!!! thank you very much!!

  • http://www.michelemenniti..it Michele Menniti

    Hi Diego!
    I am very happy for you, congratulations!
    Michele

  • http://www.michelemenniti.it Michele Menniti

    @ NukeTheMoon:
    OK, I managed to make tests and to burn a ATmega328P with IDE 1.0.1.
    You follow these steps:

    0 – Add the file boards.txt these lines:
    ####################################################
    atmega3216.name ATmega328P = 16MHz
    atmega3216.upload.protocol = arduino
    atmega3216.upload.maximum_size = 32768
    atmega3216.upload.speed = 115200
    atmega3216.bootloader.low_fuses = 0xff
    atmega3216.bootloader.high_fuses = 0xDF
    atmega3216.bootloader.extended_fuses = 0xFF
    atmega3216.bootloader.path = optiboot
    atmega3216.bootloader.file = optiboot_atmega328.hex
    atmega3216.bootloader.unlock_bits = 0x3F
    atmega3216.bootloader.lock_bits = 0x0F
    atmega3216.build.mcu = atmega328p
    atmega3216.build.f_cpu = 16000000L
    atmega3216.build.core = arduino
    atmega3216.build.variant = standard

    Save and close the file. Open the IDE 1.0.1.

    1 – Set the board “Arduino UNO” and the corresponding COM / USB / DEV.
    2 – Set the programmer “Arduino as ISP”
    3 – Open the sketch “ArduinoISP” present in the samples and make upload to Arduino UNO
    4 – Now open the sketch “blink”
    5 – Set the board “ATmega328P 16MHz”
    6 – Run the command File – Upload Using Programmer

    If you want to load the bootloader instead of the sketch, you must only follow the steps 1-2-3, then:
    4 – Run the command Tools – Burn Bootloader.

    Keep in mind that:
    the micro leaves the factory to 1MHz, if you want to use it clocked at 16MHz must set the fuse, the only way to set the fuse is loaded BEFORE the bootloader and then send the sketch.
    Good luck!

  • Duncan

    Hi

    I finally found the time to build this and it seems to work fine on IDE 1.0.1.

    The Blink sketch was running slow and I realised that the ATmega328 was running at 1MHz.

    I tried burning the bootloader but it failed with the message:

    ***failed;
    avrdude: verification error, first mismatch at byte 0×0000
    0xff != 0×07
    avrdude: verification error; content mismatch

    I have Board set at ATmega328p = 16MHz and Programmer set to Arduino as ISP, then I clicked on Burn Bootloader.

    Am I doing something wrong or is this because I have burned the sketch first and it now cannot burn the bootloader?

    Can the situation be fixed?

    Thanks

  • http://www.michelemenniti.it Michele Menniti

    Hi Duncan, the situation can be fixed easily.
    1 – Replace the value in the virtual board: eFuse = FF with eFuse = 07
    2 – Save, then close and reopen the IDE 1.0.1
    3 – Burn the bootloader (REQUIRED!!!)
    4 – Upload blink, now everything should work.

    Follow the instructions for 1.0.1 which I wrote in my last post

    Let me know.
    Michele

  • Duncan

    Hi Michele

    That fixed the problem and it is now working correctly.

    I took the opportunity to look up Fuses but could not understand much of what I read. Is there a SIMPLE explanation somewhere that you could reccomend that would explain what they are and how to set them?

    If I want to run an ATmega328 without any external oscillator components (for an application that is not time-critical) can I just burn the sketch onto a blank chip without burning the bootloader first – as I mistakenly did before? I didn’t try unplugging the crystal to see if it continued working at 1MHz (8MHz with 1/8 prescaler set???).

    Regards and thanks

    Duncan

  • http://www.michelemenniti.it Michele Menniti

    Very good!
    The topic of fused is not difficult to understand but it is difficult to explain.
    I have published two articles on Electronics In Numbers (June and July / August 2012), in particular in the June, I explained very well the use of fused and lock bits. I recommend reading them.

    You can work at 1MHz or 8MHz but you ALWAYS burn the bootloader first and then the sketch.

    Hello
    Michele

  • Duncan

    Hi Michele

    Two problems:

    1) The programmer seems to have stopped working.
    I tried to burn another sketch over the Blink sketch.
    On plugging in the ATmega328 the LED on Pin 19 (digital 13) blinks at the one second rate of the Blink sketch and continues to do so after I hit Upload using Programmer – nothing changes.
    The IDE then reports “avrdude: stk500_getsync(): not in sync: resp=0×00″ and the ATmega328 continues to run the Blink sketch.

    Do I have to run “Burn Bootloader” before each and every upload of a sketch or something?

    2) I did a Google search for “Electronics in Numbers” but nothing showed up – can you provide a link to this please?

    Sorry to be so dumb!!!

    Duncan

  • http://www.michelemenniti.it Michele Menniti

    Hi Duncan,

    The error “avrdude: stk500_getsync (): not in sync: resp = 0×00″ indicates connection problems, double check that the wires and check the current COM port

    You do not have to run “Burn Bootloader” before every upload sketches but only when you set the fuse of the micro.

    You have to look “ElettronicaIn – Current Issue” in this same page, on the right frame

    Michele

  • Duncan

    Hi Michele

    I checked the wiring, I even tried a new USB cable – nothing…

    Then I had a flash of inspiration. I seperated the programmer from the Arduino and reprogrammed the Arduino with the Blink sketch – that worked ok. I then uploaded the ArduinoISP sketch again, reconnected the programmer and everything is working again.

    Do you have any idea what may have caused the Arduino to mess up its stored program?

    Given the trouble I am having understanding all of this in English, I don’t think your articles on Fuses are going to help me much in Italian – thank you anyway.

    Duncan

  • Duncan

    Hi Michele

    I have been programming ATmega328 chips for standalone projects at 16MHz (external crystal oscillator) without any problems but now I need to do some for Internal Oscillator at 1MHz and at 8MHz..

    Obviously I need to create two new entries in the “boards.txt” file (I was going to call the entries “atmega32801″ & “atmega32808″ and use “atmega32801.build.f_cpu=1000000L” & “atmega32801.build.f_cpu=1000000L” respectively), but I am totally confused about what settings to use for the fuses and other things.

    Also (I don’t actually need to do it yet) is it possible to program the chips without a bootloader to free-up space or am I doing that already with “maximum_size=32768″ and the references to the bootloader apply to the Arduino boad that is acting as the programmer?

    The boards.txt entry I am using at the moment is:

    atmega3216.name=ATmega328p = 16MHz Crystal
    atmega3216.upload.protocol=arduino
    atmega3216.upload.maximum_size=32768
    atmega3216.upload.speed=115200
    atmega3216.upload.using=arduino:arduinoisp
    atmega3216.bootloader.low_fuses=0xff
    atmega3216.bootloader.high_fuses=0xdf
    atmega3216.bootloader.extended_fuses=0×07
    atmega3216.bootloader.path=optiboot
    atmega3216.bootloader.file=optiboot_atmega328.hex
    atmega3216.bootloader.unlock_bits=0x3F
    atmega3216.bootloader.lock_bits=0x0F
    atmega3216.build.mcu=atmega328p
    atmega3216.build.f_cpu=16000000L
    atmega3216.build.core=arduino
    atmega3216.build.variant=standard

    Thanks

  • Duncan

    Whoops…

    That should have read…

    “atmega32801.build.f_cpu=1000000L” & “atmega32808.build.f_cpu=8000000L”

    (the curse of “cut and paste”)

  • Michele Menniti

    Hello Duncan, these boards allow you to program the micro and 1MHz to 8MHz with IDE 1.0.1 with the normal mode. The cast are already designed to use the entire flash memory for the application. But the first thing to do is always to load the bootloader, to set the fuse, then you can load the firmware, which will erase the bootloader.
    Let me know how the tests will be
    Michele
    ##############################################################
    mega3208.name=ATmega328P 8MHz internal clock
    mega3208.upload.protocol=arduino
    mega3208.upload.maximum_size=32768
    mega3208.upload.speed=115200
    mega3208.bootloader.low_fuses=0xe2
    mega3208.bootloader.high_fuses=0xdf
    mega3208.bootloader.extended_fuses=0×07
    mega3208.bootloader.path=optiboot
    mega3208.bootloader.file=optiboot_atmega328.hex
    mega3208.bootloader.unlock_bits=0x3F
    mega3208.bootloader.lock_bits=0x0F
    mega3208.build.mcu=atmega328p
    mega3208.build.f_cpu=8000000L
    mega3208.build.core=arduino
    mega3208.build.variant=standard
    ##############################################################
    mega3201.name=ATmega328P 1MHz internal clock
    mega3201.upload.protocol=arduino
    mega3201.upload.maximum_size=32768
    mega3201.upload.speed=115200
    mega3201.bootloader.low_fuses=0×62
    mega3201.bootloader.high_fuses=0xdf
    mega3201.bootloader.extended_fuses=0×07
    mega3201.bootloader.path=optiboot
    mega3201.bootloader.file=optiboot_atmega328.hex
    mega3201.bootloader.unlock_bits=0x3F
    mega3201.bootloader.lock_bits=0x0F
    mega3201.build.mcu=atmega328p
    mega3201.build.f_cpu=1000000L
    mega3201.build.core=arduino
    mega3201.build.variant=standard
    ##############################################################

    • Duncan

      Hi Michele

      Can I just confirm the steps involved – I think I am worried that I may overwrite the bootloader on the Arduino that is the programmer.

      To program a chip at 8MHz Internal Clock:-

      1) Set “Board” to “ATmega328P 8MHz internal clock”
      2) Set Comm Port
      3) Set “Programmer” to “Arduino as ISP”
      4) Click “Burn Bootloader”
      5) Load the Sketch
      6) Click “Upload Using Programmer”

      Yes?

      The programmer is now using a Duemilenove that blew its voltage regulator – as it is being powered only by 5V from the USB everything works fine (eventually I will replace the regulator).

      Sorry if I am appearing to be a bit stupid!!!

      Thanks

      Duncan

      • melrick nicolas

        where can i find the sample arduino isp sketch ???

        • http://www.michelemenniti.it/ Michele Menniti

          In the list of programs included in the IDE, name ArduinoISP

  • http://www.facebook.com/ian.blundell.39 Ian Blundell

    Hi Michele

    I must be missing something, I can burn the bootloader no
    problem but when I try to upload a sketch ArduinoISP tries to upload using
    serial coms, it does not pull the reset on the breadboard and attempt to use the
    same method as it does when I burn the bootloader. How do I ensure that the
    sketch can be downloaded without rewiring the breadboard. I want to use in circuit programing not in circuit
    serial programming.

  • Michele Menniti

    Hi Ian,
    which IDE version are you using?
    You did both tests burn bootloader and upload sketches with the micro on-board?

  • http://www.facebook.com/ian.blundell.39 Ian Blundell

    IDE version 1.01, I found the problem the Sketch was set at 19200 and the board is 115200, correcting enabled me to upload a sketch. but now I have to burn the bootloader each time before it will run the sketch correctly although there are no errors reported by averdude.
    Thanks
    Ian

  • Michele Menniti

    I’ve never had problems with the baud rate.
    However, when you upload a sketch with the technique ISP bootloader is automatically deleted.
    You need to burn the bootloader just to change the fuses to the micro, then you can load the sketch as many times as you want.
    Are you following the additional info that I wrote in the post for version 1.0.1?

  • Lukas

    Dear Michele Menniti

    I am sorry to bother you, my problem seems much more basic than all the questions that you have had to answer here. I just started with the Arduino Uno R3 (and have no useful knowledge in electronics whatsoever). I work with IDE 0022 on a MacBook Pro and wanted to burn the bootloader on a ATMEGA328P-PU on a breadboard (my goal is to get sketches like blink on it, but it seems that I am far from it). I have tried many tutorials and collected all kinds of error messages, but since I like your tutorial the most, I decided to ask you the following questions:

    1) first of all: can I use your tutorial with my gear or am I already wrong here?
    2) using your first approach (ignoring the 10uF cap) produces the error message :

    avrdude: Yikes! Invalid device signature.
    Double check connections and try again, or use -F to override
    this check.

    (I am pretty sure my cables are connected in the same way as in your picture)

    3) also the approach with the extra 10uF cap and the modified virtual board does produce this error.

    I am sorry that I have no idea how to get further information where the problem might be. Do you have any suggestion what might go wrong?

    Thanks a lot for any comment! Most likely I am doing a very stupid mistake that I just cannot see.

    best regards,
    Lukas

  • http://www.michelemenniti.it/ Michele Menniti

    Hi Lukas,
    you can burn the bootloader with your configuration. You must not use the 10μF capacitor and even the 120ohm resistor. You have to follow the Tutorial main, it’s for version 0022.
    The error you get depends certainly in connections. You want to email me a photo of your connections between Arduino and breadboard? Some boards choose to burn the bootloader?

    • lukas

      Dear Michele,

      Miraculously, after changing the cables and redoing
      all the connections, it works just fine. I am not sure what really
      changed, but I am most happy that it works. Thanks a lot for your help
      and all the effort to bring your knowledge to newcomers like me!

      Best regards,
      Lukas

      • Lukas

        Just found out what most probably was the problem (in case someone might use this): the microcontroller was not pressed hard enough into the breadboard, hence not all the legs had good contacts to the board. Most probably a beginners mistake..

        thanks again,
        L

        • http://www.michelemenniti.it/ Michele Menniti

          Hi Lukas,
          as I said these types of errors are recurring.
          Thank you for the feedback.
          Best regards
          Michele

  • Juliano Polito

    Another info: I’ve tried doing it using Arduino 0022 and it gives me the same error:

    avrdude: Device signature = 0×000000
    avrdude: Yikes! Invalid device signature.
    Double check connections and try again, or use -F to override this check.

    Thank you.

  • http://www.michelemenniti.it/ Michele Menniti

    Hello everyone, I appeal to all those who write to me.
    I can not give you an answer if you do not give me at least the following information:
    1 – operation that you’re trying to do (burn bootloader, upload sketch)
    2 – the IDE version you are using (0022 or 1.0.1)
    3 – rows of virtual boards you are using (for uploading sketch)
    Moreover, 80% of problems are caused by incorrect connection, should be carefully monitored.
    Finally you must remember that this tutorial is based on IDE 0022, if you use 1.0.1 (1.0 is inappropriate!) Please refer to my post directed @ NukeTheMoon.
    Thanks to all
    Michele Menniti

  • Juliano Polito

    Hi Michele, again!

    Solved it. After a good night sleep, I realized it was a connection problem. Basically I could not see that one of the crystal’s leg was not on pin 10, but on pin 11. I was 4 a.m. I’m really sorry for that, hope I did not take any of your time.

    I could now burn the bootloader and upload a sketch. I need to test it yet, but I’m very confident. And just for the info, although I tried with both 1.0.1 and 0022, after seeing the connection problem I did the upload using 1.0.1.

    Thank you a lot.

    Best regards,

    Juliano

    • http://www.michelemenniti.it/ Michele Menniti

      Hi Juliano,
      I am very happy, I know that many times you something wrong in the connections.
      I did not waste time, do not worry.
      Best regards
      Michele

  • melrick nicolas

    where can i find the sample isp sketch ??? or pls send me the sample to my email add..
    melricknicolas@yahoo.com
    tnx … :)

  • Nicola Romanò

    Hello Michele,

    I am trying to upload a sketch to an ATMega168 (with an external 16MHz clock), using an Arduino Uno. How would I setup the board.txt entry for it?

    thanks

    • http://www.michelemenniti.it/ Michele Menniti

      parli Italiano o preferisci che ti risponda in inglese?

      Ciao

      • Nicola Romanò

        Ciao Michele,

        italiano o inglese è lo stesso :-) puoi anche provare col francese se vuoi!

        • http://www.michelemenniti.it/ Michele Menniti

          Bien :-) si vous voulez que je vous donne une information complète, vous devez d’abord me donner des réponses:
          1 – Générique complet imprimé sur le microcontrôleur
          2 – Version IDE (en particulier la “famille” 002x ou 1.0.x)
          3 – Chargement se faire via bootloader ISP, croquis, ou les deux

          Scherzi a parte mi servono questi dati perché cambiano parametri e procedure: la sigla completa del micro da programmare (quella stampata sul micro stesso), la versione IDE che vuoi usare e inoltre devo sapere se ti basta caricare uno sketch o se devi far uso del bootloader. Ciao

          • Nicola Romanò

            Allora, trattasi di un ATMEL 1122 ATMEGA168A-PU. La versione IDE è 1.0.1. Il bootloader è già preinstallato, mi basta poter caricare uno sketch. Ho provato un po’ a modificare i parametri in boards.txt ma senza successo (in generale ottengo un errore “Invalid device signature”). Grazie mille!

          • http://www.michelemenniti.it/ Michele Menniti

            Dunque, la tecnica ISP ti permette di caricare il bootloader o di caricare uno sketch sovrascrivendo il bootloader; quindi nel tuo caso, con la tecnica ISP puoi caricare lo sketch ma cancelli il bootloader. Se il bootloader è di un Arduino predisposto per il 168 potresti provare a risolvere in modo molto più semplice. Ti indico i passaggi:
            1 – Scollega Arduino dal PC e togli il micro ATmega328P
            2 – Al suo posto (ATTENZIONE alla polarità ed ai pin!) inserisci il tuo ATmega168A-PU
            3 – Collega nuovamente Arduino al PC
            4 – Setta come board il modello: “Arduino NG or older w/ ATmega168″

            5 – Richiama il tuo sketch e fai un normalissimo UPload.

            In questo modo lo sketch si carica senza cancellare il bootloader.

            Se l’operazione non va a buon fine significa che il bootloader è una versione più recente, nel qual caso la cosa si complica, e devi rassegnarti a perdere il bootoloader (che poi non ti serve a nulla se devi usare il micro in stand-alone). In questo caso me lo dici che provo a prepararti una board specifica per il tuo micro.

            Buone prove!

            P.S: Se vuoi approfondire l’argomento scaricati la mia Guida:
            http://www.michelemenniti.it/VHD/Elettronica/GPAT_v4.pdf

          • Nicola Romanò

            Grazie mille per le preziose informazioni! Faccio un po’ di test nei prossimi giorni!

  • MichelP

    Hi, I have been successfully using your directions to program some Atmega328P (PDIP) on a few prototype boards. I would like now to use the same method on an Atmega328P TQFP on a custom PCB powered at 3.3V. The GND, Reset, SCK, MOSI and MISO pins can be wired to my Arduino Uno board, the target chip’s reset pin is tied to the 3.3V through a 10K resistor and I have a 16Mhz crystal with 2x22pf caps . Is there any reason I could not program the chip ? Anything I should do differently?

    Also, I noticed that I had to install the bootloader first in order to use the external crystal. I’m not sure I can burn the bootloader with this setup. Any suggestions ?

    Thanks!

    Michel

    • http://www.michelemenniti.it/ Michele Menniti

      Hi Michel,
      You may NOT program a circuit powered at 3.3 V with Arduino, which runs at 5V, will almost certainly damage it a result of
      differing logic
      levels. Then you
      must to use an
      adapter of
      logic levels or even the simple voltage dividers, to be implemented with two resistors.

      It ‘s normal that you had to first load the bootloader in your micro, in fact this is the only type of operation that allows you to modify its fuse.

      Best regards

      • MichelP

        Hello Michele,

        Thank you for the advice, I should have though about it as it totally makes sense. On top of it, I also realized that I cannot drive the chip at 16Mhz under 3.3V. I think I need to ssomewhat rethink my plans…
        Regarding the bootloader, thank you for confirming.

        Best Regards,
        Michel