-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect bit masking (e.g. data &= ~0xfc ) in various functions #4
Comments
I agree. I noticed this in the CTRL_REG4 as well. It is perhaps going unnoticed because the default is 00, and changing to non-zero values would work...once. If you set the range to non-zero bits and then back it would be incorrect. That's how it looks to me anyway, so this seems like confirmation. I have not done anything to test that idea yet, or try changing the method, but just in code review. Seems fairly easy to fix but needs these multiple places reviewed as it seems to be a systematic mistake. |
To piggy back on this, another customer also found a similar issue with the library here: https://github.com/sparkfun/SparkFun_LIS331_Arduino_Library/blob/master/src/SparkFun_LIS331.cpp#L232-L246 and proposed the following changes:
|
I can confirm that clearing the wrong bits in CTRL_REG4 (and not clearing the right ones) was preventing the sensor to switch the full scale range to lower ranges once HIGH_RANGE was selected. Changing line 255 of SparkFun_LIS331.cpp to Moreover, looking for further register bit-clearing operations, I've found that lines 116, 240, and 245 also seem wrong, with the bitwise negation incorrectly used (or wrong constants). I did not test these, though. |
There appear to be several places where the wrong bits are being masked/reset to zero in the LIS331.cpp library.
For example, at
SparkFun_LIS331_Arduino_Library/src/SparkFun_LIS331.cpp
Line 240 in fe80a5d
Actually, this is clearing all bits except the low two bits of the register. The correct statement would be either
data &= ~0x03;
ordata &= 0xfc;
(note the presence/absence of tildes in each of these versions).Similarly this occurs in
SparkFun_LIS331_Arduino_Library/src/SparkFun_LIS331.cpp
Line 245 in fe80a5d
which should be
data &= ~0x18;
.I found these examples/bugs when looking at the code for LIS331::setFullScale(), which should be clearing bits 5:4 but actually clears everything except those bits:
The third statement should read
data &= ~0x30;
.Thanks,
Pm
The text was updated successfully, but these errors were encountered: