Proper SW reset recovery of I2C/compass ICM-20948

By georgeopeneraero , 9 October 2020

I'm wondering what the best way to SW reset an ICM-20948. We have some cases where sometimes on initial initialization attempts the I2C bus and/or the internal compass on this chip becomes locked up and unable to pass WHOAMI checks. In this state we have found the only way to reset the I2C bus is to power cycle the chip.

Currently our reset routine looks something like this:

// Reset the ICM20948
write_register(Icm20948Registers::kPwrMgmt1Addr, Icm20948Values::kPwrMgmt1DeviceReset);
SystemTime::DelayMs(10);

// Exit sleep mode and configure the clock. It seems most registers can't be configured until
// this is done -- they read back as 0x00 no matter how many times they are written to.
bool success = write_register_verified(Icm20948Registers::kPwrMgmt1Addr, Icm20948Values::kPwrMgmt1ClkSelMask1);

// Enable I2C Master, disable I2C slave.
success &= write_register_verified(Icm20948Registers::kUserCtrl,
Icm20948Values::kUserCtrlSpiEnableMask | Icm20948Values::kUserCtrlI2cMstEn);

// Set to I2C stop between reads, clk frequency to 345 kHz
success &= write_register_verified(Icm20948Registers::kI2cMstCtrl,
Icm20948Values::kI2cMstCtrlStopBetweenReads | Icm20948Values::kI2cMstCtrlClockFreq);

// Delay shadowing external sensor data until all data is received
success &= write_register_verified(Icm20948Registers::kI2cMstDelayCtrl, Icm20948Values::kI2cMstDelayEsShadow);

// Configure gyro and accel
success &= configure_gyro(kIcm20948SampleRate, Icm20948Values::kGyroConfigFs500_dps, Icm20948Values::kGyroConfigBw50Hz);
success &= configure_accel(kIcm20948SampleRate, Icm20948Values::kAccelConfigFs16_g, Icm20948Values::kAccelConfigBw50Hz);

//Setup compass attempts
if (!VerifyMagnetometerDeviceId()) {
return false;
}

// Soft reset of the compass
write_mag_register(Icm20948MagRegisters::Cntl3, Icm20948MagRegisters::Cntl3Srst);

We have tried putting the compass reset above the deviceID checks without success. We are currently confident in our driver because most of the time the compass starts up properly and reads correct information without fault for the duration of our tests. In addition, our gyro and accel have been working without issue. This lockup issue usually only happens during powerup or SW reset of the controlling microcontroller.

Any help with this would be much appreciated.

phpbb Topic ID
38690