EEPROM Save Data Arduino Programming Help

Click For Summary
The user is attempting to save integer data to a 24LC256 EEPROM using Arduino but is encountering issues where only about two hours of data is successfully written before it begins to overwrite. The writing process involves a loop that records data every minute, but the user suspects that the problem may lie in the reading or writing code. A key suggestion is to verify the order of the high and low bytes when transmitting the memory address, as this could affect data integrity. The user is open to sharing their reading code for further assistance. Clarifying these coding aspects is essential for successful data storage and retrieval.
trustnoone
Messages
17
Reaction score
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
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
 
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 75 ·
3
Replies
75
Views
6K