I want to read a register 0x012A from the device I2C address 0x0A, the value stored in the register is two bytes, If the register address is one byte i can use Wire.requestFrom and give the register address and how many bytes i want to read since here register address itself 2 bytes i'am bit confused . can any one help in this regard.
1 Answer
i can use Wire.requestFrom and give the register address and how many bytes i want to read
So you give it 2
to ask for 2 bytes.
Then you combine them. How you do that depends on what the bytes represent. If the first is the upper byte and the second the lower byte of a 16 bit value then you would:
uint8_t b1 = Wire.read();
uint8_t b2 = Wire.read();
uint16_t val = (b1 << 8) | b2;
If it's the other way around then just swap the variables in the combining section.
However if the values are some other arrangement (I saw something recently that had two registers with a 12 bit value with overlapping bits) you will have to combine it in the way that is required for that specific arrangement.
requestFrom
to read any number of bytes (which happens to be two as well, in your case).