Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

EEPROM Save Data Arduino Programming Help

  1. Jul 14, 2014 #1
    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 (Text):

    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.
     
  2. jcsd
  3. Jul 14, 2014 #2
    Code (Text):

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: EEPROM Save Data Arduino Programming Help
Loading...