Thank you for your great responce FAW_CA1 Now it seems to work but I have a few issues however. These are the two function I implemented The first function sets the accel in low power mode while gyro and mag in suspended mode. In order to put mag in suspended mode I followed the procedure of Table 17 pg 26. void low_active_state(struct bmi160_dev *dev_bmi160, struct bmm150_dev *dev_bmm150, uint8_t *bmm150_aux_addr, int state) {
/*
ACCEL: LOW POWER (200Hz ODR, AVG=4)
GYRO: SUSPENDED
MAG: SUSPENDED
*/
// na - Progress to put magnetometer and magnetometer interface into suspended mode
// na - It is mandatory to put magnetometer into suspend mode before putting magnetometer interface into suspend mode see pg 16 of BMX160 datasheet
uint8_t reg_data = 0;
uint8_t data = 0;
int8_t rslt = BMI160_OK;
reg_data = 0x19;
bmi160_set_regs(BMI160_COMMAND_REG_ADDR, ®_data, 1, dev_bmi160);
nrf_delay_ms(1);
reg_data = 0x80;
bmi160_set_regs(BMI160_AUX_IF_1_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x00;
bmi160_set_regs(BMI160_AUX_IF_4_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x4B;
bmi160_set_regs(BMI160_AUX_IF_3_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x18;
bmi160_set_regs(BMI160_COMMAND_REG_ADDR, ®_data, 1, dev_bmi160);
nrf_delay_ms(2);
dev_bmi160->gyro_cfg.power = BMI160_GYRO_SUSPEND_MODE; // na - set gyro to suspended mode
rslt = bmi160_set_sens_conf(dev_bmi160);
APP_ERROR_CHECK(rslt);
dev_bmi160->accel_cfg.odr = BMI160_ACCEL_ODR_200HZ;
dev_bmi160->accel_cfg.power = BMI160_ACCEL_LOWPOWER_MODE; // na - set accel to low power mode mode
rslt = bmi160_set_sens_conf(dev_bmi160);
APP_ERROR_CHECK(rslt);
nrf_delay_ms(10); // na - see pg 90 of BMX160 datasheet
rslt = bmi160_get_regs(BMI160_PMU_STATUS_ADDR, &data, 1, dev_bmi160);
NRF_LOG_INFO("info: Enter LOW ACTIVE STATE %d", state);
NRF_LOG_INFO("BMI160_PMU_STATUS_ADDR - LOW ACTIVE STATE: %d", rslt);
} The second function enters the void active_state(struct bmi160_dev *dev_bmi160, struct bmm150_dev *dev_bmm150, uint8_t *bmm150_aux_addr, int state) {
uint8_t reg_data = 0;
uint8_t data = 0;
int8_t rslt = BMI160_OK;
// na - Process to initialize magnetometer sleep mode, low power preset, 12.5Hz ODR and magnetometer interface low power - see pg 25 Table 16 of the BMX160 datasheet
reg_data = 0x19;
bmi160_set_regs(BMI160_COMMAND_REG_ADDR, ®_data, 1, dev_bmi160);
nrf_delay_ms(2);
reg_data = 0x80;
bmi160_set_regs(BMI160_AUX_IF_1_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x01;
bmi160_set_regs(BMI160_AUX_IF_4_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x4B;
bmi160_set_regs(BMI160_AUX_IF_3_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x01;
bmi160_set_regs(BMI160_AUX_IF_4_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x51;
bmi160_set_regs(BMI160_AUX_IF_3_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x0E;
bmi160_set_regs(BMI160_AUX_IF_4_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x52;
bmi160_set_regs(BMI160_AUX_IF_3_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x02;
bmi160_set_regs(BMI160_AUX_IF_4_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x4C;
bmi160_set_regs(BMI160_AUX_IF_3_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x42;
bmi160_set_regs(BMI160_AUX_IF_2_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x05;
bmi160_set_regs(BMI160_AUX_ODR_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x00;
bmi160_set_regs(BMI160_AUX_IF_1_ADDR, ®_data, 1, dev_bmi160);
reg_data = 0x1A;
bmi160_set_regs(BMI160_COMMAND_REG_ADDR, ®_data, 1, dev_bmi160);
nrf_delay_ms(2);
dev_bmi160->accel_cfg.odr = BMI160_ACCEL_ODR_400HZ;
dev_bmi160->accel_cfg.power = BMI160_ACCEL_NORMAL_MODE; // na - set accel to normal power mode mode
rslt = bmi160_set_sens_conf(dev_bmi160);
APP_ERROR_CHECK(rslt);
nrf_delay_ms(10); // na - see pg 90 of BMX160 datasheet
dev_bmi160->gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
rslt = bmi160_set_sens_conf(dev_bmi160);
APP_ERROR_CHECK(rslt);
nrf_delay_ms(150); // na - see pg 90 of BMX160 datasheet
rslt = bmi160_get_regs(BMI160_PMU_STATUS_ADDR, &data, 1, dev_bmi160); // na - read the PMU_STATUS register
NRF_LOG_INFO("info: Enter ACTIVE STATE %d", state);
NRF_LOG_INFO("BMI160_PMU_STATUS_ADDR - ACTIVE STATE: %d", rslt);
} It seems to work since in low_active_state only the accel is working while in active_state everything working and I have not any issue while changing states. I have however two issues: 1. I read the PMU_STATUS register and each time is 0... This couldn'd be possible since I receive measurements 2. I cannot see any impact in current consumption while changing states.. I mean the current consumption for both states low_active_state and active_state is the same. This couldn't be possible if I was succefully change power modes isn't it? Any advice on these issues? Thanks for your support so far Nick
... View more