I have a program where my Arduino Duemilanove is counting pulse inputs. If the Arduino has to restart for one reason or another, I lose this counter value. I would like to store the counter value into flash memory, then when the Arduino starts up after losing power or something, it will read the counter value from flash memory and start counting from where it left off. I read the documentation on PROGMEM, but I can’t get it to work.
Below is some simple code I tried just to store and read a long integer in flash. But it returns 65535 instead of 80000. I also tried it with integer (not long), but that doesn’t work. What I really want is to read the value in the setup() section, and write the value in the loop() section.
I think you want to use EEPROM for this purpose, not FLASH. You can't really write to FLASH while your program is running, and FLASH is programmed in pages (big groups of bytes) rather than 1-2 bytes at a time.
I looked at the link you provided, but I can't figure out how to use eeprom_read_dword and eeprom_write_dword. I'm confusued about the parameters to pass. Do I need to use references instead of values? If so, how does that work? I'm a beginner with this stuff.