(A Continuation from (
Really) Beginners Microcontroller Guide (Part-I) Compiling the first program)
(alpha version. Very unstable, still editing)
Writing program to Microcontroller
We will be using ponyprog from lancos. Although it is possible to program directly from winavr, I like the interface of the program very much.
Construct the simplified SI Prog. You'll need:
1. A serial port DB9 Female Connector,
2. 5V1 Zener Diodes x3
3. Resistors: 15K, 10k, 4k7 x 3
4. Bread board wires
Connect the circuit on veroboard. To see how it looks go to my blog
http://sajiduc.blogspot.com/2008/04/beginners-microcontroller-programming.html
To connect the programmer always consult the datasheet of the microcontroller. Connect the Mosi, MISO, SCK, Reset lines of the programmer to the corresponding pins of microcontroller, and connect GND to 0V. Connect the serial connector to the serial port of your mother board. Please do not use a usb-serial converter, and connect only to true serial port.
Goto
http://www.lancos.com/prog.html and download ponyprog from there. Install ponyprog, and open ponyprog from startmenu.
After the annoying neigh sound, click ok. Pony prog will say
Click ok again
Now do the bus timing calibration:
Afterwards, it is important. Click Setup>Interface Setup. Select Serial radio button. From drop down select SI Prog API / SI Prog IO. Select the COM port in which the programmer is connected. It is COM1 if you have only one serial port, but for multiple ports, you have to select the appropriate one.
Please note that 90% cases, the SIProg does not work because of not proper configuration in this dialog. So if the SI Prog does not work, try to change the COM port, or switch between SI Prog API and IO
Select the appropriate device name
Now to test if the programmer is working, Click Command>Read All. From my experience 70% cases, people don't get a smooth read operation at the first try. See below for common problems
If every thing is ok, (Which actually did in my first experimental SIProg) Then reading will start.
Now click File>Open, and open the testprog.hex file generated by the compiler.
Now select write all
And then the write will be successful!
Then play with your microcontroller circuit:
Ofcource the write may not be successful.
This might be due to
1. Circuit connection error (Check if you have connected power to micr
ocontroller, check if the breadboard connections are loose, if the programmer are connected to the proper pins, if the programmer is soldered properly.)
2. Check if the BC547 transistor is working by testing if 0.7 V drop occus between Emitter and Base.
3. Check if your serial port is working and you are not using a USB-serial converter
4. Play around with the interface setup (in ponyprog) to find another suitable setting for you. (Try SIprog API, SIProg IO, Check if you have selected correct serial port)
5. This is very common for me:- the microcontroller is dead!!!!
Well, no 5 can result from 2 cases, a) a heart attack of the microcontroller (Fry out, like connecting Vcc of microcontroller to ground and ground to Vcc, microcontroller, at 90% cases just fry) b) Accidental programming of the fusebits of the microcontroller can result the SPI interface to be locked out. This can be overcome by a universal programmer. If you happen to have access to one, ask some one clear the lock bits.
6. You forgot to select the right device (I also sometimes forget to do that)