24LC256 I2c eeprom with i2c lib insteed of wire

Hey guys im looking to to expand the memory of my eeprom to store more waypoints for my quadcopter im using arudcopter so when i tried to add my eeprom read write functions that are depended on the Wire library it failed as some of the functions ect are the same as the I2c library that arudcopter uses so id like to know how to use my eeprom with this library https://github.com/ninjablocks/arduino/tree/master/I2C as i believe thats the library there useing.

my read / write functions for the Wire lib are as follows

void i2c_eeprom_write_byte_rot(unsigned int eeaddress,byte data ) 
{
    int waydata = data;
    int deviceaddress = 0x50;

    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.write(data);
    Wire.endTransmission();

    delay(20);
}

byte i2c_eeprom_read_byte_rot( unsigned int eeaddress ) 
{
    int deviceaddress = 0x50;
    byte wayreaddata = 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()) wayreaddata = Wire.read();
    return wayreaddata;

}

but im unsure how to use the i2c lib with my eeprom there is an example here https://github.com/ninjablocks/arduino/blob/master/I2C/examples/HMC5883L/HMC5883L.pde for useing a i2c magnetometer but i i couldn't sort it out

any help will be much appreciated

hector.

ok heres my attempt

        void i2c_eeprom_write_byte_rot(int eeaddress,byte data ) 
        {
            int waydata = data;
            int deviceaddress = 0x50;
            //I2c.beginTransmission(deviceaddress);
            I2c.write(deviceaddress,eeaddress >> 8); // MSB
            I2c.write(deviceaddress,eeaddress & 0xFF); // LSB
            I2c.write(deviceaddress,data);
            //I2c.endTransmission();

            delay(20);
        }

But it fails with this error

ArduCopter.cpp: In function 'void i2c_eeprom_write_byte_rot(int, byte)':
commands:193: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
C:\Users\User\Desktop\QUAD STUFF\arudmegacopter\arduino-1.0.1\libraries\I2C/I2C.h:88: note: candidate 1: uint8_t I2C::write(int, int)
C:\Users\User\Desktop\QUAD STUFF\arudmegacopter\arduino-1.0.1\libraries\I2C/I2C.h:87: note: candidate 2: uint8_t I2C::write(uint8_t, uint8_t)

this confused me alittle could anyone explane those errors?

It looks like i2c lib has these two functions:

    uint8_t write(uint8_t, uint8_t);
    uint8_t write(int, int);

I think the complaint is for this call

  I2c.write(deviceaddress,data);

"deviceaddress" is type int and "data" is type byte which is uint8_t so the compiler can't choose which to use.

You must cast "deviceaddress" to uint8_t or "data" to int. like this:

  I2c.write((uint8_t)deviceaddress,data);

or

  I2c.write(deviceaddress,(int)data);

written an I2C EEPROM lib some time ago - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

the most useful feature added was the writeBlock and readBlock that can write bigger objects accross page boundaries.

I2C_eeprom(uint8_t);                    // constructor; param is I2C address
void writeByte(unsigned int, uint8_t ); // write a byte to address
uint8_t readByte(unsigned int);     // read a byte from address

void writeBlock(unsigned int, uint8_t* , int ); // write a bunch of bytes
void readBlock(unsigned int, uint8_t*, int );   // read a bunch of bytes
//first param is the address.
//second param is pointer to object.
//third is the size of the object.

what is still on my list is a readNext function that could read the next byte from eeeprom without applying the address every time

to read a string one could do something like

c= readByte(addr);
while (c != '\0')
{
  s[i++] = c;
  c = readNext();
}

never found time (or need ;)

The individual writes will not work. You basically have to package the the writes in one call. To quote the author of the i2c library:

"Technically when sending bytes to a slave device there is no difference between data and an address. In other words let's say you have a three byte address and three bytes of data. You could use the write(address, regaddress, *data) by making the first byte of your multibyte address equal to regaddress and then combine the rest of the address and data together into *data."

This works for me...

    I2c.begin();
    I2c.pullup(0);
    uint8_t registerAddress = 0x02;

    //WRITE
    uint8_t msb = (registerAddress >> 8);
    uint8_t lsb = (registerAddress & 0xFF);
    uint8_t data[4] = {lsb, 0, 11, 22};
    byte e = I2c.write(disk1, msb, data, 4);
    Serial.println("Reports (0 if success):");
    Serial.println(e);

    //READ
    I2c.write(disk1, msb, lsb);
    I2c.read(disk1, (uint8_t) 3); //read 3 bytes (x,y,z) from the device
    int x = I2c.receive();
    int y = I2c.receive();
    int z = I2c.receive();
    Serial.println("Results:");
    Serial.println(x);
    Serial.println(y);
    Serial.println(z);

robtillaart: written an I2C EEPROM lib some time ago - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

the most useful feature added was the writeBlock and readBlock that can write bigger objects accross page boundaries.

I2C_eeprom(uint8_t);                // constructor; param is I2C address
void writeByte(unsigned int, uint8_t ); // write a byte to address
uint8_t readByte(unsigned int); // read a byte from address

void writeBlock(unsigned int, uint8_t* , int ); // write a bunch of bytes void readBlock(unsigned int, uint8_t*, int ); // read a bunch of bytes //first param is the address. //second param is pointer to object. //third is the size of the object.




what is still on my list is a readNext function that could read the next byte from eeeprom without applying the address every time

to read a string one could do something like 



c= readByte(addr); while (c != '\0') {  s[i++] = c;  c = readNext(); } ```

never found time (or need ;)

uint8_t readNext(I2Caddress){
Wire.requestfrom(I2Caddress,1);
return Wire.read();
}

Of course, this assumes (ass U Me) that the internal 'register' pointer is pointing to the byte you want to read.

Reading 30 bytes this way is more than twice as slow as:

bool done = false;
while(!done){
 Wire.requestFrom(I2Caddress,30);
 while( Wire.available()){ 
     ch = Wire.read();
     }
 done = some magical termination decision;
 }

Chuck.