Search code examples
memoryavrmemory-addressflash-memory

AVR flash memory reading and writing


I don't understand one fundamental thing about flash memory access in AVR. As datasheet says flash page consists from 64 words for atmega16 and there are 128 pages. Since it has 16kbytes of flash memory it easy to get that word size is 2 bytes and page size is 128 bytes.

Well.. In Spi programming mode there are load and write instructions. First of all, what is the difference between them?

And the second question is about load memory page instructions. There are two instructions: one for low byte and one for high. We have to send four bytes: command identification byte(if I can call it so), MSB of the address, LSB of the address and data byte. Question exactly is what do that instructions do? What are high and low bytes here although we load page which consists from 128 bytes?


Solution

  • Well.. In Spi programming mode there are load and write instructions. First of all, what is the difference between them?

    You are probably not aware of the "Page Buffer". To write new data to a page, the Page Buffer must be filled first. It is holding one temporary page and must be filled word by word. -> Load instruction

    The buffer is copied to Flash memory in one operation. -> Write instruction

    And the second question is about load memory page instructions. There are two instructions: one for low byte and one for high. We have to send four bytes: command identification byte(if I can call it so), MSB of the address, LSB of the address and data byte. Question exactly is what do that instructions do? What are high and low bytes here although we load page which consists from 128 bytes?

    It refers to the low and high byte of each word that is loaded into the page buffer.