Pages: [1]   Go Down
Author Topic: Flash vs EEPROM  (Read 1343 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 106
Where's the Kaboom?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 198
Posts: 12750
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 106
Where's the Kaboom?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
}

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 198
Posts: 12750
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: