I2c eeprom ??

fdaniels

Well-known member
Is there any teensy-approved Library to easily write and read data to an 24lc512 eeprom?

Any help highly appreciated!
 
There are several libraries for I2C EEPROM on Github. I looked at them for reference purposes when employing a 24C512 to hold firmware for the GSL1680 touch controller. Not too difficult to do. Remember to allow 10mS or more for each write operation as indicated in the spec. Use dummy writes to set the address counter.

I'm away right now but can share the code when I return in a few days for reference purposes.
 
Code to do writes to EEPROM

Code:
//EEPROM_I2C_Write  Use to create EEPROM contents
//  writes are always in groups of 5-bytes * 25 repeats
//  last 3-bytes on page are left un-programmed
//  p6 is page pointer
//  P5 is address on page pointer
static void EEPROM_I2C_Write(uint8_t regAddr, uint8_t *val, uint16_t cnt)
{
  uint16_t i=0;

  Serial.print(regAddr, HEX);Serial.print("  ");        //  gsl1680 register address  (start)
  p2=(p6*128) + p5;                                     //  calculate byte address
  Serial.print("Page Address: "); Serial.println(p2);
  Wire.beginTransmission(eeprom);                       //  slave address
  Wire.write((p2 & 0x0000ff00) >> 8);                   //  byte address high
  Wire.write(p2 & 0x000000ff);                          //  byte address low
  Wire.write(regAddr);                                  //  page register (0xF0) or data register 4-bytes 0
  for(i=0;i<cnt;i++,val++)                                //  4-bytes of page/register data
  {   
          Wire.write( *val );  // value                 //  page or register data  4-bytes
          Serial.print( *val, HEX );Serial.print("  ");        //  gls1680 register data
  }
  uint8_t retVal = Wire.endTransmission(); 
  delay(10);                                            //  write delay time   10mS
  p5=p5+5;
  if (p5>=125)  {p5=0; p6=p6 + 1;}
  Serial.println(" ");
}


Code to read & transfer data to touch controller chip.


Code:
  //  ----------------------------------
  //  sends firmware to GSLx680 chip
void eepromXfer() {
  
//    Serial.println("EEPROM Transfer.");
    for (p6=0; p6 < 692; p6++)  {              //  read 692 * 125 = 86500 bytes     something less than 2048 + 128 = 262144 bytes
      p2 = (p6 * 128);
//      Serial.print("READ addr:  ");  Serial.println(p6, HEX);
      Wire.beginTransmission(eeprom);         //  slave address
      Wire.write((p2 & 0x0000ff00) >> 8);     //  address high byte
      Wire.write(p2 & 0x000000ff);            //  address low byte
      Wire.endTransmission();
      for (p5=0; p5<25; p5++)  {               //  read only 125 bytes of 128 bytes   (groups of 5)
        Wire.requestFrom(eeprom, 5);             //  read 5-bytes
        if (Wire.available() >= 1)  {         //  slave address       (no stop sent)
          p0=Wire.read(); //  Serial.print(p0, HEX);  Serial.print("   ");
          p3=Wire.read(); //  Serial.print(p3, HEX);  Serial.print("   ");
          p7=Wire.read(); //  Serial.print(p7, HEX);  Serial.print("   ");
          p8=Wire.read(); //  Serial.print(p8, HEX);  Serial.print("   ");
          p9=Wire.read(); //  Serial.print(p9, HEX);  Serial.print("   ");
          
        }
        //  Serial.println("   ");
          p4 = Wire.endTransmission();
        
        Wire.beginTransmission(addr);
        Wire.write(p0);
        Wire.write(p3);
        Wire.write(p7);
        Wire.write(p8);
        Wire.write(p9);
        Wire.endTransmission();
        
      }     //  end p5 for loop
      p5=0;
    }       //  end p6 loop
  
}   //  end eepromXfer
 
I2C eeprom use with GSL1680 touch controller

This is the file used to write the GSL1680 program into a local eeprom to eliminate 'all those lines of code'. Run once to program the eeprom contents then remove the 'Wx' jumper to load from eeprom and remove those extra lines of code in the 'real' program. It is set up to use either wire or wire1 bus. At 100KHz bus clock it takes about 27 (boring!) seconds to load and at 400KHz only 8.3 seconds. I have not tried this using any faster clock settings for the I2C bus.
 

Attachments

  • ER-TFTM050A2-3-Teensy3r5.ino
    115.3 KB · Views: 36
Back
Top