I wrote correctly because my EEPROM doesn't seem to read EEPROM correctly every time. Sometimes it fails to read the data that is written or it doesn't write at all. How should I use it? Delays?
I'm using built in .put .get functions and structs all the time. Size of the struct is about 512chars :o
Thanks in advance.
PS: I'm using a button that is attached as a interrupt, which calls a function to clear eeprom. This sometimes fails to clear eeprom too. Any suggestions?
PSS: I've already tried out few other microcontrollers (atmegas)
Don't try to write to the EEPROM (or erase) within an interrupt. The EEPROM uses interrupts to do its work, which would be disabled if called from within an interrupt context.
For a button being pressed by a human, there is never a reason to use an interrupt. Use digitalRead() like everyone else.
I'm doing tons of web access work in loop(), therefore it requires a human to press that eeprom reset button for like 10 seconds, which lacks user experience at some point. Do you recommend anything else to reset eeprom?
edencakir:
I wrote correctly because my EEPROM doesn't seem to read EEPROM correctly every time. Sometimes it fails to read the data that is written or it doesn't write at all. How should I use it? Delays?
I'm using a button that is attached as a interrupt, which calls a function to clear eeprom.
Bad idea!
Interrupt handling routines should be FAST! I.e. less than one microsecond or just a few microseconds.
But writing to EEPROM ist slow, I think with Atmega controllers the duration is something like 5 milliseconds per byte with an Arduino UNO (Atmega328).
That's 1000 times as long as an interrupt handling should last at most.
edencakir:
I wrote correctly because my EEPROM doesn't seem to read EEPROM correctly every time. Sometimes it fails to read the data that is written or it doesn't write at all. How should I use it? Delays?
I'm using a button that is attached as a interrupt, which calls a function to clear eeprom.
Bad idea!
Interrupt handling routines should be FAST! I.e. less than one microsecond or just a few microseconds.
But writing to EEPROM ist slow, I think with Atmega controllers the duration is something like 5 milliseconds per byte with an Arduino UNO (Atmega328).
That's 1000 times as long as an interrupt handling should last at most.
Why aren't they just include this kind of information on their eeprom website? or its just me missing the details.
sterretje:
Because everybody (?) knows that writing EEPROM is slow Nah seriously, EEPROMWrite actually gives the number. And the 328 datasheet as well.
Several things ... isn't that complicated, but it has many examples rolled into one sketch. Here is a super-simplified demonstration of non-blocking timing that just does two things - reads a switch and counts up numbers on the serial monitor. You will need to wire a normally open switch to pin 8 (or the pin of your choice.) Momentarily close the switch, and the count resets. The switch is continuously monitored, the count code executes once a second. No delays are used - you can make this as complicated as you like.
// Simplest counter, output to serial
unsigned long previousSecondMillis;
const long oneSecond = 1000UL;
int counter = 0;
void setup()
{
pinMode(8, INPUT_PULLUP); // pin -- button -- gnd
Serial.begin(9600);
previousSecondMillis = millis();
}
void loop() {
// this section executes every time through the loop
if (!digitalRead(8)) counter = 0;
// this section gets executed every oneSecond millis
if (millis() - previousSecondMillis >= oneSecond) {
previousSecondMillis += oneSecond; // do this once a second
Serial.println(counter++);
}
}