Introduction: Integrate ArduinoISP and Atmel Studio

Picture of Integrate ArduinoISP and Atmel Studio

Want a cheap solution, or even a spare solution for AVR programming? Worry no more, with this tutorial you will learn how to use an Arduino Uno as an AVR programmer that can be putted into action straight from the Atmel Studio 6.

In this tutorial we will be using the ArduinoISP sketch alonside with AVRDUDE and Atmel Studio to perform the full smooth integration between coding in Atmel Studio and deploying your code to your AVR microcontroller.

Step 1: Peparing Your Arduino

Picture of Peparing Your Arduino

Since we will be using the Arduino Uno as an ISP programmer, we first have to upload a sketch that will be responsible for receiving data through the serial port (USART) and outputting it correctly to the target microcontroller through their SPI ports.

So, open up the Arduino IDE, go to File>Examples>ArduinoISP.

Once the sketch is open, on the top of the file, some comments are made on pin names and connections. Those will be addressed on the next step, but make sure they match with the tutorial.

Connect your arduino and fire the Upload button away. It takes a little more tha usual but don't worry.

Step 2: Connecting Your ArduinoISP Programmer to Your AVR

Picture of Connecting Your ArduinoISP Programmer to Your AVR

For this first step you will need the following materials:

  1. Jumper wires of saveral colors (yes they matter);
  2. 01 RED LED
  3. 01 YELLOW LED
  4. 02 LEDs of different colors, your choice (we are using blue and white)
  5. 01 10uF electrolytic capacitor
  6. 04 200 ohm 1/8W resistors

These other materials are project-dependent. In our case, we are going for a solution that uses a 8 MHz crystal and an internal clock with the same value. Therefore:

  1. 01 8 MHz crystal
  2. 02 20 pF ceramic capacitors

Hook all the components together according to the picture.

Do notice that for each trail that receives one of the lead of the crystal, there is a ceramic capacitor connecting this trail to the ground trail.

The LEDs' anodes are identified by the slight curve their leads have. Pay attention to the white LED, the one to be blinked by the code that will be loaded. Due to a software limitation, that doesn't allow component flipping, the LED ended up being crossed.

The electrolytic capacitor is polarized, therefore make sure you have the longer lead connected to RESET while the smaller one is connected to GND. This will filter out the automatic reset signal, disabling it.

A good advice is to keep the jumper wires in the same color code as the one shown in the picture. This helps further hardware debugging.

Step 3: Integrating Atmel Studio

Picture of Integrating Atmel Studio

Since you have used the Arduino IDE to load the ArduinoISP sketch to your Arduino board, this means that you already have AVRDUDE installed in your computer.

AVRDUDE is a command line application that intermediates the firmware loading process on your computer side. Long story short, AVRDUDE reads the .hex file produced by the compilation and translation process and queues it in order to output it correctly through the serial port. From there the USB-serial converter on your Uno board (the black square next to the USB port) reads it from the USB line, sends it to the ATMEGA on the Arduino Uno board and finally outputs it through SPI to the target microcontroller.

One of the coolest features of Atmel Studio is the support to external tools, like the AVRDUDE itself. Basically, Atmel Studio leaves this open enough to customization, that with the press of a button, you can perform a full command line program call and deploy your firmware to the target microcontroller.

Enough said,

Open Atmel Studio 6.

Go to Tools>External Tools

Fill in the fields as the picture shows. The Command field is to be filled with the location avrdude in your machine, in my case: C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe

As to the Arguments field, fill in with the following line:

-U lfuse:w:0xe6:m -U hfuse:w:0xd9:m -e -v -patmega328p -carduino -PCOM2 -b19200 -D -Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i -C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

Those are the firmware deployment arguments or information to be interpreted by AVRDUDE and converted into write actions.

In this line there are three main things to be altered:

  1. The COM port you are using your Arduino Uno on. In order to check, go to Device Manager>COM&LPT Ports and you should see Arduino listed.
  2. The file path where to find avrdude.conf. A simple windows search should get you going with that.
  3. The fuse bits value, depending on how you have planned your projects configuration. Simply change the hex value in the middle of -U lfuse:w:0xe6:m and the fuse name you intend to configure.

Pay attention to the portion of the line with the .hex in the middle. That's the reference in the arguments to where AVRDUDE will look for the file. $(ProjectDir) and $(ItemFileName) are bash script variables and will be replaced according to your project name and location propely once the &Deploy action is called.

The other arguments are just guidelines to AVRDUDE concerning the target microcontroller and where to find the firmware file and the AVRDUDE configuration file.

Basically, this line of arguments makes AVRDUDE execute 4 write operations:

  1. The first writes the low fuse of the AVR
  2. The second, the high fuse
  3. The third operation is a full flash memory erase, as way to avoid write errors
  4. And the fourth a full flash memory write with the firmware

For a full list of arguments, go to : https://asensar.com/blog/2013/programming-arduino-using-avrdude/

Step 4: Compile It and Deploy It!

Picture of Compile It and Deploy It!

Once all the configuration is done, it's time to test it!

Write a simple LED blink firmware to your target microcontroller, like the one in the picture, and compile it.

Once it finishes, go to Tools>Deploy.

You should see something like the screen on the picture on the output window. That's an AVRDUDE verbosed output, telling you what it has executed.

First it shows some deployment info, then some memory stats, that really come in handy for larger projects, and finally it outputs the write operation summaries. Here you can observe 3 of the 4 writes that were mentioned before. The two fuses plus the flash.

Once this is complete you can already see your code working through your blinking LED! Congrats!

This configuration stays permanent for all your following projects, so don't mind having to do it all again. The one thing you might change from project to project is the fuses configuration that will have to be reconfigured on the arguments field of the previous step.

For the best fuse calculator, check: http://www.engbedded.com/fusecalc/

TROUBLESHOOTING:

It is possible that you run into AVRDUDE not being able to find or open your COM port. Should that happen, make sure you don't have your Arduino IDE open. This will cause AVRDUDE to try to claim the COM port while it is connected to the Arduino IDE. To solve that, close the Arduino IDE, disconnect the board from the computer, close Atmel Studio, reconnect the board, and then restart Atmel Studio 6.

I hope you have enjoyed it! Cheers!

Comments

zanod (author)2017-10-29

When I started in AVR processing, this article was very helpful - but also costly, as I have just lost 4 ATtiny85's as a result of it. I went to the guys at AVRFreaks to ask if they were recoverable, and they immediately picked out the "-F" in the parameter string to AVRDude, which is a frequent cause of questions to their forum.

See the thread at

http://www.avrfreaks.net/forum/my-at85-bricked-can-it-be-recovered#comment-2309006

I was asked to update this thread with the following (from them)...

"WARNING! Never, NEVER, use the -F switch unless you know
exactly what you're doing and understand the possible consequences. The
-F switch incapacitates checks that you've selected the correct AVR
model, and results in AVRDUDE "blindly" programming your chip as if it was
the one you've selected on the AVRDUDE command line. If it actually
isn't (e.g. you've made a typo on the command line) then it might render
your AVR "bricked" (impossible to program) and hard to
resurrect from that state, possibly requiring a "parallel programmer"
(a quite rare type of programmer these days - your programmer most
likely isn't one of those).

REPEAT: Never, NEVER, use the -F switch on the avrdude command line.
If you're having trouble programming your AVR then there is a fault
somewhere and -F is not the solution!

Also, see

http://www.nongnu.org/avrdude/user-manual/avrdude_...

for the command line parameters.

felipemundy (author)zanod2017-10-30

Hi there zanod! I appologize for the inconvenience, I will edit that out. PS: the -F was never a problem for me and I recall getting that line from another tutorial. But, again, I will edit it out to avoid further accidents with other users. Thank's for the head's up!

zanod (author)felipemundy2017-10-31

felipemundy - In the end result, the -F wasn't a problem for me either - it turned out to be something different, but when I went to AVRfreaks for help, one of the guys noticed it in about 50mS, and flagged it, then they all started discussing it. They have seen it pretty often as a cause of problems.

AVRdude takes a bunch of parameters from the command line, among which is the chip type. When AVRdude looks at the target chip, it reads its signature, which is a 3-byte number, and compares it with what it should be according to the chip type in the parameters. That way, it avoids destroying chips if you have accidentally put in the wrong type. If, however, you have put a -F among your parameters, it ignores the result of the test - though I think it still logs something to the screen.

I believe that in rare cases, you can get a processor that has a corrupted signature, in which case, you can still program it by using the -F - but it should only ever be used in a one-off situation.

zanod (author)2017-03-19

It's not working for me. My project is called "Reg2Scope", and the hex file is called "Reg2Scope.hex"

When I try to send the file to my target (ATtiny85), everything seems to work ok - the fuses are written etc, but it fails when trying to write "main.hex" - which doesn't exist. It appears that

$(ProjectDir)Debug\$(ItemFileName).hex

does not substitute the right name.

BTW, I'm using the currently-available Studio-7. Your instructions were written for Studio-6.

Craig12345 (author)2016-03-31

Felip,

Thanks for the blog. A couple of things I noticed. One was the fritzing diagram shows the led connected to portd pin 7, not 6. The other was my IDE didn't recognize PD6 so I substituted with PIND6. Both of these issues are maybe due to my inexperience - but I thought I would offer this for others who might have difficult and know better than me.

GuilleT1 (author)2016-02-23

hi, hope you read this!

when I click deploy I get this:

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0xffffff (retrying)

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x000000

avrdude.exe: Yikes! Invalid device signature.

avrdude.exe: Expected signature for AT90S2313 is 1E 91 01

avrdude.exe: safemode: Fuse reading not support by programmer.

Safemode disabled.

avrdude.exe: erasing chip

"lfuse" memory type not defined for part "AT90S2313"

avrdude.exe done. Thank you.

my argument line is :

-U lfuse:w:0x64:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m -e -F -v -p2313 -carduino -PCOM3 -b19200 -D -Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i -C"C:\Users\asdasdas\Desktop\arduino-nightly\hardware\tools\avr\etc\avrdude.conf"

I'm Programing a attiny2313a with 8mhz internal clock, i read that I need to put -F to override the signature from de attiny2313 since they have the same signarute, but it doesn't seem to work, help me please!

tomatoskins (author)2015-09-28

Such a cool idea! Thanks for sharing and welcome to the community!

felipemundy (author)tomatoskins2015-09-28

Thanks for the support @tomatoskins!

About This Instructable

20,799views

19favorites

License:

More by felipemundy:Integrate ArduinoISP and Atmel Studio
Add instructable to: