Programming AVR Chips

It better to know how to program the AVR controllers before start developing applications. I was first introduced to Atmega8
in workshop when I was in college. In that workshop I got a Atmega8 based development board. After some days when I was working
with it accidentally I damaged the controller. So instead of buying new development board i bought new Atmega8 controller. but
it is not working when i inserted the controller into the board. After doing lot of googling i found the old controller is
using some thing called boot loader(more later) which the new controller does not have.

All AVR controllers have tiny amount of flash memory to store code. for example atmega8 have 8KB of flash memory.
when ever you give power to the microcontroller it will start executing the code present in the flash memory.

There are several ways available to load your hex file to the AVR. Now I will discuss about two ways here

1.Using ISP (In System Programming)
2.Using Boot loader

Using ISP:

Every AVR has a set of pins that are the programming pins, you just have to connect the programmer to those pins in the right order and presto you are ready to program it. Unfortunately, nearly every chip has a different pinout so its imperative that you look in the datasheet for the correct pins. For example Atmega8 ISP uses MOSI, MISO, SCK, GND, VCC, RESET pins.


So now we need to conect these pins to the computer some how.

We can interface the ISP with the computer in three different ways

1.Parllel interface

2.Serial interface

3.USB interface (USBASP)

Parlle interface and serial interfaces are no longer available on laptaps..These are legacy interfaces now

We are left with USB interface..Since our controller ISP can not talk directly with USB we need some kind of bridge between them. USBASP is small peace of hardware that works as a bridge between computer usb port and AVR ISP port.

Using Boot loader:

In recent years, microcontroller designers have added the capability for the chip to program its own flash (often called self-programming). What this means is that a program burned on a microcontroller can actually change its own program. In most cases this is not a good idea, a program can overwrite itself, damage itself, and/or cause the microcontroller to freak out. However, in certain cases this can be a benefit.

Take, for example, a small program that is burned into the chip that can communicate with a computer through a USB or serial cable and allow the computer to download new firmware without the use of a programmer.When you ‘update the firmware’ on your cell phone, this is whats happening.

For example, Arduino use a bootloader that is programmed into the chip at the Arduino factory. The bootloader is protected so that it can’t overwrite itself. To upload code to the Arduino, you use the Arduino software which is smart enough to recognize when an Arduino is connected.

Bootloaders are great, but you need a ISP programmer to put the bootloader on the chip the first time if you’re buying a new chip. Its a bit of a chicken-and-egg problem. If you have two arduino borads you can use one board as USBASP programmer to burn the bootloader in new controller which is placed in other board.

Bootloaders also don’t let you modify the fuses (more later) and they take up a portion of the flash memory so uploaded programmers must be smaller.

In general bootloaders are great for starting out with but I find its important to have some way to program the chip so that you can put the bootloader on and maybe modify the bootloader or fuses.

I won’t be using bootloaders in my examples unless the examle is for arduino, but will assume you have an ISP programmer as they are more universal. Later on, you can always add your own bootloader.

 

 

Add a Comment

Your email address will not be published. Required fields are marked *