{"id":938,"date":"2013-02-12T02:54:29","date_gmt":"2013-02-12T01:54:29","guid":{"rendered":"http:\/\/www.sciencetronics.com\/greenphotons\/?p=938"},"modified":"2025-06-16T18:38:15","modified_gmt":"2025-06-16T16:38:15","slug":"hacking-an-avr-programmer","status":"publish","type":"post","link":"https:\/\/www.sciencetronics.com\/greenphotons\/?p=938","title":{"rendered":"Hacking an AVR programmer"},"content":{"rendered":"<p><strong style=\"color:red;\">(see also my recent appendix to this topic: <a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/?p=1937\" style=\"color:red;\">Hacking an AVR programmer II &#8211; especially if you have an ATmega88-based programmer!<\/a>)<\/strong><\/p>\n<p>On eBay I recently purchased a set of cute small USB AVR programmers which I intend to use in the course <a href=\"http:\/\/www.uu.se\/en\/education\/master\/selma\/kursplan\/?kKod=1TE663\" target=\"_blank\">1TE663 Microcontroller Programming at Uppsala University<\/a>.<br \/>\n<figure id=\"attachment_943\" aria-describedby=\"caption-attachment-943\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/USB-ISP-Programmer.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/USB-ISP-Programmer-300x195.jpg\" alt=\"\" title=\"USB ISP Programmer\" width=\"300\" height=\"195\" class=\"size-medium wp-image-943\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/USB-ISP-Programmer-300x195.jpg 300w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/USB-ISP-Programmer-150x97.jpg 150w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/USB-ISP-Programmer.jpg 335w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-943\" class=\"wp-caption-text\">MK-USBISP-V3.00 programmer in an aluminum shell on eBay.<\/figcaption><\/figure><br \/>\nAfter waiting for one month for the delivery from China the package finally arrived today. Unlike other programmers which I purchased before, these come with a sturdy aluminum shell and in happy colors.<\/p>\n<p>However, connecting the first programmer to my PC brought me quickly back to earth &#8211; it was not recognized as an USBasp. OK, it would not be the first delivery from China with broken or counterfeit electronics, so I tested the second one&#8230;<\/p>\n<p>At that time I got a bit confused, because the programmer registered as an HID unit on the USB with vid=0x03EB &#038; pid=0xc8b4. Not as an USBasp with vid=0x16c0 &#038; pid=0x05dc.<\/p>\n<p>This is the point where I usually ask Google. So I did and I found some threads discussing the same issue and pointing out, that these programmers needed a different software and were not at all compatible with avrdude. BAD!<\/p>\n<p>But of course, one should be able to reprogram the programmer using another programmer. At my home this is not a henn and egg problem, since I have accumulated several AVR programmers. <\/p>\n<p>Ok, I downloaded the <a href=\"http:\/\/www.fischl.de\/usbasp\/\" target=\"_blank\">USBasp firmware from Thomas Fischl<\/a>, flashed the programmer after inserting the self-programming jumper:<br \/>\n<figure id=\"attachment_939\" aria-describedby=\"caption-attachment-939\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/IMGP0586a.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/IMGP0586a-300x230.jpg\" alt=\"\" title=\"IMGP0586a\" width=\"300\" height=\"230\" class=\"size-medium wp-image-939\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/IMGP0586a-300x230.jpg 300w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/IMGP0586a-150x115.jpg 150w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/IMGP0586a-400x307.jpg 400w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/IMGP0586a.jpg 724w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-939\" class=\"wp-caption-text\">Self-programming jumper on the MK-USBISP-V3.00 AVR programmer.<\/figcaption><\/figure><\/p>\n<p>Since the original firmware is protected by the lock-bit fuses, I had to fully erase the chip first, then set the fuses correctly to HFUSE=0xc9  LFUSE=0xef and then flash the .hex file. I tried first the 2009-firmware from Thomas Fischl and the first observation was that instead of the red LED which was on previously, now the programmer showed a blue light.<\/p>\n<p>But: Windows would not at all recognize this device as any USB device. Nothing showed up. I got confused. I tried both WinXP and Win7 &#8211; to no avail. Well, perhaps this programmer was not hardware compatible to the USBasp? Let&#8217;s have a look&#8230;<br \/>\n<figure id=\"attachment_940\" aria-describedby=\"caption-attachment-940\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0589a.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0589a-300x159.jpg\" alt=\"\" title=\"Imgp0589a\" width=\"300\" height=\"159\" class=\"size-medium wp-image-940\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0589a-300x159.jpg 300w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0589a-150x79.jpg 150w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0589a-400x212.jpg 400w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0589a.jpg 886w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-940\" class=\"wp-caption-text\">AVR programmer MK-USBISP-V3.00: component side.<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_941\" aria-describedby=\"caption-attachment-941\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0588a.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0588a-300x150.jpg\" alt=\"\" title=\"Imgp0588a\" width=\"300\" height=\"150\" class=\"size-medium wp-image-941\" srcset=\"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0588a-300x150.jpg 300w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0588a-150x75.jpg 150w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0588a-400x200.jpg 400w, https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/Imgp0588a.jpg 921w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-941\" class=\"wp-caption-text\">AVR programmer MK-USBISP-V3.00: solder side.<\/figcaption><\/figure><\/p>\n<p>There are some tiny, yet important, differences to  the original USBasp programmer: in the USBasp USB-D- is connected to pin PB0, USB-D+ to PB1 and PD2\/INT0. Here also USB-D- was connected to a pin on port D: PD3\/INT1. Well, this should not really make a difference, and I continued my search for differences. OK, for some reason, also the LEDs are connected in parallel to 2 port pins each &#8211; so what&#8230;<\/p>\n<p>In despair I decided to look into the source code of the USBasp firmware. The header files: OK &#8211; pin assignments were as expected, nothing special here. But let&#8217;s wait, where is the definition of the utilization of port D? Well, it was in the main.c file:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:435px;\"><div class=\"text codecolorer\">int main(void) {<br \/>\n&nbsp; uchar i, j;<br \/>\n<br \/>\n&nbsp; \/* no pullups on USB and ISP pins *\/<br \/>\n&nbsp; PORTD = 0;<br \/>\n&nbsp; PORTB = 0;<br \/>\n&nbsp; \/* all outputs except PD2 = INT0 *\/<br \/>\n&nbsp; DDRD = ~(1 &lt;&lt; 2);<\/div><\/div>\n<p>hey &#8211; wait a second? All pins of port D are defined as output, except for PD2\/INT0? I always tell my students to only define pins as output, which are really used as output&#8230; And what happens here? <\/p>\n<p>Since the modified design also connected USB-D- to PD3\/INT1, the rather aggressive definition of output pins leads to a unsolvable conflict, when suddenly PD2 is driving against the USB signals from the host!<\/p>\n<p>Changing this little piece of code solved the problem. Rather conservative I set all pins of port D as input (none of them is currently used as output!):<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:435px;\"><div class=\"text codecolorer\">int main(void) {<br \/>\n&nbsp; uchar i, j;<br \/>\n<br \/>\n&nbsp; \/* no pullups on USB and ISP pins *\/<br \/>\n&nbsp; PORTD = 0;<br \/>\n&nbsp; PORTB = 0;<br \/>\n&nbsp; \/* all PDx input *\/<br \/>\n&nbsp; \/* MK-USBISP v3.0 *\/<br \/>\n&nbsp; DDRD = 0x00;<\/div><\/div>\n<p>I compiled the code, flashed it onto the AVR programmer using another AVR programmer<br \/>\n&#8230;and behold: it works!<\/p>\n<p>I will contact Thomas Fischl and tell him about this observation &#8211; perhaps the modification will be implemented in the distributed firmware on his homepage.<\/p>\n<p>Here is a .zip-archive of the modified firmware. The .hex file for use with an ATmega8 is found in the <em>default<\/em> subdirectory.<br \/>\n<a href='http:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/20130212_mega8_usbisp.zip'>Download ZIP archive: 20130212_mega8_usbisp<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(see also my recent appendix to this topic: Hacking an AVR programmer II &#8211; especially if you have an ATmega88-based programmer!) On eBay I recently purchased a set of cute small USB AVR programmers which I intend to use in the course 1TE663 Microcontroller Programming at Uppsala University. After waiting for one month for the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":943,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[46,22,11,8],"tags":[],"class_list":["post-938","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-avr","category-computers_en","category-electronics_en","category-everything_en","entry","has-media"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.sciencetronics.com\/greenphotons\/wp-content\/uploads\/2013\/02\/USB-ISP-Programmer.jpg","jetpack_shortlink":"https:\/\/wp.me\/p48grL-f8","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts\/938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=938"}],"version-history":[{"count":17,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts\/938\/revisions"}],"predecessor-version":[{"id":2477,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/posts\/938\/revisions\/2477"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=\/wp\/v2\/media\/943"}],"wp:attachment":[{"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sciencetronics.com\/greenphotons\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}