Pages: [1]   Go Down
Author Topic: eeprom does not store the data after restart....  (Read 1380 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ,,,, I am very new to this and I need some help!

As I read the atmega's eeprom can store values as a rom....It would not erase the values after restart...
I use this code to write two values on addresses 1 & 2:
regs[MB_D9]= EEPROM.read(1);      /*error delay*/
     if (regs[MB_CTRL3] != EEPROM.read(1) ){
     EEPROM.write(1, regs[MB_CTRL3]); //delay error
   }
regs[MB_D10]= EEPROM.read(2);      /*error delay*/
     if (regs[MB_CTRL4] != EEPROM.read(2) ){
     EEPROM.write(2, regs[MB_CTRL4]); //delay error
   }

But every time I restart the board(power off or reset) the value of EEPROM.read(i) change to 0,,,
This is normal?????
If it was rom it should not happen.

any suggestions?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
any suggestions?
Yes, post your code.
(What is wrong with your '?' key - is it sticky?)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry about my ? key my friend.
This is my code for write and read eeprom memory:

regs[MB_D9]= EEPROM.read(1);      /*error delay*/
     if (regs[MB_CTRL3] != EEPROM.read(1) ){
     EEPROM.write(1, regs[MB_CTRL3]); //delay error
   }
regs[MB_D10]= EEPROM.read(2);      /*error delay*/
     if (regs[MB_CTRL4] != EEPROM.read(2) ){
     EEPROM.write(2, regs[MB_CTRL4]); //delay error
   }



I use the eeprom.h library and all the "regs[]" is int.
When I have my arduino powered it is working fine (I can set the values in memory but when I restart this, the eeprom.read(1 or 2) gives me 0 again.)
I use the EEPROM.read to use this values in my sketch, so I understand that the EEPROM.write is working.


(I am very sorry for my english).
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I use the eeprom.h library and all the "regs[]" is int.
And EEPROM.read() and EEPROM.write() work with bytes.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

works with bytes means that works with an int 0 to 255,
is this wrong?
My sketch is working just fine the write in eeprom memory is success ,(I use eeprom.read() and it gives me the value)  but it can not store the values after restart. is it normal?
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

works with bytes means that works with an int 0 to 255,
is this wrong?

Yes.  A byte is an 8-bt unsigned integer, not a 16-bit signed integer.  You will have issues.  Use uint8_t or byte when working with EEPROM, and convert them back later.
Logged

0
Offline Offline
Sr. Member
****
Karma: 2
Posts: 303
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao,

I think there is an error in EEPROM.write reference in Arduino site:

the example is wrong (uhmm at least at me seems wrong)

Code:
#include <EEPROM.h>

void setup()
{
  for (int i = 0; i < 512; i++)
    EEPROM.write(i, i);
}

max value for a EEPROM memry location is 255 (maximum 8 bit value).

If You want to write structured data easily You can follow this example:
http://www.arduino.cc/playground/Code/EEPROMWriteAnything

Ciao,
Marco.
Logged

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

works with bytes means that works with an int 0 to 255,
is this wrong?
My sketch is working just fine the write in eeprom memory is success ,(I use eeprom.read() and it gives me the value)  but it can not store the values after restart. is it normal?

You need to post both your full eeprom read/write sketch and your full eeprom read only sketch that exhibits the problem, for us to figure this out for you. Lots of us have used the internal eeprom with no problems, so I'm sure it's solvable.

Lefty

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Was this problem solved? I am having the same problem.

Thanks.
Logged

Pages: [1]   Go Up
Jump to: