Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: I2c eeprom ??

  1. #1
    Senior Member fdaniels's Avatar
    Join Date
    Oct 2020
    Location
    Ostwestfalen, Germany
    Posts
    101

    I2c eeprom ??

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

    Any help highly appreciated!

  2. #2
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,769
    Don't think there is an approved library for I2C eeproms - never really played with them. You could try https://github.com/PaoloP74/extEEPROM library for arduino. Probably should work. No guarantees though.

  3. #3
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    183
    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.

  4. #4
    Senior Member
    Join Date
    Mar 2016
    Posts
    319
    If you use FRAM, you can eliminate the write delays.

  5. #5
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    183
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •