EEPROM Save Data Arduino Programming Help

Click For Summary
SUMMARY

The discussion focuses on issues related to saving data to the 24LC256 EEPROM using Arduino. The user reports that while writing integer values to EEPROM, they only retrieve about two hours' worth of data instead of the expected eight hours. The problem is identified as potentially stemming from the order of byte transmission in the eepromWrite function, specifically regarding how the memory address is transmitted. The suggested solution is to verify the order of the high and low bytes in the memory address transmission.

PREREQUISITES
  • Understanding of Arduino programming
  • Familiarity with I2C communication protocol
  • Knowledge of EEPROM memory structure and limitations
  • Experience with data types in C++ (specifically integers)
NEXT STEPS
  • Review the I2C communication protocol for Arduino
  • Learn about EEPROM memory addressing and data storage
  • Investigate the correct byte order for data transmission in EEPROM
  • Explore debugging techniques for Arduino code to identify data writing issues
USEFUL FOR

Arduino developers, hobbyists working with EEPROM, and anyone troubleshooting data storage issues in embedded systems.

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
 

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
7K