We are used to ‘c’ language, and the “0b00001111” is handled by the compiler and never fails.
The Arduino definition of “B00001111” is not as versatile.
There are two ways to check the I2C communication: the error return value of Wire.endTransmission() and the number of received bytes return value of Wire.requestFrom().
The Wire.available() can also be used instead of the return value of Wire.requestFrom().
When you write something to the sensor for the first time, it might be good to test the return value of Wire.endTransmission(). Your function “i2c_writeRegisterByte()” returns that error, but there is no example how to use it.
If the first test is okay (error is 0), then you may assume that the I2C bus is working and you don’t have to do extra tests.
In case the slave is an Arduino board, perhaps testing the return value of Wire.requestFrom() or Wire.available() could be added.
If a normal sensor does not return data, there must be something very wrong with the I2C bus. But since many users use long wires, long cables, wrong pullup resistors, wrong voltage levels, and so on, there is often something very wrong with the I2C bus. Perhaps adding extra checks can be usefull for such situations as well.
I think the best way is not to fill the variables with data, when there is no valid data.
There is more than one way to check if data was received. Here are a few examples:
byte n = Wire.requestFrom( 0x27, 4);
if( n == 4)
{
Wire.readBytes( buffer, 4);
}
if( Wire.requestFrom( 0x27, 4) == 4)
Wire.readBytes( buffer, 4);
Wire.requestFrom( 0x27, 4);
if( Wire.available() == 4)
{
for( int i=0; i<4; i++)
{
buffer[i] = Wire.read();
}
}
In the past there was an undocumented Wire.requestFrom() that did writing the register-address and reading the data (just like your “i2c_readRegisterByte”) all at once. I think it is removed since I can’t find it anymore.