I2C , wire.h and 24 bit register with 16 bit address...

Hi all,

I have some doubt about how to use wire.h when I need to work with some I2C device with 7 bit device address, 16/24 bit register address and 24/32 bit register size.

For example the ADE7953 have many registers sized 24/32bit and 16 bit address :

Register: AWATT Address (24 bit Data) 0x212 Address (32 bit Data) 0x312

As you can see, the register address is 16 bit long and register size is 24 or 32 bit long.

It is possible to use wire.h in this case? It seems that wire.h could work only with 8 bit long address registers...

Thank you in advance for your kindly help, best regards, Mik

You may be confusing the I2C device address with the register addresses. Read page 53 of the datasheet.

Hi SurferTim,

no, I already read (and read again, and again, and again... :) ) the datasheet of the device. As you can see: I2C device address : is 7 bit long (+1 bit for R/W) Register Address: is 16 bit long Data : is 24/32 bit long

But the answer is still the same: how can I use wire.h with 16 bit register address size?

Thank you again, Mik

Seems fairly straightforward to me. The master sends the I2C device address byte, followed by the 16 bit register address. See figures 70 and 71.

Michelelos, you might be confused with those low level I2C descriptions. But most of the things at page 53 and 54 are automatically done by the Wire library.

I prefer to name the "register address" as "register", but I will call it register_address. And prefer to name "register" as "data".

To write to the chip:

int slave_address = ?;   // what is the I2C slave address ?
uint16_t register_address;
uint32_t data;

Wire.beginTransmission( slave_address);
Wire.write( highByte( register_address));
Wire.write( lowByte( register_address));
Wire.write( (data >> 24) & 0xFF);
Wire.write( (data >> 16) & 0xFF);
Wire.write( (data >> 8) & 0xFF);
Wire.write( (data) & 0xFF);
Wire.endTransmission();

As you can see, they are just a bunch of Wire.write().

To read from the chip:

Wire.beginTransmission( slave_address);
Wire.write( highByte( register_address));
Wire.write( lowByte( register_address));
Wire.endTransmission();

Wire.requestFrom( slave_address, 4);
// use Wire.read() 4 times, and store it in a 32-bit integer.
// probably with shifting
...

Koepel, I understood now!

Thank you very much for your GREAT help.

:smiley:

Mik