I have reserved one flash page for saving an operating hours counter. There is an array of 32 entries in RAM of "unsinged long". This array is also filled with "0xFFFFFFFF". Every hour the index for the array is incremented by "1". After reaching the last entry, the index is set to "0" and the flash page will be erased. On the first run, the reserved flash page is cleared (every entry is 0xFFFFFFFF) and the array is also filled with 0xFFFFFFFF. After every hour, the complete array is copied into flash, without erasing. This shall work, because writing the same values or wriring the new last updated array entry value shall work. Sometimes this stategy fails and the stored data in flash is not the same as in the array. Why is it so? If I erase the flash page before write the new content of array, it works. But I don't want to erase the flash page every hour. My stategy is to ease it every 32 hours to save writing cycles.
Screenshot of memory content:
-sOPHours stored in RAM
-csOPHours stored in FLASH
The last new entry was 1077. During write RAM into FLASH, the entry of index 20 was set to an invalid value, Why?