USB Key AVR Programmer

2 09 2011

So, you saw some AVR microcontrollers and you decided they are cute (they really are!). If you choose to work in plain C what you need is just a toolchain (you probably have some package ready for your distribution), the avr-libc library, a programming software like avrdude and a hardware programmer!

While you can freely download all the software you need, including the source code, for the programming hardware you have to choose between buying a commercial programmer (either from Atmel or some third party) and building your own.

What I’m publishing in this post is my version of the popular USBasp, an open source USB AVR programmer design from Thomas Fischl.

My version is a USB key-like design, using many SMD parts and a very small PCB. You can take it with you everywhere!

The microcontroller I used is an ATMega168-20AU, the SMD version with TQFP package. All passive components are in 0805 package, the clamping diodes are in SMA package, the USB connector is a PTH footprint (but an SMD one will fit fine) and the programming connector is side mounted.

Programming Header

There are currently two footprints for the programming connector of AVR controllers: the most common one, which is the one used in this design, is the one proposed by Atmel in the AVR910 application note.

The pinout is the following:

Please note that VCC pin can be used either to power the logic signal of the programmer at the correct target voltage (as it happens with the AVRISP mkII) or to power up the target hardware from the programmer itself.

Jumpers

This USBasp design, as the original one, provides a 2×1 jumper to send 5V power to the target, but there is an additional series resistor as a safety against short circuit.

Also, an additional 2×1 jumper is used for the initial programming and reprogramming of the device firmware. If you don’t have another programmer available and you need to program your first “smart” programmer, check out the parallel port BSD programmer (which was what I first used).

The third 2×1 jumper is used to manually select the low speed programming mode, which is what you need the first time you program an AVR device, as the default configuration for the microcontroller is to run at 1MHz, and the default programming speed of an USBasp is too high (the maximum programming speed is 1/4 of the system clock).

This jumper is not necessary anymore as the programming speed can be changed via software, using the -B flag of avrdude.

Other Information

The one drawback of this design is that it only runs at 5V, so you need a couple of clamping zener diodes to limit the USB signal voltage. If you can’t find the SMD diodes, try using some white LEDs, they should have the right voltage drop and it’s nice to see the lights on the USB traffic!


Also, you should only use this to program 5V devices… 3.3V ones should work but you would push the target logic well over its limits. It may work for some time, but don’t blame me if this sets on fire your latest-greatest-funkyest project! Anyway, I do that quite often. Just don’t tell anyone… Ok?

A final note is that this design is not firmware compatible with the Thomas’s one, as the GPIO pin mapping was changed to simplify the layout.

You can download my version of hardware and firmware for this design from GitHub.

The schematics in PDF version can be downloaded from here.

Happy programming!

Update!

The PCB is available on BatchPCB!

Advertisement

Actions

Information

42 responses

7 09 2011
someshmahanty

can i buy one from u? how much does it cost?

7 09 2011
fabiobaltieri

Hi Somesh!

Thank you for the request, but I’m not currently selling it. Maybe I’ll do that in the future if more people ask for it…

In the meantime, if you want to build one like mine, I suggest you to build the PCB on http://batchpcb.com/, they are really cheap and that’s what I’m using! The microcontroller and passive components can be bought on eBay (search for 0805 and 0603 kits). As for the rest I usually recycle components from old boards, but you can easily find everything online (like on Farnell or Digikey).

Alternatively, Thomas sells the components for his through-hole version, check out his website!

Cheers.

8 09 2011
danjovic

Nice work. I suggest you to use the AVRminiprog firmware, compiled for USBASB Hardware.
I have a single sided version for USBASB hardware that was placed inside a mint case https://picasaweb.google.com/lh/photo/4Hwhfr3F34Pf8XGblY6luw?feat=directlink

[]s
Danjovic

8 09 2011
fabiobaltieri

Interesting design! I like the idea of recycling stuff… that mint case is perfect for USB gadgets!

I’ll take a look at the AVRminiprog fw.

Thanks.

14 10 2011
Massa

Hi,

Mine is inside a Mentos power-kiss case. Its dispenser is well sized for mini-usb, so I could make a programmer with detacchable cable, using ATMega88.

Rgds,
Massa

18 09 2011
Rahul

i have connected Atmega 8 hardware but is not responding. Kindly respond immidiatly

Rahul M

19 09 2011
fabiobaltieri

Hi, what you mean by “it’s not responding”? Are you trying program something or you are referring to the programmer itself?

17 10 2011
31 10 2011
Resty
16 11 2011
Blagovest Zhelev

Hello
I saw your usbasp and I was wondering can I order from BatchPCB your design ? I like it very much and great work.

16 11 2011
fabiobaltieri

Hi!

Thanks for the comment, I published the design on BatchPCB and updated the post with the direct link.

Alternatively you can also download Eagle (the Freeware version is ok!), open the .pcb file and regenerate the gerber from that!

Cheers.

21 11 2011
printed circuit board

Wow! Such a brilliant post i will try to make this one and thanks a lot for share its PDF file with programming details.

29 11 2011
Breno lima

Boa tarde,
sou do Brasil, antes de mas nada, obrigado.
estou querendo fazer uma interface usb que simule 10 teclas de um teclado normal abnt, você recomedaria que projeto já pronto?

29 11 2011
fabiobaltieri

Hi Breno!

From what I understood from google translator you want to build a 10 key USB keyboard… if that’s correct take a look to the HIDkeys project from obdev, that’s really simple 17 key USB keyboard based on the obdev V-USB firmware (the same used by the USBasp programmer).

Link: http://www.obdev.at/products/vusb/hidkeys.html

Bye!

11 12 2011
edy

How to install usbasp firmware to aTmega8 before it can be used?

11 12 2011
fabiobaltieri

Hi!

You need another programmer. What I used the first time was a parallel port programmer, which doesn’t use any microcontroller but just a parallel port connector and three resistors. You can find a link in the post!

Good luck!

15 12 2011
edy

Oh I see. In the folder “firmware” that u share, what file should i program to the ATmega?

15 12 2011
fabiobaltieri

The firmware folders contains the firmware source code, which you can use to firmware binary with the “make main.hex” command on a Linux system or (I think) with the gnuavr package on a windows system.

22 12 2011
Dhany

hi
Mr Fabio, sorry if my english is not good,
I want to ask, can I install the firmware using a usb programmer the other (such as USB ISP, not a parallel programmer), and can I use this USBasp to program the MCS-51?
and in fact I am still confused with the firmware (actually I am a newcomer to the field of microcontroller, and that’s why I’m asking a lot) ATMega 8 chip can accommodate flash memory up to 8 kb, but the firmware is too big I think, can you explain to me, please. …
thank you very much …

23 12 2011
fabiobaltieri

Hello Dhany,

of course, to program the firmware on the programmer you can use any other programmer! For the flash memory, the memory of the microcontroller of the programmer is only used to store the programming firmware, so you can program any ISP-based AVR with it, independently by its flash size.

As for the MCS-51/8051, this programmer can only be used on Atmel AVRs with an ISP interface, so you can’t use it on anything else, and while in principle you can modify it to support other MCUs, this is going to be a pretty big effort if you are a newcomer.

Hopes it helps!

24 12 2011
Dhany

thanks, it would be helpful
but I am still confused with the firmware, atmega 8 can accommodate up to 8 kb flash memory, but the size of the firmware, I see 11 kb, whether atmega 8 can accommodate firmware exceeds its memory capacity ?

24 12 2011
fabiobaltieri

How are you checking the firmware size?

In my build the .hex file is 11kB, but that file is in Intel HEX format, so you have to use avr-size to check the size of the binary code in it, which in my case is little less than 4kB, as in:

$ ls -l main.hex
-rw-r–r– 1 balto users 11002 Dec 24 14:58 main.hex
$ avr-size main.hex
text data bss dec hex filename
0 3902 0 3902 f3e main.hex

Of course, if the output of avr-size is more than 8kB, the firmware cannot fit an ATmega8, but that should not be the case for usbasp… in fact it should fit also on an ATmega48!

31 12 2011
andryan

i have plans of building the fischl circuit before that i want to be sure if it can do the job.

can this programmer burn the at89c2051 mcu?
i not sure because i saw programmers that can only program at89c2051.
they also say that at89c2051 don’t support ISP.

7 01 2012
fabiobaltieri

Hi Andryan,

Atmel AT89 series microcontrollers are 8051 based (so they are *not* AVRs), and they cannot be programmed using the usbasp firmware/hardware. I’ve never used one but looking at the datasheets the at89c2051 can use only high voltage programming, so it’s very hard to program that one in-system. Other chips of the family have a serial bootloader, which I think you can use with the FLIP software from Atmel and a generic USB-serial converter.

Bye.

9 01 2012
viks

Hello,

I have built Your device using PCB from BatchPCB, Your firmware and Atmega8-16AU. Successfully programmed bin and fuses. When i’m inserting it into PC (Linux) i see:

[ 8289.244101] usb 6-1: new low speed USB device number 68 using uhci_hcd
[ 8289.368124] usb 6-1: device descriptor read/64, error -71
[ 8289.596104] usb 6-1: device descriptor read/64, error -71
[ 8289.812105] usb 6-1: new low speed USB device number 69 using uhci_hcd
[ 8289.936073] usb 6-1: device descriptor read/64, error -71
[ 8290.164674] usb 6-1: device descriptor read/64, error -71
[ 8290.380108] usb 6-1: new low speed USB device number 70 using uhci_hcd

Where can be the problem?

9 01 2012
fabiobaltieri

Hi Viks,

I’ve had similar problems with certain PCs when using the clamping diodes on the USB D+/D- lines. Currently I only use White LEDS (the one in broken laptop LCDs are good!) in place of clamping diodes and they seems to work better.

Can you try to swap that components for something else?

9 01 2012
viks

I will try at the end of this week.

10 01 2012
viks

Soldered 2 blue leds instead of zenner diodes. Now leds blinks when inserting into USB, but device is still not detected.
After insertion one blue led is on an other is off. Voltage on lit led is 2.65V (when using zenner diodes voltage on sam led is 2.92V).

10 01 2012
fabiobaltieri

That’s strange… are you using the correct values for the fuse bytes? The one in my Makefile are for the ATMega168 but the lfuse and hfuse bits are different in the ATMega8…

Anyway, the led behavior seems ok… I’ll check the voltage values on my board tonight!

10 01 2012
viks

I used fuse values for atmega8 from comments in Makefile.
TARGET=atmega8
HFUSE=0xc9
LFUSE=0xef

10 01 2012
fabiobaltieri

Looks correct… I mine samples does 2.6-2.7V on the bus when idle (led lit) and works correctly with ATMega168-20AU and firmware as on my github.

I have an ATMega8-16AI laying around… I’ll try to mount it on one board just to check if it works in next days.

10 01 2012
viks

Is this ok for Atmega8 to be clocked at 12MHz?

11 01 2012
fabiobaltieri

That’s ok, you can try to change or remove the load capacitance if you suspect problems with that.

Anyway, I put an ATMega8-AI on one of my boards this morning, in the firmware I just used TARGET=atmega8
HFUSE=0xc9
LFUSE=0xef

rebuilt the firmware, reflashed and it works correctly. Are you sure you rebuilt the firmware after changing TARGET to atmega8? The makefile is not safe for changes and you have to manually issue a “make clean” after any change…

12 01 2012
viks

I have changed Makefile before building anything.
Can You send me compiled firmware?

12 01 2012
fabiobaltieri

Sent!

13 01 2012
viks

Thank You very much! Flashed Your firmware. Now USB device is detected. Seems like there was something wrong with compilation. At least now i know where to dig.

13 01 2012
fabiobaltieri

Good to know!

You can try to build a toolchain from sources, I think mine is built with these instruction:

http://projects.qi-hardware.com/index.php/p/ben-wpan/source/tree/master/atusb/fw/README

Cheers.

13 01 2012
Msd

Thank you for your great job.
will you send me hex file for Atmega8. I have problem making it for Mega8.

13 01 2012
fabiobaltieri

Hi!

Just committed the binary images for ATMega8 and ATMega168 into the GitHub repository in the binaries/ directory… pull it out!

13 01 2012
Msd

Thank You very much!. hope to to put it together this weekend.

13 01 2012
joans

usb device not recognized, what should i do?

14 01 2012
fabiobaltieri

Checkout prebuilt firmware images and voltage level on USB lines!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.