reading data from EEPROM

hello,

for my project I want to make use of an EEPROM in case of a power failure.
Writing to the EEPROM and checking that the data is there where i want it to be is not the problem,
only when i"m trying to use the data I'm getting confused.

the stored values are correct but I'm not able to get them back in my program.
I'm using an arduino nano for this project, the EEPROM is external and uses the I2c

tweede_opzet1.ino (27.7 KB)

It would have been helpful if you had explained that you were using an external EEPROM

Instead of the monster program with 1080 lines of code please write a program that simply writes to the EEPROM and reads back from it that illustrates the problem

Please, tell the type number of your external EEPROM.

OK,

thanks so far for the quick reply, my problem is that i can't get the stored data in address 1 to 11 ( that's all ),back into my program ( which by the way is not yet finished.

the data stored into the memory stands for a starting time and stopping time for a relays, so data stored in a dress 1 is the starting hour, address 2 is the starting minute ,address 3 is stopping hour and 4 is stopping minute.

so the problem is that the data in the eeprom is correct but when i'm trying to write them back into the programm in lines 1020 till 1039 they will not match.

the external eeprom i'm using is intergrated in a real time module ( rtc1307)

Please post an MCVE rather than a 1000 line program

lampje68:
thanks so far for the quick reply, my problem is that i can't get the stored data in address 1 to 11 ( that's all ),back into my program ( which by the way is not yet finished.

the external eeprom i'm using is intergrated in a real time module ( rtc1307)

The EEPROM of the RTC1307 Module is: ATMEGA 24C32 with device address 0b1010000 (0x50) and capacity 4 Kbyte.

1. Assume that your data are:
byte myData[] = {0x12, 0x24, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9A, 0xAB, 0xBC, 0xCD};

2. Assume that Target EEPROM locations are:
0x0001 to 0x000B (1 to 11)

3. The following sketch performs Read-after-Write verification of data in the EEPROM. The read out data are in the array recData[]. Now, you can use them in your program as needed.

#include<Wire.h>
byte myData[] = {0x12, 0x24, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9A, 0xAB, 0xBC, 0xCD};
int eepromAddress = 0x0001;
byte recData[11];

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  
  Wire.beginTransmission(0x50);
  Wire.write(highByte(eepromAddress));  //pointing beginning address of EEPROM
  Wire.write(lowByte(eepromAddress));
  Wire.write(myData, sizeof(myData));
  byte busStatus = Wire.endTransmission();
  if(busStatus !=0)
  { 
    Serial.print("EEPROM not found...!");
    while(1);
  }
  delay(5);       //write cycle delay
  //-------------------------------------------
  Wire.beginTransmission(0x50);
  Wire.write(highByte(eepromAddress));  //pointing beginning address of EEPROM
  Wire.write(lowByte(eepromAddress));
  Wire.endTransmission();
  //--------------------------------------------

  byte n = Wire.requestFrom(0x50, 11);   //reading 11 bytes data
  for (int i = 0; i < n; i++)
  {
    recData[i] = Wire.read();
    Serial.print(recData[i], HEX);
    Serial.print(' ');
  }
}

void loop()
{

}

smeeprom.png

smeeprom.png

hello,

I've shorten my EEPROM reading problem, so my problem is this: reading the data from address 1 from the
EEPROM is correct in this case it's 7.

trying to give this number to "Sau" results in "23 " , "Lam " shoot be "10 " and not "12 " ( address 8 of the EEPROM)

what's the fault in my program ?

probleem_eeprom.ino (5.18 KB)

UKHeliBob:
It would have been helpful if you had explained that you were using an external EEPROM

Instead of the monster program with 1080 lines of code please write a program that simply writes to the EEPROM and reads back from it that illustrates the problem

If you follow UKHeliBob advice problem solving would be much easier.