Go Down

Topic: Write external EEprom is takes 1-2 seconds (Read 1 time) previous topic - next topic


I have some code that writes to an external EEProm. It take much longer that writing to the internal EEProm. The delay is annoying. The data is typically less than 100 characters but always less than 150.

Can anyone help me with a more efficient way, or is this as good as it gets?

I've thought about buffering the data through internal EEProm and when the program finishes a cycle move it to the external and Clear the internal.

Code: [Select]
  #include <Wire.h> //I2C library

  void write2ExtEeprom(int address, char* myDataStr)
    Wire.send((int)(address >> 8)); // MSB
    Wire.send((int)(address & 0xFF));
     for(int i=0; i< strlen(myDataStr); i++)
}  // sends one byte     
  Wire.endTransmission();    // stop transmitting

void EwrCur(int Curaddr)
{ // Write Current Address to Memory-
  int CurMsbLsb = Curaddr;     // -Locations 0 and 1
  byte CurMsb = (CurMsbLsb>>8); // Break (int)Curaddr into two bytes
  byte CurLsb = (CurMsbLsb&0xFF);
  Ewr0(0,CurMsb);   // Write Curaddr Msb to Memory Location 0
} // Write Curaddr Lsb to Memory Location 1

void Ewr0(unsigned int Eaddr, byte data) // Write only to Loc 0
  { byte rdata = data;
    Wire.send((int)(Eaddr >> 8)); // MSB
    Wire.send((int)(Eaddr & 0xFF)); // LSB
    //Serial.print("rdata = ");
    //Serial.print(rdata, HEX);
int ErdCur()
{ // Read Ext Eeprom Memory Locations 0 and 1 CurrAddress
   byte CMsb = Erd0(0);
   //Serial.print("CMsb = ");
    //Serial.print(CMsb, HEX);
   byte CLsb = Erd0(1);
   //Serial.print("CLsb = ");
   // Serial.print(CLsb, HEX);
   // Serial.println();
   int CMsbLsb = ((CMsb<<8) + (CLsb&0xFF));
   //Serial.print("CMsbLsb = ");
   // Serial.print(CMsbLsb, HEX);
   // Serial.println();
   int Caddr = CMsbLsb;   
   //Serial.print("Caddr = ");
    //Serial.print(Caddr, HEX);
    return Caddr;
  byte Erd0(unsigned int eaddr )
    byte rdata = 0xFF;
    Wire.send((int)(eaddr >> 8)); // MSB
    Wire.send((int)(eaddr & 0xFF)); // LSB
    if (Wire.available())
    rdata = Wire.receive();
    return rdata;

void storeExtEeprom(char* dataStr1)
  int addr;
  addr = ErdCur();
  write2ExtEeprom(addr, dataStr1);
  addr+= strlen(dataStr1);
//   void setup() {
//    Wire.begin(); // initialise the connection
//    Serial.begin(9600);
//    EwrCur(0x00);
//  void loop() {
//  String dataStr = "Offender of The Universe.";
//  ExtEeprom(dataStr);
//  delay(2000);


well a 20 msec delay repeated 100 times = ??
there are only 10 types of people
them that understands binary
and them that doesn't


The Wire.send() method has an overload that can write the whole array at once, without the need for the for loop (or the delay).
The art of getting good answers lies in asking good questions.


check - http://arduino.cc/playground/Main/LibraryForI2CEEPROM -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)



Doh! I didn't think of that, but it works like a charm. I looked for large delays, but didn't thhink of the *100.

OK. I was to be able to get the data out the same way I put it in, so I am thinking of storing the size of the data inline like so:


I think that is a fairly common way of doing it. Can someone help point me towards an example to write and then read that way. 

Go Up