reading only a bit with Wire library

I want to read only one bit of an ADXL345 accelerometer using Wire library. Specifically i want to read only a specific bit from INT_SOURCE (0x30) without touching the other bits. I understand that requestFrom and read function of Wire library support only 1 byte minimum readings..

Read the byte that contains the bit then use the bitRead() function to get the bit that you want.

groundFungus:
Read the byte that contains the bit then use the bitRead() function to get the bit that you want.

No, this will not work..this is what the library does..
The problem is that i DONT want to read the whole byte, because if i read it, it will clear all the interrupts..i want to clear only specific interrupt = read specific bit..
not read all byte and find a specific bit value

You can’t read just one bit using I2C. The ADXL345 has two interrupt output pins, which report any desired combination of available interrupts, and you can read those pins using Arduino digital inputs.

Tell us what you actually want to do.

uzer123:
I understand that requestFrom and read function of Wire library support only 1 byte minimum readings..

That is how I2C works :wink:

1. I2C Bus is a "byte oriented" communication protocol which means data exchange takes place 1-byte at a time. There is no way to exchange 1-bit data between Master and Slave even you use low level assembly instructions.

2. There are 8 flag bits in the "INT_SOURCE" register of ADXL345 sensor (Fig-1). These flag bits assume Logic High states when the corresponding events are triggered.
INT_SOURCEReg.png
Figure-1:

(1) READ_BIT, WATERMARK, and OVERRUN bits are cleared when data are read from the accelerometer registers (DATAX, DATAY, DATAZ).

(2) The remaining bits (SINGLE_TAP, DOUBLE_TAP, ACTIVITY, INACTIVITY, FREE_FALL) are get cleared when a read operation is done on the INT_SOURCE Register at address 0x30.

3. The following codes could be exercised to verify the above propositions of data sheets.

Wire.beginTransmission(0x1D);   //device address
Wire.write(0x30);  //pointing the INT_SOURCE Register
Wire.endTransmission();

byte m = Wire.requestFrom(0x1D, 1);    //reading 1-byte data from INT_SOURCE Register
byte y = Wire.read();    //check that BIT_READY (y7 of y) is still HIGH

INT_SOURCEReg.png

Thanks for the answers..i actually know the info you sent, i just validated that there isnt a way to "partially" read a byte with i2c protocol.

Thank you

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.