0
Offline
Faraday Member
Karma: 6
Posts: 2504
|
 |
« Reply #1 on: March 30, 2007, 11:07:00 am » |
The ATmega8 (and 168, and probably others of the family) has three different types of memory: flash, EEPROM, and RAM. Flash is where your program lives; it's 8kb on the ATmega8. EEPROM is where your program can store stuff between power cycles (e.g. configuration information that can be changed). The ATmega8 has 512 bytes of EEPROM. RAM is, well, RAM, where your typical variables are stored; there's 1k of this on the ATmega8.
I point this out because some folks don't differentiate between flash and EEPROM and use the terms interchangeably (because they're similar physically) but the ATmega has both and uses them for two completely different things.
The ATmega8 flash can be written ~10,000 times. EEPROM can be written ~100,000 times. both are non-volatile - they will retain their values when power is lost. You can write to RAM as many times as you want, but the contents are gone if power is lost. All three types of memory can be read an infinite number of times.
The AVR is a Harvard architecture - this means program memory and data memory are separate, with separate address spaces. The ATmega8 actually has 3 address spaces - one for flash, one for EEPROM, and one for RAM. This is different from your "typical" microprocessor, like a Pentium, where there is only one address space and it is shared between data and program (this is called a von Neuman architecture). You'll find this Harvard architecture frequently in microcontrollers, as it simplifies some aspects of the design, allowing the CPU to be simpler (therefore faster and cheaper).
So, you have flash memory addresses 0 - 8191, EEPROM memory addresses 0 - 511, and RAM addresses 0 - 1023.
To begin to answer your question, flash and EEPROM can be written be an executing program (else the bootloader wouldn't work and we would all be using ICP programmers). This process is neither fast nor straightforward, since the data has to be transferred a byte at a time from a register (and probably from RAM to the register first), then out to flash (or EEPROM). flash and EEPROM are both slower to write than RAM.
To really answer your question, I would only attempt to use flash to store data that is configured at compile time and never changes (e.g. constant strings for prompts, messages and so forth), and be aware you'll have to manually copy the data out of flash before you can use it (e.g. send it to Serial.print()).
What you are asking can be done, but you need to have some understanding of the web page you referenced to read from flash; writing to it gets more complicated (I've never tried).
-j
|