SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Movement & IMU category should be posted in this forum.
By dkelly79
#207056
I'm running the Sparkfun Qwiic ICM-20948 IMU connected to the Sparkfun ESP32 Thing Plus, connected via I2C Qwiic. When I run Example 2, the magnetometer will not output. If I comment out the

myICM.swReset( );

line, everything appears to print out fine. I've tried a few work-arounds, but it appears that for some reason running swReset() shuts off the mag output.
#207059
Hello dkelly79,

In the ICM-20948 the magnetometer is a 'sister' sensor to the gyroscope and accelerometer. When talking to the ICM breakout board over I2C the '.begin()' function configures the board to use I2C passthrough to talk to the magnetometer directly. In example2 performing a sw reset after the '.begin()' call undoes that configuration and it is not re-performed in the example. The easiest way to get your magnetometer output is to add this line to your setup function after the reset (I did it after the 'configuration complete' print statement when I tested it)
Code: Select all
myICM.startupMagnetometer();

For a more detailed look here's what happens inside '.begin()'
Code: Select all
    _has_magnetometer = true;
    retval = startupMagnetometer();
    if(( retval != ICM_20948_Stat_Ok) && ( retval != ICM_20948_Stat_NotImpl )){ status = retval; return status; }
    if( retval == ICM_20948_Stat_NotImpl ){
        // This is a temporary fix. 
        // Ultimately we *should* be able to configure the I2C master to handle the 
        // magnetometer no matter what interface (SPI / I2C) we are using. 

        _has_magnetometer = false;
        retval = ICM_20948_Stat_Ok; // reset the retval because we handled it in this cases
    }

The comment regarding magnetometer startup in SPI vs I2C is there b/c in a SPI interface we cannot use the I2C passthrough to talk to the mag, so we need to use the I2C master capabilities of the ICM-20948. That feature is not currently built into the library but it would make a great contribution!