Regarding this post: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/315587.aspx
//
// Status register was read, check if reset is done before proceeding.
//
case MPU6050_STATE_INIT_WAIT:
{
//
// Check the value read back from status to determine if device
// is still in reset or if it is ready. Reset state for this
// register is 0x40, which has sleep bit set.
//
if(psInst->pui8Data[0] != MPU6050_PWR_MGMT_1_SLEEP)
{
//
// Device still in reset so begin polling this register.
//
psInst->uCommand.pui8Buffer[0] = MPU6050_O_PWR_MGMT_1;
I2CMRead(psInst->psI2CInst, psInst->ui8Addr,
psInst->uCommand.pui8Buffer, 1, psInst->pui8Data, 1,
MPU6050Callback, psInst);
}
else
{
//
// Device is out of reset, move to the idle state.
//
psInst->ui8State = MPU6050_STATE_IDLE;
}
break;
}
When t refer to the mpu9150, and i change the mpu6050.c lib to this one:
case MPU6050_STATE_INIT_WAIT:
{
//
// Check the value read back from status to determine if device
// is still in reset or if it is ready. Reset state for this
// register is 0x40, which has sleep bit set. Device may also
// respond with an address NACK during very early stages of the its
// internal reset. Keep polling until we verify device is ready.
//
//
if((psInst->pui8Data[0] != MPU6050_PWR_MGMT_1_SLEEP) ||
(ui8Status == I2CM_STATUS_ADDR_NACK))
{
//
// Device still in reset so begin polling this register.
//
psInst->uCommand.pui8Buffer[0] = MPU6050_O_PWR_MGMT_1;
I2CMRead(psInst->psI2CInst, psInst->ui8Addr,
psInst->uCommand.pui8Buffer, 1, psInst->pui8Data, 1,
MPU6050Callback, psInst);
//
// Intentionally stay in this state to create polling effect.
//
}
else
{
//
// Device is out of reset, move to the idle state.
//
// psInst->ui8State = MPU6050_STATE_IDLE;
//
// Device is out of reset, bring it out of sleep mode.
//
psInst->uCommand.pui8Buffer[0] = MPU6050_O_PWR_MGMT_1;
psInst->uCommand.pui8Buffer[1] = MPU6050_PWR_MGMT_1_CLKSEL_XG;
I2CMWrite(psInst->psI2CInst, psInst->ui8Addr,
psInst->uCommand.pui8Buffer, 2, MPU6050Callback,
psInst);
//
// Update state to show we are modifing user control and
// power management 1 regs.
//
psInst->ui8State = MPU6050_STATE_INIT_PWR_MGMT;
}
break;
}
But i dont actually understand why and also the state machine. Can anybody help me, i posted many questions but nobody answers me!
Please help me!