Ceska verze

Atmel AVR for beginners 3 - how to write the AVR

    Introduction:
This article describes in detail for beginners how to write a program into the AVR microcontroller. It does not deal with writing program, but only programming (writing) of the final file to the AVR. It is also suitable for those who do not want to write a program themselves, but only put the file (downloaded from somewhere) into their AVR.
    Procedure - hardware:
To program the AVR you need some hardware and some software :). Hardware or a programmer is a device that allows the communication between PC and AVR. The simplest way for ISP programming hardware is only the LPT connector (male), cable, 4 resistors and power supply about 5V. All the hardware you can easily build yourself for example in a breadboard. Examples of most frequent AVR's programming schematics are shown in the diagrams below. If the target device will use crystal, connect it (and also the C1 and C2) during programming. You can also use the universal value of crystal, 4MHz. Connection of other AVR is similar. Always in search datasheet for pins: MISO, MOSI, SCK and RESET (and for XTAL2 and XTAL1 when crystal is used). Connect your programmer to the LPT port of your PC.
    Procedure - Software:
You will also need some software. Download and install PonyProg (I used version v2.07c BETA). This allows you to write programs into AVR and setting the configuration bits. After the first startup of PonyProg, you must correctly set the communications port. Select Parallel, Avr ISP I/O, LPT1. Before writing the program into AVR, you must select the type of the microcontroller (AVR micro and ATtiny... orA Tmega...). There is also an option "AVR Auto", but I do not recommend it - configuration bits setting does not work then. Open the file you want to write to AVR. The AVR needs the compiled file with .HEX extension. The tutorials on the Internet (including mine) usually offer the file for download. Make sure the programming circuit with AVR is connected to the LPT and the power is on. Then click on the "Write Device" button and confirm. Your program will be written into the AVR. You should see the "Write successful". Then you have to set up and write the configuration bits (writion only the program is not enough!). Open the settings window (Security and Configuration Bits), set the appropriate bits . Bits have to be set as the appropriate design requires. I usually publish the printscreen of the window. Carefully check the setting before writing. Beginners are strongly discouraged to play with setting of these bits - AVR could get blocked (stop communicating). Warning - writing the bits is done by clicking on Write button, not the OK button! The whole procedure is illustrated on the images below.
    Conclusion:
After programming and setting the bits, AVR microcontroller can be connected to the target circuit and tested. If an error messages appears while you are trying to write the program or configuration bits, you probably defined the improper port for PonyProg, improper type of AVR, did not connect the LPT connector, PonyProg does not have access to the port, programming circuit is wired wrong, there is no power, no crystal or capacitors (where the crystal should be present), your AVR is faulty or you've allready blocked it by wrong bits setting :).


Schematic of LPT Atmel AVR Tiny programmer: ATtiny13, ATtiny25, ATtiny45, ATtiny85 and others in DIP8 housing. (Note.: ATtiny13 does not support the crystal).


Schematic of LPT Atmel AVR Mega programmer: ATmega8, ATmega48, ATmega88, ATmega168 and some other in DIP28.


Schematic of LPT Atmel AVR ATtiny2313 programmer.


Schematic of LPT Atmel AVR Mega programmer: ATmega16, ATmega32, ATmega8535, ... (not for ATmega8515 !)


Port setting of PonyProg. Select Parallel, Avr ISP I/O, LPT1.


AVR type selection.


Opening the HEX file to be written into AVR.


The "Write" button.


Configuration bits setting. Important note - use Write button, not OK button!!!



Added: 2. 7. 2012
home