Hi, I'm using the I2C Master library created by Wayne Truchsess (for the timeout feature). The common write and read functions are defined for 8bit register address. I'm now dealing with 16bits registers and I don't know how to use the I2C functions to do it.(I tried to look into the cpp file but can't understand some basic settings)
I just wonder how to use I2C Master low level functions like I2c.start(), I2c.sendAddress() and I2c.sendByte(), I2c.receiveByte() to do that. (I'll get an error said: is private within this context)
Thanks in advance
Sorry about the stupid question. Looks like general users should not use the low level (private) methods.
For 16 bit register address, we could use I2c.write(slave_addr, reg_addr[0:7], data*(reg_addr[8:15]+original_data))
I2C is a byte oriented serial data communication protocol. Any data/operand/register larger than 8-bit must be broken into bytes before they are handled by I2C Bus. For example: you want to write data byte 0x12 into memory location 0x0100 of an external EEPROM location and 0x34 into the next memory location, you need to execute the following codes:
Wire.beginTransmission(slaveAddress);
Wire.write(highByte(0x0100)); //upper 8-bit of the EEPROM beginning location
Wire.write(lowByte(0x0100)); //lower 8-bit of the EEPROM beginning location
Wire.write(0x12); //data for location 0x0100
Wire.write(0x34); //data for location 0x0101;
Wire.endTransmission();
delay(5); //data write delay fro the EEPROM
To read the above data back from the EEPROM, let us execute the following codes:
Wire.beginTransmission(slaveAddress);
Wire.write(highByte(0x0100)); //upper 8-bit of the EEPROM beginning location
Wire.write(lowByte(0x0100)); //lower 8-bit of the EEPROM beginning location
Wire.endTransmission();
Wire.requestFrom(slaveAddress, 2); //2 byte data to read statring from location 0x0100
byte x1 = Wire.read(); //x1 should hold 0x12
byte x2 = Wire.read(): //x2 should hold 0x34