ICM 20948 magnetometer issue

By dmoroibvorg , 30 July 2020

Hi
I have a problem with magnetometer. I am following the code of the example eMD-SmartMotion-ICM20948-1.1.0-MP. In the setup I programmed this code:

#define AK0991x_DEFAULT_I2C_ADDR 0x0C /* The default I2C address for AK0991x Magnetometers */
icm20948_serif.context = 0; /* no need */

icm20948_serif.read_reg = my_serif_read_reg;
icm20948_serif.write_reg = my_serif_write_reg;
icm20948_serif.max_read = 128; /* maximum number of bytes allowed per serial read */
icm20948_serif.max_write = 128; /* maximum number of bytes allowed per serial write */
icm20948_serif.is_spi = false;

inv_icm20948_reset_states(&icm_device, &icm20948_serif);
rc += inv_icm20948_get_whoami(&icm_device, &who);

I have checked rc and who and I got 0 and 0xEA as expected.

/* Setup accel and gyro mounting matrix and associated angle for current board */
inv_icm20948_init_matrix(&icm_device);
rc += inv_icm20948_initialize(&icm_device, dmp3_image, sizeof(dmp3_image));

Again I checked rc and it is OK

/* Initialize auxiliary sensors */
inv_icm20948_register_aux_compass( &icm_device, INV_ICM20948_COMPASS_ID_AK09916, AK0991x_DEFAULT_I2C_ADDR);

rc += inv_icm20948_initialize_auxiliary(&icm_device);

When I checked rc here I got -1. I have search in the code what function returns the error code and I found that is int inv_icm20948_setup_compass_akm(struct inv_icm20948 * s) in Icm20948AuxCompassAkm.c. In this function this statement is executed:

if (data[0] != DATA_AKM_ID) {
// inv_log("Compass not found!!\r\n");
return -1;
}

I have read data[0] and it is 0. Any idea of why the compass is not found?

phpbb Topic ID
38552