Hi all,
I think I found a bug into the SFE_LSM9DS0 library for Arduino into the setAccelABW routine.
This is the original code:
void LSM9DS0::setAccelABW(accel_abw abwRate)
{
// We need to preserve the other bytes in CTRL_REG2_XM. So, first read it:
uint8_t temp = xmReadByte(CTRL_REG2_XM);
// Then mask out the accel ABW bits:
temp &= 0xFF^(0x3 << 7);
// Then shift in our new ODR bits:
temp |= (abwRate << 7);
// And write the new register value back into CTRL_REG2_XM:
xmWriteByte(CTRL_REG2_XM, temp);
}
In my opinion instead of:
temp &= 0xFF^(0x3 << 7);
temp |= (abwRate << 7);
Should be:
temp &= 0xFF^(0x3 << 6);
temp |= (abwRate << 6);
These lines of codes are masking and then setting the new accelerometer anti-alias filter bandwidth bits. But the original code is setting the wrong ones.
Shifting the “2 digits (0x3)” by 7 position will create a register overflow masking the wrong bits and missing one of the two bits that we want to setup ABW1 and ABW0. The “two digits” should be shifted only by 6 positions in order to get the desired result.
I hope that this will help to avoid some headaches.
Regards,
Maximilian
Check the LSM9DS0’s datasheet at page 56 for more details.