EEPROM Save Data Arduino Programming Help

In summary, the user is having trouble writing and reading data onto their 24LC256 EEPROM. They are writing an integer value once per minute, but when they read from the EEPROM, they only obtain about 2 hours of data. The problem may be in the code for writing to the EEPROM, specifically in the order in which the memory address is transmitted. It is suggested to double check the order of transmission for the address.
  • #1
trustnoone
17
0
hi guys, so I'm trying to save data onto my EEPROM, the problem is it works for a while of data, but not all of it. I'm not sure if its a problem with reading though, or the writing part. Essentially I'm writing an integer value into the EEPROM to obtain later, although I expect to have quite a few pieces of data in there.
I'm using the 24LC256 EEPROM

Currently my writing to EEPROM is as follows:
<Altered as its quite long>

Code:
int address = 0;
#define disk1 0x50    //Address of 24LC256 eeprom chip
..
..

loop{
//obtain time value here

    eepromWriteInt(disk1, address, timeTemp.toInt());  //timetemp is just an integer time value
    address+=2;
    delay(60000);
}

void eepromWriteInt(int theDeviceAddress, unsigned int theMemoryAddress, int theInt) 
{
  byte theByteArray[sizeof(int)] = {
    (byte)(theInt >> 8), (byte)(theInt >> 0)};
  eepromWrite(theDeviceAddress, theMemoryAddress, sizeof(int), theByteArray);
  eepromAddress=eepromAddress+2;
}
void eepromWrite(int theDeviceAddress, unsigned int theMemoryAddress, int theByteCount, byte* theByteArray) 
{
  for (int theByteIndex = 0; theByteIndex < theByteCount; theByteIndex++) 
  {
    Wire.beginTransmission(theDeviceAddress);
    Wire.write((byte)((theMemoryAddress + theByteIndex) >> 8));
    Wire.write((byte)((theMemoryAddress + theByteIndex) >> 0));
    Wire.write(theByteArray[theByteIndex]);
    Wire.endTransmission();
    delay(4);
  }
}


I think a big problem I am having is I don't quite understand it too well either, so its pretty much just a combination of a few examples I've found online.

It should write to the EEPROM once per minute (although its a little longer due to the 4ms delay), over like 8 hours, preferably more, but just testing 8 hours for now. The problem is when I read from my EEPROM I only obtain about 2 hours, and then it just go's back over everything again.

If you feel it might be better for me to post my read code I will be happy to do that as well.

Thanks heaps for any help.
 
Engineering news on Phys.org
  • #2
Code:
void eepromWrite(int theDeviceAddress, unsigned int theMemoryAddress, int theByteCount, byte* theByteArray) 
{
  for (int theByteIndex = 0; theByteIndex < theByteCount; theByteIndex++) 
  {
    Wire.beginTransmission(theDeviceAddress);
    Wire.write((byte)((theMemoryAddress + theByteIndex) >> 8));
    Wire.write((byte)((theMemoryAddress + theByteIndex) >> 0));
    Wire.write(theByteArray[theByteIndex]);
    Wire.endTransmission();
    delay(4);
  }
}

My guess is your problem is in this section of code. When you say you're getting a little over 2 hours of data. 2*60*2 (2 bytes/per int based on your code)= 240. 1 byte of memory will address 256. If I were to hazard a guess, you xmit the high byte of the memory address first then the lower byte. It's possible that these need to be in the opposite order. Double check exactly the order you need to transmit the address
 

Related to EEPROM Save Data Arduino Programming Help

1. What is EEPROM in Arduino programming?

EEPROM (Electrically Erasable Programmable Read-Only Memory) is a type of non-volatile memory that can store data even when the power is turned off. In Arduino, it is used to save data that needs to be retained between power cycles, such as sensor readings or user settings.

2. How do I save data to EEPROM in Arduino?

To save data to EEPROM in Arduino, you need to use the EEPROM.write() or EEPROM.put() function. The write() function takes two parameters - the address where you want to save the data and the data to be saved. The put() function is used to save larger data types such as strings or arrays.

3. How do I read data from EEPROM in Arduino?

You can read data from EEPROM using the EEPROM.read() or EEPROM.get() function. The read() function takes the address as a parameter and returns the data stored at that address. The get() function is used to read larger data types.

4. Can I overwrite data in EEPROM?

Yes, you can overwrite data in EEPROM. To do so, you can use the write() or put() function at the specific address where you want to overwrite the data. Keep in mind that EEPROM has a limited number of write cycles, so it is important to use it sparingly.

5. How do I clear the EEPROM in Arduino?

To clear the EEPROM in Arduino, you can use the EEPROM.clear() function. This function takes the size of the EEPROM as a parameter and clears all the data stored in it. Be careful when using this function as it will erase all the data in the EEPROM.

Similar threads

Replies
1
Views
3K
Replies
4
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
7
Views
4K
Back
Top