EEPROM Write Anything Question: MOVED

Hello,

I am looking to store a variety of information from a structure into the eeprom while my arduino runs and then retrieve it afterwards. I am using a 32KB I2C EEPROM: I2C EEPROM - 256k Bit (24LC256) - COM-00525 - SparkFun Electronics. I am using the EEPROM_WriteAnything library found here: http://playground.arduino.cc/Code/EEPROMWriteAnything.

I wrote a test script to try and store 4 longs at a time and then retrieve them later. The issue i am having is that if the code loops through 64 or fewer times, then everything is okay. However, if the code loops through more than that, say 100 times, then some of the values are overwritten. I do not understand why this is happening because each structure I write into the EEPROM is only 16 bytes meaning that I should be able to write 2000 times before the EEPROM is full.

I will attach my code here. Can someone please advise me on this?

#include <EEPROM.h>
#include "EEPROMAnything.h"

struct config_t
{
    unsigned long a;
    unsigned long b;
    unsigned long c;
    unsigned long d;
} configuration;

void setup()
{
  Serial.begin(9600);
}
void loop()
{
    int i = 0;
    int j = 0;
    int counter;
    while (i < 100)
    {  
      configuration.a = i*10;
      configuration.b = i*100;
      configuration.c = i*1000;
      configuration.d = i * 10000;
      counter = EEPROM_writeAnything(j, configuration);
      Serial.println(counter);
      i++;
      j = j + 16;
    }

    int k = 0;
    while (k < j)
    {
      
      EEPROM_readAnything(k, configuration);    
      Serial.print("a = ");Serial.println(configuration.a);
      Serial.print("b = ");Serial.println(configuration.b);
      Serial.print("c = ");Serial.println(configuration.c);
      Serial.print("d = ");Serial.println(configuration.d);
      Serial.print("\n");
      k = k + 16;
    }
}

The header file that is attached needs to be in a tab with the actual code.

testing_stuffs.ino (906 Bytes)

EEPROMAnything.h (520 Bytes)

The ATmega328 chip has only 1K of EEPROM, and 16 x 64 = 1K

Perhaps you are confusing flash memory with EEPROM - they are separate memories. EEPROM can
be written byte-by-byte, Flash is only programmable in entire blocks.

That would make sense but I am using a 32 KB I2C EEPROM: I2C EEPROM - 256k Bit (24LC256) - COM-00525 - SparkFun Electronics. Do I have to do something special in order to write to that rather than the built in arduino eeprom?

Uh, send I2C commands?

KeithRB:
Uh, send I2C commands?

can you please explain that? I have programming experience but am relatively new to arduinos. Does this mean that the EEPROM_writeAnything template will only write to the arduino's built in eeprom and cannot be used to write to an external eeprom location like the chip that I am using? If so, how would you recommend I write to the chip if I need to store about 9 values at a time (most integers but some longs). I know that you can store integers with writing a high/low byte and I imagine a similar approach can be used to store longs but that seems rather cumbersome and more importantly time consuming. It would be nice to store an entire structure with one write to the eeprom rather than 16 individual writes to write 16 bytes.

Thanks!

I don't know anything about writeAnything library, but if you don't tell it the I2C address of the EEPROM, how can it use it? You need to read the data sheet for the EEPROM and use the Arduino I2C ("TwoWire") library to send the correct commands.

Your library is just using internal eeprom of the atmega!
If you are using an I2C eeprom you must refer his address on the BUS and the send it the write command!
Be aware eeprom is write limited.
If you are running that in a loop you can get the maximum write limit very fast and destroy the eeprom.

Thanks for the feedback guys! I have added the I2C communication into my code and am still experiencing the same problem so I am not sure if there is a coding error in my communication to my I2C device.

#include <EEPROM.h>
#include "EEPROMAnything.h"
#include <Wire.h>
#define ADDRESS 0x50

struct config_t
{
    unsigned long a;
    unsigned long b;
} configuration;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
}
void loop()
{
    int i = 0;
    int j = 0;
    int counter;
    while (i < 129)
    {  
      configuration.a = i*10;
      configuration.b = i*100;
      Wire.beginTransmission(ADDRESS);
      EEPROM_writeAnything(j, configuration);
      Wire.endTransmission();    
      i++;
      j = j + 8;
    }

    int k = 0;
    while (k < j)
    {
      Wire.beginTransmission(ADDRESS);  
      EEPROM_readAnything(k, configuration);    
      Serial.print("a = ");Serial.println(configuration.a);
      Serial.print("b = ");Serial.println(configuration.b);
      Wire.endTransmission();
      Serial.print("\n");
    
      k = k + 8;
    }
    while(1)
    {
    }
}

Removed.

Sorry, didn't see that you started a new thread in which you moved to I2C
http://forum.arduino.cc/index.php?topic=175517.0