Thursday, June 11, 2009

The Year Long Tale of USBasp

It all started during summer of 08. After completing the Embedded Robotics the previous semester , I realized that the plain simple Parallel Port Programmer that we were using till then for programming the AVR microcontroller was not just sufficient for programming. It is a big pain when you need a PC with a parallel port and the every time you have to burn a new code in the micro-controller you need to physically bring the robot to the PC or in the worst case you have to take the IC out every time and put it on the programmer board, flash the code, remove it and again put it back in the robot's circuit. More so I was thinking that for competitions like Robocon we needed a programmer that is more efficient and can be used with a laptop ie USB port.

So after some googling I came across USBasp and some other USB programmer like AVR Doper. The simplicity of USBasp appealed in the first look. So I quickly soldered one PCB of the USBasp circuit. But some issues came up. First I found that the Atmega8 in USBasp was running at 12MHz and according to data sheet of ATMega8 only ATMega8 can support 12MHz CPU clock frequency and ATMega8L can clock only upto 8MHz, now here in Hyderabad (Gujrati Gali) mostly ATMega8L is available and so I tried desperately to find a ATMega8 to have USBasp completed. Somehow I found one.
Now when I tried to test the circuit it gave error "USB device not recognized" and after checking the circuit again and again I could not find where the problem is so I abandoned the whole thing.

When the summers ended and during 5th semester , we started preparing for Robocon , we ordered 2 different USB programmer and both worked well and clearly were almost same as USBasp. Next in the 6th semester I became the TA for Embedded Robotics , so we again ordered 10-12 USB programmer for students. There was big time problem with the delivery of the programmer and this created lot of problem for conducting the course.
In the mean time Jayant one of the hopeful MS student for Robotics Research Lab came and I told him about USBasp and when he tried he made it work and that too even with ATmega8L , I was totally surprised but happy that now even I can make tha thing work somehow.

When the next summers of 09 started I set down with PS Abhimanyu determined to make USBasp work. We had with us the working USBasp programmers that we had purchased and the information that Jayant had got it working.
The first thing I did was to check all the connections of the 1 year old circuit and Lo!! I could not believe myself when I found 2 bugs in the wiring. What on earth did I do 1 year back that I could not find these error at that point of time !!! anyways I saw the circuit of the programmer that we had brought and i knowingly did not short the pin 25 to GND that was supposed to regulate the speed of programmer , thinking that if this working circuit did not have this connection why would I need one myself ?
So when the circuit was connected to the laptop the device was recognized but any attempt to burn a hex file would fail resulting in error "rc = -1 .......".
Next we tried everything that was mentioned in the ReadMe file and still this problem was not resolved. Now this was a big headache , here we were supposed to design and develop AVR development Kits and AVR Kits for Embedded System Lab course and we were not even able to get the programmer working.
So I we tried our best to solve the problem , we tried to see the voltages going on the MOSI, MISO,SCK pins on the oscilloscope and they also seemed to be fine except for MISO which was almost always zero. Next we tried to read the hex file from the working programmer and tried to flash our programmer controller with the same code but this reverse engineering also did not work , we did not had the intention nor the temperament to go through Fischl's code and see what he was doing .
Totally heart fallen I tried contacting Jayant but he was not available, so after one week I tried again one night to see if the circuit works, for checking I took one of Abhimanyu's ER boards with one of his ATMega8, and tried dumping the code once and Lo !! by heavens infinite kindness that code was dumped and verified :). Now I tried changing the code several times and it worked every time but only on Abhimanyu's board ,still I was totally overjoyed and I went to sleep thinking that I have very well earned a nice and content full sleep :).

So next morning we were again brainstorming why the thing worked on only one board , and now see what the luck we had, Abhimanyu told me that all his ATMega8 were clocked at 8MHz rather then the default setting of 1 MHz, it was there that out Tube light glowed for the first time !!! All this time I was assuming that the pin 25 need not be connected to ground since it was not done in the programmer that we had purchased.

So the final verdict was that , the guy who's USBasp we had purchased had modified the source code of Fischl'e and so he didn't needed the jumper at pin 25 , to program the controller that were clocked at 1 MHz. But in our case since we had pin 25 open so we were able to program only the microcontrollers that were clocked at higher then 1.5 MHz.

So it was eventually that USBasp , a well tested and very popular USB programmer was finally up and working after 1 full year from the first time the circuit was assembled on PCB.

Then when we tested the circuit with an ATMega8L instead of ATMega8, it also worked , so we can assume that AVR microcontroller can safely be overclocked without much problem !!!


  1. Hello shubham,
    I really like your blog.
    You have written in very interestingly.:P
    I am also interested in making USBasp programmer.
    Can you help me in debugging the problem.

    I have explained my problem on this website.
    It would be really helpful for me if you can help.

    Thanks in advance.
    my email id is.

  2. @dakudiv - the is no need to use a 2-diode voltage drop if you are using ATMega8 infact Atmega8 would not work at 3.6V according to datasheet.

    One debugging tip is that if uC is getting powered on then the Green LED should glow.

  3. Please look at the following schematic and layout.

    I am getting "unrecognized device" on PC.

    can you suggest some solution

    thanks, gaurav