Introduction: Turn Arduino's Serial Converter Into AVRISP MkII Clone
I'll show you how to use Arduino’s USB-serial converter as AVRISP mkII. Process is completely reversible. You’ll need:
- Arduino UNO, or any other board with ATmega16U2 or 32U2 (8U2 has too small flash) USB-serial converter,
- Some wires,
Optionally for ATmegaXXU2 without DFU bootloader (mainly clones or counterfeit boards):
- Other Arduino, ISP programmer or standalone serial adapter.
Step 1: Going Into DFU (and Also Cheking If You Have It)
You have to disconnect your board short XXU2's reset to GND with some wire or jumper, connect it again to USB and unshort that pins.
New device ATmega16U2 should appear in Your system (you can skip next step)
You might need driver for it, which is included in Flip's folder (step 3)
If nothing like this happen You have to burn new bootloader into XXU2 (next step).
I used this page as reference: Arduino's guide to programming XXU2 through DFU protocol
Step 2: Burning DFU Bootloader
Simplest way I found was to burn new bootloader with Arduino IDE. I used HoodLoader2 project for more simplification:
Add new entry to Arduino additional boards manager (file > preferences)
You have to connect XXU2’s ISP header to your programmer.
As programmer You can use:
- other Arduino: ArduinoISP tutorial
connect Arduino's 10,11,12,13 to ATmegaXXU2’s RST, MOSI, MISO, SCK respectively and also connect poder
- the same Arduino board with another serial converter (same tutorial as previous): just connect ATmega328’s pins 10,11,12,13 to ATmegaXXU2’s RST, MOSI, MISO, SCK respectively and ATmega328 RxD TxD to TxD and RxD of your serial converter (as on included pic)
- AVR programmer from Arduino IDE’s list.
Select your ATmegaXXu2 and DFU (I have 32U2 on my clone).
Than burn bootloader and go back to step 1.
Step 3: Uploading AVRISP Hex
Download hex file
with AVRISP mkII firmware:
I used this forum http://forum.and-tech.pl/viewtopic.php?t=1398 (Its included in first post, select newest version)
You can probably also use Olimex’s page https://www.olimex.com/Products/AVR/Programmers/AVR-ISP-MK2/open-source-hardware
And-tech’s forum version have three options, so choose NORMAL for Atmel Studo.
For uploading you can refer to DFU programming 8U2
On Windows download Atmel’s Flip , open it, select uC, select osb, open it, select hex and download it.
Step 4: Solder Pin for PB4 (ISP Reset)
You can refer to pictures, soldering that pin that shouldn't be problem.
Step 5: Try It With Atmel Studio
Download Atmel Studio, install it and open.
You might have to install driver manually from: Atmel\Studio\Drivers\inf\avrispmkii
Connect Your new AVRISP mkII to some ATmega nad than to USB.
Select Available Atmel tools from View menu, press RMB on AVRISP mkII, select device and apply, set 16,1kHz clock and read device signature.
You can now read/set fuses, check memories and program your device.
Your Arduino (I mean ATmega328 and AVRISP mkII) is great setup for start Elliot Williams' MAKE: AVR Programming (I reccomend this book)
Step 6: Some More Info
As you may notice this setup is not fully compatible to AVRISP mkII, but you can do it adding few resistors and level translator chip, just follow this hackaday article (autor says that you should not use MAX3002 level translator IC but GTL2003 or Olimex's schematic (which does not have level translator)
I believe, that this insctructable would work with ease on Arduino Micro and Leonardo and would give you simple way to add level translator and easy acces to TPI and PDI protocols' pins for few ATtiny (most of theme have ISP) and ATXmega.
For going back you can again burn HoodLoader2 DFU bootloader with serial or follow Arduinos tutorial DFUProgramming8U2.
You can compile hex files with Arduino IDE just show verbose output of compiler (file>preferences). Hex location is in one of last lines.
You can upload any hex with Atmel Studio View>Select Available Atmel tools>RMB on AVRISP mkII>Device Programming>select device and apply, set 16,1kHz clock and read device signature. Go to memories and program uC with desired hex.
And this unfortunately :( (copied from Olimex's Q'n'A):
Q:I have performed a firmware switch. My drivers are properly installed. Still I can't properly program my target with AVRDUDE. I also tested with the latest Arduino IDE. What is the problem? Is my programmer bricked?
A: The hardware of your AVR-ISP-MK2 is fine. There is a software bug that affects LUFA-based programmers in newest releases of AVRDUDE. Either use AVRDUDE versions prior to 6.x.x or apply this patch to the AVRDUDE sources and compile.
I was unable to program ATmega328 onboard Arduino unless I cut RESET EN pad (I mean reset line, because my clone doesn't have pad :( see photo) because AVRISP mkII uses reset pin of XXU2 for something else. You can cut it (solder them back together or reset every time you upload sketch when you to go back to Arduino) or transfer ATmega328 to breadboard and connect it's XTAL pins to to crystal on Arduino board in order to program and change fuses (don't be afraid of them, they are simple stuff, just change oscillator to internal 8MHz if you want to use ATmega328 without additional XTAL wires - you'll gain additional 2 pins) or buy yourself a 16MHz crystal.
According to all of this you should be able to upload sketches to your ATmega328 with Arduino IDE, but you have to:
1. Change AVRDUDE in \Arduino\hardware\tools\avr\bin to older or compiled with patch, and may be it's config file in Arduino\hardware\tools\avr\etc. Or try older IDE.
2. Cut/desolder RESET-EN pad on your Arduino board.
3. Select AVRISP mkII as programmer.
4. Program it with Upload using programmer commend (Ctrl+Shift+U)
This is just theory, I didn't test it. I'm using Atmel Studio, which has Arduino extension for importing sketches.
Participated in the
Arduino Contest 2016