Go Down

Topic: Flash vs EEPROM (Read 1 time) previous topic - next topic

Marvin Martian

Hi

I need to store one byte of program-state data in non-volatile memory. Are there any pros/cons on using flash vs eeprom?

From a code POV it looks like the EE is most straightforward.

Any issues with writing either in an ISR?

Cheers

retrolefty

Quote
Any issues with writing either in an ISR?


I could be mistaken but I thinks it's very hard, if even possible to write to flash program memory within a running sketch, so EEPROM is your friend.

Lefty

Coding Badly

Quote
Any issues with writing either in an ISR?

Writing to EEPROM takes about 3.5ms.  I suspect writing to Flash is also a relatively slow process.  Leaving interrupts disabled that long is very likely going to cause problems.

Marvin Martian

Quote
Leaving interrupts disabled that long is very likely going to cause problems.


Yeah I suddenly realised that just after I posted!

I'm thinking of something on the lines of

setup
{
 read eeprom - if it's outside permitted range, default to 0
 copy value to ram
}

ISR
{
 update ram value
}

loop
{
 if ram & eeprom differ, write ram back to eeprom
 do stuff with ram value...
}


Coding Badly

Should work well so long as the usual caveats regarding data shared between loop and an interrupt service routine are considered.

BenF

Quote
Writing to EEPROM takes about 3.5ms.

The way I read the datasheet is that the write itself is "immediate", but you will have to wait for the eeprom update to finish prior to writing the next byte.

The avrlibc implements this as an initial status/wait followed by write. For the first byte - wait will return immediately, but will block for successive bytes.

So a single byte EEPROM write may actually be Ok also from within an ISR.

Go Up