ICM20948 - Unable to change the accel and gyro fullscale

Hi all,

I recently built my own ICM20948 module to use it in my project. I use nRF52840 uC for controlling the ICM20948. I also use the SparkFun library for reference in order to create my own very basic library to communicate with the sensor.

For some reason I cannot explain, when I try to set the Accelerometer and Gyroscope Fullscale registers to an other value (i.e. Accel = 8G, Gyro = 1000dps) the scale of both sensors will not change ( 2G/250dps).

Although I can receive data from both accelerometer and gyroscope, these data are always at 2g and 250dps scale.

I have tried various combinations in the initialization function I wrote, based on the ICM_20948_I2C::begin() function but without success.

I believe that I do something wrong with the write sequence I use to write the accel/gyro registers.

Below I copy the initialization function that I wrote based on the sparkfun library ( ICM_20948_I2C::begin() )

If any ideas of what I am doing wrong please share. Thanks

// ICM20948 initialization
void ICM_init(void){

     if(ICM_ID_read() == 0xEA){   // check if ID is correct  and initialize the sensor

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_PWR_MGMT_1);      // reset ICM20948
         nrf_delay_ms(100);
         var |= 0b10000000;
         ICM_WR_byte(ICM20948_PWR_MGMT_1, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_PWR_MGMT_1);     // wake up ICM20948 
         nrf_delay_ms(100);
         var &= 0b10111111;
         ICM_WR_byte(ICM20948_PWR_MGMT_1, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_PWR_MGMT_1);     // disable low power 
         nrf_delay_ms(100);
         var &= 0b11011111;
         ICM_WR_byte(ICM20948_PWR_MGMT_1, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_PWR_MGMT_1);    // select best clk 
         nrf_delay_ms(100);
         var &= 0b11111000;
         var |= 0b00000001;
         ICM_WR_byte(ICM20948_PWR_MGMT_1, var);
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_PWR_MGMT_2);     // disable sensors Acc and Gyro 
         nrf_delay_ms(100);
         var &= 0b11000000;
         var |= 0b00111111;
         ICM_WR_byte(ICM20948_PWR_MGMT_2, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_PWR_MGMT_2);     // enable sensors Acc and Gyro 
         nrf_delay_ms(100);
         var &= 0b11000000;
         ICM_WR_byte(ICM20948_PWR_MGMT_2, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_LP_CONFIG);     // set acc/gyro mode
         nrf_delay_ms(100);
         var &= 0b00000000;     // continuous
         ICM_WR_byte(ICM20948_LP_CONFIG, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_0);
         var = ICM_RD_byte(ICM20948_USER_CTRL);     // enable I2C_Mst 
         nrf_delay_ms(100);
         var &= 0b11011111;
         var |= 0b00100000;
         ICM_WR_byte(ICM20948_USER_CTRL, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_ACCEL_CONFIG);     // accelerometer fullscale
         nrf_delay_ms(100);
         var &= 0b11111001;
         var |= 0b00000100;        // 8G 
         ICM_WR_byte(ICM20948_ACCEL_CONFIG, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_GYRO_CONFIG_1);     // gyroscope fullscale
         nrf_delay_ms(100);
         var &= 0b11111001;
         var |= 0b00000100;        // 1000dps
         ICM_WR_byte(ICM20948_GYRO_CONFIG_1, var); 
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_ACCEL_CONFIG);     // accelerometer dlpf configuration
         nrf_delay_ms(100);
         var &= 0b11000110;
         var |= 0b00100000;        // Accel DLPFCFG = 4
         ICM_WR_byte(ICM20948_ACCEL_CONFIG, var);
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_GYRO_CONFIG_1);     // gyroscope dlpf configuration
         nrf_delay_ms(100);
         var &= 0b11000110;
         var |= 0b00100000;        // Gyro DLPFCFG = 4
         ICM_WR_byte(ICM20948_GYRO_CONFIG_1, var);
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_ACCEL_SMPLRT_DIV_1);     // accel samplerate MSB
         nrf_delay_ms(100);
         var &= 0b00000000;        // SMPRT MSB = 0
         ICM_WR_byte(ICM20948_ACCEL_SMPLRT_DIV_1, var);
         nrf_delay_ms(100);
         
         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_ACCEL_SMPLRT_DIV_2);     // accel samplerate LSB
         nrf_delay_ms(100);
         var &= 0b00000000;
         var |= 0b00000111;         //SMPRT LSB = 7
         ICM_WR_byte(ICM20948_ACCEL_SMPLRT_DIV_2, var);
         nrf_delay_ms(100);

         ICM_Bank_selector(ICM_BANK_2);
         var = ICM_RD_byte(ICM20948_GYRO_SMPLRT_DIV);     // gyro samplerate 
         nrf_delay_ms(100);
         var &= 0b00000000;
         var |= 0b00000111;         // Gyro SMPR = 4
         ICM_WR_byte(ICM20948_GYRO_SMPLRT_DIV, var);
         nrf_delay_ms(100);
     }
     else    // if ID is not correct send debug message and blink LED forever
     { 
       NRF_LOG_INFO("ID ERROR");
       nrf_delay_ms(20);
       while(1)
       {
          nrf_delay_ms(400);
          bsp_board_led_invert(2);

       }
     }  
}