Hi everyone,
I recently built an ICM module to use it in my project.
I use IC to communicate with the ICM. but for some strange reason I cannot explain,
when I try to set the Accelerometer and Gyroscope Fullscale registers and then I read them back to check what has been written
the accelerometer registers have not been changed as I would expect.
Furthermore, after initialization of the sensor I read continuously the ACCEL_FS_SEL and GYRO_FS_SEL bits in
ACCEL_CONFIG and GYRO_CONFIG_1 registers and the ACCEL_FS_SEL bits change in every repeat.
What is going on here? What am I doing wrong? Do I forget something?
Below you can see the initialization code I have written and the debug output
Thank you for your time
void ICM_init(void)
{
ICM_Bank_selector(ICM_BANK_); // Ayth xreiazetai giati diaforetika den trexei thn ICM_ID_read
NRF_LOG_INFO("Selected Bank %d", ICM_Bank_read());
// ICM_WR_byte(ICM_PWR_MGMT_, x);
nrf_delay_ms(); if(ICM_ID_read() == xEA){
NRF_LOG_INFO("ICM ID is correct");
//--------------------------------------ICM POWER ON------------------------------------
NRF_LOG_INFO("============ICM Power-On==========");
ICM_Bank_selector(ICM_BANK_); NRF_LOG_INFO("IS BANK = x? x%x", ICM_Bank_read());
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_PWR_MGMT_ VALUE: x%x",ICM_RD_byte(ICM_PWR_MGMT_));
nrf_delay_ms();
ICM_WR_byte(ICM_PWR_MGMT_, x); //select best clk and disable temperature sensor
nrf_delay_ms();
NRF_LOG_INFO("IS NEW ICM_PWR_MGMT_ VALUE = x? x%x", ICM_RD_byte(ICM_PWR_MGMT_));
nrf_delay_ms();
//ICM_clk_select(BIT_CLK_PLL_);
//nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_LP_CONFIG VALUE: x%x",ICM_RD_byte(ICM_LP_CONFIG));
nrf_delay_ms();
ICM_WR_byte(ICM_LP_CONFIG, x);
nrf_delay_ms();
NRF_LOG_INFO("IS NEW ICM_LP_CONFIG = x? x%x", ICM_RD_byte(ICM_LP_CONFIG));
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_PWR_MGMT_ VALUE: x%x",ICM_RD_byte(ICM_PWR_MGMT_));
nrf_delay_ms();
ICM_enable_sensor(false, false, false);
nrf_delay_ms();
NRF_LOG_INFO("IS NEW ICM_PWR_MGMT_ = xF? x%x", ICM_RD_byte(ICM_PWR_MGMT_));
nrf_delay_ms();
ICM_enable_sensor(true, true, false);
nrf_delay_ms();
NRF_LOG_INFO("IS NEW ICM_PWR_MGMT_ = x? x%x", ICM_RD_byte(ICM_PWR_MGMT_));
nrf_delay_ms();
NRF_LOG_INFO("==========ICM ACCEL GYRO INIT=======");
//--------------------------Gyroscope Configuration----------------------
ICM_Bank_selector(ICM_BANK_); NRF_LOG_INFO("IS BANK = x? x%x", ICM_Bank_read());
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_GYRO_CONFIG_ VALUE: x%x",ICM_RD_byte(ICM_GYRO_CONFIG_));
ICM_WR_byte(ICM_GYRO_CONFIG_, xF ); //NRF_LOG_INFO("Set Gyro_Scale = dps and LPF = Hz");
nrf_delay_ms();
NRF_LOG_INFO("IS IT SET TO xF? x%x",ICM_RD_byte(ICM_GYRO_CONFIG_));
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_GYRO_SMPLRT_DIV VALUE: x%x",ICM_RD_byte(ICM_GYRO_SMPLRT_DIV));
nrf_delay_ms();
ICM_WR_byte(ICM_GYRO_SMPLRT_DIV, xA); //NRF_LOG_INFO("Set Gyro Sample_rate = Hz");
nrf_delay_ms();
NRF_LOG_INFO("IS IT SET TO xA? x%x",ICM_RD_byte(ICM_GYRO_SMPLRT_DIV));
nrf_delay_ms();
//--------------------------Accelerometer Configuration--------------------
ICM_Bank_selector(ICM_BANK_); NRF_LOG_INFO("IS BANK = x? x%x", ICM_Bank_read());
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_ACCEL_CONFIG VALUE: x%x",ICM_RD_byte(ICM_ACCEL_CONFIG));
nrf_delay_ms();
ICM_WR_byte(ICM_ACCEL_CONFIG, x); //NRF_LOG_INFO("Set Accel_Scale = g and LPF = Hz");
nrf_delay_ms();
NRF_LOG_INFO("IS IT SET TO x? x%x",ICM_RD_byte(ICM_ACCEL_CONFIG));
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_ACCEL_SMPLRT_DIV_ VALUE: x%x",ICM_RD_byte(ICM_ACCEL_SMPLRT_DIV_));
nrf_delay_ms();
ICM_WR_byte(ICM_ACCEL_SMPLRT_DIV_, x); //NRF_LOG_INFO("Set Accel Sample_rate = Hz ");
nrf_delay_ms();
NRF_LOG_INFO("IS IT SET TO x? x%x",ICM_RD_byte(ICM_ACCEL_SMPLRT_DIV_));
nrf_delay_ms();
NRF_LOG_INFO("OLD ICM_ACCEL_SMPLRT_DIV_ VALUE: x%x",ICM_RD_byte(ICM_ACCEL_SMPLRT_DIV_));
nrf_delay_ms();
ICM_WR_byte(ICM_ACCEL_SMPLRT_DIV_, xA); //NRF_LOG_INFO("Set Accel Sample_rate = Hz");
nrf_delay_ms();
NRF_LOG_INFO("IS IT SET TO xA? x%x",ICM_RD_byte(ICM_ACCEL_SMPLRT_DIV_));
nrf_delay_ms();
ICM_Bank_selector(ICM_BANK_);
NRF_LOG_INFO("Changed bank to ? %d", ICM_Bank_read());
nrf_delay_ms();
}
NRF_LOG_INFO("Read ACCEL_CONFIG and GYRO_CONFIG repeatedly");
for(uint_t k=;k<;k++){
resolutionA = ICM_RD_byte(ICM_ACCEL_CONFIG);
resolutionG = ICM_RD_byte(ICM_GYRO_CONFIG_);
arrayLen = sprintf(resArray,"ACCEL_CONFIG: %X GYRO_CONFIG: %X\n", (uint_t) resolutionA, (uint_t) resolutionG);
NRF_LOG_INFO("%s",resArray);
resolutionA = ;
resolutionG = ;
strcpy(resArray, "\");
}
======================================OUTPUT==================================
`