writing to i2C EEPROM

greetings,

I have a third party EEPROM i2C memory that I need to modify using an arduino.

Using the third party application I can export the EEPROM data to a txt file and I can see the contents using a hex editor.

So I am trying to reproduce the contents using arduino and write to the EEPROM. The format is simple and should look like this but i am missing something and cannot reproduce it.

[Param]
param1=123
param2=456
param3=789
param4=987
param5=654
param6=321
param7=999
param8=888
param9=999
param10=111

I can see in the attached text file TEST.txt extracted using the third party app that the end of line characters are 0x0D,0x0A and the end of file character is 0xFF.

My problem is that i cannot figure out how to recreate the data and write to the i2c EEPROM using and arduino.

below is the code i am testing with. Currently it seems that I can only write the first string "this is a test string" and the third party application ignores everything after that. the output text file after processing my code can be found here. TEST2.txt

i think my issue is related to the Wire.endTransmission(); function that closes the file but im doing my head in trying to understand it.

please help me construct my strings correctly so i can build and save multiple parameters.

here is the code that i am testing with that is based on the wire example code.

#include <Wire.h>

void setup()
{
    char somedata[] = "THIS IS A TEST STRING";       // will be [Param]
    char somedata2[] = "One Two Three Four";         // will be param1=123 etec. 
    
    Wire.begin();                                                             // initialise the connection
    i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata));       // write to EEPROM
    i2c_eeprom_write_byte(0x50, 0x0E,0x0D) ;                                  // OD End Of Line                  ( int deviceaddress, unsigned int eeaddress, byte data )
    i2c_eeprom_write_byte(0x50, 0x0F,0x0A);                                   // OA End Of Line
    i2c_eeprom_write_page(0x50, 0x10, (byte *)somedata2, sizeof(somedata2));  // write to EEPROM
    i2c_eeprom_write_byte(0x50, 0x22,0xFF);                                   // FF End Of File
    Wire.endTransmission();
    delay(100); //add a small delay

}

////////////////////////////////////////////////////////////////
void loop()
{

}
////////////////////////////////////////////////////////////////




void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
    int rdata = data;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.write(rdata);
    Wire.endTransmission();
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddresspage >> 8)); // MSB
    Wire.write((int)(eeaddresspage & 0xFF)); // LSB
    byte c;
    for ( c = 0; c < length; c++)
        Wire.write(data[c]);
    Wire.endTransmission();
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.read();
    return rdata;
}

// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,length);
    int c = 0;
    for ( c = 0; c < length; c++ )
        if (Wire.available()) buffer[c] = Wire.read();
}

Thanks in advance!

TEST.JPG

TEST2.JPG

TEST.JPG

TEST2.JPG

What kind of EEPROM is it?

microchip 24FC64

My take, addressing the test code:

You might want strlen() rather than sizeof() to write the initial string. This would write the characters only and not the terminating null. Possibly the 3rd party sees the null and chokes.

somedata[] is twenty-two characters, including the terminating null, \0. So, after writing that your next address should be twenty-two, 0x16. You then append the CR/LF at 0x0E (14 decimal) and overwrite the end of the string.

thanks Dougp,

ill try the strlen() idea !

the address for CR and LF have been changed a few times to accommodate my different test strings and i forgot to adjust the addresses in the example. but thanks for spotting it!

i will try to make their addresses variable in the future so they are not in fixed locations.