Skip to content

Commit a29c1c5

Browse files
committed
Corrections and extra debug for issue #8
1 parent b27edc2 commit a29c1c5

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

examples/Arduino/Example2_Advanced/Example2_Advanced.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ void setup()
9898
SERIAL_PORT.println(myICM.statusString());
9999
}
100100

101-
delay(1); // Give the ICM20948 time to change the sample mode (see issue #8)
102-
103101
// Set full scale ranges for both acc and gyr
104102
ICM_20948_fss_t myFSS; // This uses a "Full Scale Settings" structure that can contain values for all configurable sensors
105103

src/ICM_20948.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ bool ICM_20948::isConnected(void)
395395
ICM_20948_Status_e ICM_20948::setSampleMode(uint8_t sensor_id_bm, uint8_t lp_config_cycle_mode)
396396
{
397397
status = ICM_20948_set_sample_mode(&_device, (ICM_20948_InternalSensorID_bm)sensor_id_bm, (ICM_20948_LP_CONFIG_CYCLE_e)lp_config_cycle_mode);
398+
delay(1); // Give the ICM20948 time to change the sample mode (see issue #8)
398399
return status;
399400
}
400401

src/util/ICM_20948_C.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,26 @@ ICM_20948_Status_e ICM_20948_set_sample_mode(ICM_20948_Device_t *pdev, ICM_20948
627627
{
628628
return retval;
629629
}
630+
631+
// Check the data was written correctly
632+
retval = ICM_20948_execute_r(pdev, AGB0_REG_LP_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_LP_CONFIG_t));
633+
if (retval != ICM_20948_Stat_Ok)
634+
{
635+
return retval;
636+
}
637+
if (sensors & ICM_20948_Internal_Acc)
638+
{
639+
if (reg.ACCEL_CYCLE != mode) retval = ICM_20948_Stat_Err;
640+
}
641+
if (sensors & ICM_20948_Internal_Gyr)
642+
{
643+
if (reg.GYRO_CYCLE != mode) retval = ICM_20948_Stat_Err;
644+
}
645+
if (sensors & ICM_20948_Internal_Mst)
646+
{
647+
if (reg.I2C_MST_CYCLE != mode) retval = ICM_20948_Stat_Err;
648+
}
649+
630650
return retval;
631651
}
632652

@@ -646,6 +666,9 @@ ICM_20948_Status_e ICM_20948_set_full_scale(ICM_20948_Device_t *pdev, ICM_20948_
646666
retval |= ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
647667
reg.ACCEL_FS_SEL = fss.a;
648668
retval |= ICM_20948_execute_w(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
669+
// Check the data was written correctly
670+
retval |= ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
671+
if (reg.ACCEL_FS_SEL != fss.a) retval |= ICM_20948_Stat_Err;
649672
}
650673
if (sensors & ICM_20948_Internal_Gyr)
651674
{
@@ -654,6 +677,9 @@ ICM_20948_Status_e ICM_20948_set_full_scale(ICM_20948_Device_t *pdev, ICM_20948_
654677
retval |= ICM_20948_execute_r(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
655678
reg.GYRO_FS_SEL = fss.g;
656679
retval |= ICM_20948_execute_w(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
680+
// Check the data was written correctly
681+
retval |= ICM_20948_execute_r(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
682+
if (reg.GYRO_FS_SEL != fss.g) retval |= ICM_20948_Stat_Err;
657683
}
658684
return retval;
659685
}
@@ -674,6 +700,9 @@ ICM_20948_Status_e ICM_20948_set_dlpf_cfg(ICM_20948_Device_t *pdev, ICM_20948_In
674700
retval |= ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
675701
reg.ACCEL_DLPFCFG = cfg.a;
676702
retval |= ICM_20948_execute_w(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
703+
// Check the data was written correctly
704+
retval |= ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
705+
if (reg.ACCEL_DLPFCFG != cfg.a) retval |= ICM_20948_Stat_Err;
677706
}
678707
if (sensors & ICM_20948_Internal_Gyr)
679708
{
@@ -682,6 +711,9 @@ ICM_20948_Status_e ICM_20948_set_dlpf_cfg(ICM_20948_Device_t *pdev, ICM_20948_In
682711
retval |= ICM_20948_execute_r(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
683712
reg.GYRO_DLPFCFG = cfg.g;
684713
retval |= ICM_20948_execute_w(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
714+
// Check the data was written correctly
715+
retval |= ICM_20948_execute_r(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
716+
if (reg.GYRO_DLPFCFG != cfg.g) retval |= ICM_20948_Stat_Err;
685717
}
686718
return retval;
687719
}
@@ -709,6 +741,16 @@ ICM_20948_Status_e ICM_20948_enable_dlpf(ICM_20948_Device_t *pdev, ICM_20948_Int
709741
reg.ACCEL_FCHOICE = 0;
710742
}
711743
retval |= ICM_20948_execute_w(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
744+
// Check the data was written correctly
745+
retval |= ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_CONFIG, (uint8_t *)&reg, sizeof(ICM_20948_ACCEL_CONFIG_t));
746+
if (enable)
747+
{
748+
if (reg.ACCEL_FCHOICE != 1) retval |= ICM_20948_Stat_Err;
749+
}
750+
else
751+
{
752+
if (reg.ACCEL_FCHOICE != 0) retval |= ICM_20948_Stat_Err;
753+
}
712754
}
713755
if (sensors & ICM_20948_Internal_Gyr)
714756
{
@@ -724,6 +766,16 @@ ICM_20948_Status_e ICM_20948_enable_dlpf(ICM_20948_Device_t *pdev, ICM_20948_Int
724766
reg.GYRO_FCHOICE = 0;
725767
}
726768
retval |= ICM_20948_execute_w(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
769+
// Check the data was written correctly
770+
retval |= ICM_20948_execute_r(pdev, AGB2_REG_GYRO_CONFIG_1, (uint8_t *)&reg, sizeof(ICM_20948_GYRO_CONFIG_1_t));
771+
if (enable)
772+
{
773+
if (reg.GYRO_FCHOICE != 1) retval |= ICM_20948_Stat_Err;
774+
}
775+
else
776+
{
777+
if (reg.GYRO_FCHOICE != 0) retval |= ICM_20948_Stat_Err;
778+
}
727779
}
728780
return retval;
729781
}

0 commit comments

Comments
 (0)