lsm303d: added I2C disable based on method from ST engineering support

This commit is contained in:
Andrew Tridgell 2013-11-28 20:30:04 +11:00 committed by Lorenz Meier
parent 9a169d8ef4
commit 7c9d92a5d6
1 changed files with 21 additions and 0 deletions

View File

@ -322,6 +322,11 @@ private:
*/ */
void reset(); void reset();
/**
* disable I2C on the chip
*/
void disable_i2c();
/** /**
* Static trampoline from the hrt_call context; because we don't have a * Static trampoline from the hrt_call context; because we don't have a
* generic hrt wrapper yet. * generic hrt wrapper yet.
@ -595,9 +600,25 @@ out:
return ret; return ret;
} }
void
LSM303D::disable_i2c(void)
{
uint8_t a = read_reg(0x02);
write_reg(0x02, (0x10 | a));
a = read_reg(0x02);
write_reg(0x02, (0xF7 & a));
a = read_reg(0x15);
write_reg(0x15, (0x80 | a));
a = read_reg(0x02);
write_reg(0x02, (0xE7 & a));
}
void void
LSM303D::reset() LSM303D::reset()
{ {
// ensure the chip doesn't interpret any other bus traffic as I2C
disable_i2c();
/* enable accel*/ /* enable accel*/
_reg1_expected = REG1_X_ENABLE_A | REG1_Y_ENABLE_A | REG1_Z_ENABLE_A | REG1_BDU_UPDATE | REG1_RATE_800HZ_A; _reg1_expected = REG1_X_ENABLE_A | REG1_Y_ENABLE_A | REG1_Z_ENABLE_A | REG1_BDU_UPDATE | REG1_RATE_800HZ_A;
write_reg(ADDR_CTRL_REG1, _reg1_expected); write_reg(ADDR_CTRL_REG1, _reg1_expected);