3 Jul 2012

Steps how a programmer writes the hex file into microcontroller

Do You know how microcontroller writes .hex file into microcontroller most of us don't know how it writes right . There is a pattern how it writes into microcontroller . It follows a sequence while writting .hex into microcontroller there are some SPM (store program memory) commands which should be send and then send address and then data .

Some microcontrollers write data in the form of word and some write in the form of bytes. you should see this while you are developing something new like bootloader or something els.

If mc is word addressable first it loads the lower byte with data and then higher byte with next data of same address as it is word addressable. (remember).

Generally avr-gcc writes the code in byte form so what ever the address we need to change in the microcontroller you need to double the address and give it to gcc .

Suppose you want to write the code from 0xC00 in the flash which is word addressable how you should give this in avr-gcc is
                                                    0xC00 * 2 = 0x1800
in the chang section if you need to change the address location where to write.else if microcontroller is byte addressable you can write it directly 0xC00. There is no need to manipulate the addresses .

Ok leave this is brief i will explain you in the later sessions.

Now lets know what a Programmer does in the Microcontroller if it wants to write .hex file into the flash .

Steps it follows :

1. program enable mode (0)

2. check signature bits

3. read low fuse bits

4. read high fuse bits

5. read last 4bytes of the eeprom because it stores number of times the chip erase has been done .

6. program enable mode again (1)
   (address is word address here so )

7. load the data into the flash first low add (40) 1st data and then to high of the same address (48) 2nd data into the flash.

8. load until whole page is loaded and then send the command Write PAGE the flash page loading last addersss

9. now read the page with last address

10. now reads each word in flash from starting address

11. and again reads the fuse bits and lock bits

This was the mechanism followed by the USBASP programmer of any other programmer to write program into the flash .

In order to understand clearly what this means see this Post
which tells you how it is writting.

1 comment:

  1. thanks for share this...i like
    i want to learn bootloader program

    see my blog
    http://mekatronika-corner.blogspot.com/

    ReplyDelete