2022-04-03 07:10 PM
Thresholds:
lsm6dsl_****_debounce_steps_set(&IMU_Ctx, imuParams.debounce_steps);
lsm6dsl_****_timeout_set(&IMU_Ctx, imuParams.debounce_timeout);
lsm6dsl_****_threshold_set(&IMU_Ctx, imuParams.step_thd);
function tp get cstep counter:
uint16_t IMU_API_ReadAndClearStepsCounter(void)
{
uint16_t steps[2];
int tries = 2;
// do consensual decision
do {
lsm6dsl_read_reg(&IMU_Ctx, LSM6DSL_STEP_COUNTER_L, (uint8_t*)&steps[0], sizeof(uint16_t));
lsm6dsl_read_reg(&IMU_Ctx, LSM6DSL_STEP_COUNTER_L, (uint8_t*)&steps[1], sizeof(uint16_t));
tries--;
}while(tries && (steps[0] != steps[1]));
if(steps[0] !=steps[1]) {
steps[0] = (uint16_t)-1;
}
// clear steps counter
lsm6dsl_****_step_reset_set(&IMU_Ctx, 1); // reset step counter
lsm6dsl_****_step_reset_set(&IMU_Ctx, 0); // reset step counter
return steps[0];
}
2022-04-07 11:52 AM
Hello @HTurj.1 , Could you please share your sensor setup code with us? I believe there must be a problem when writing to the pedometer enabling registers.
2022-04-10 06:12 AM
Hi,
First I call to IMU_Setup()
tatic void IMU_Setup(void)
{
IMU_LOG_DEBUG_MSG("IMU_PreInit()\n");
IMU_InitLSM6DSL();
IMU_PowerDown();
IMU_API_DeferOp(IMU_CMD_PEDOMETER_WRITE);
IMU_InitInterrupt();
}
static void IMU_InitLSM6DSL(void)
{
lsm6dsl_reg_t reg;
wiced_result_t res;
// IMU Reset procedure - See LSM6DSL power up behavior paragraph 5.7 http://www.st.com/content/ccc/resource/technical/document/application_note/group0/26/07/3f/bf/12/55/47/62/DM00402563/files/DM00402563.pdf/jcr:content/translations/en.DM00402563.pdf
res = lsm6dsl_gy_data_rate_set(&IMU_Ctx, LSM6DSL_GY_ODR_OFF);
//APP_ERROR_CHECK(errCode);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_gy_data_rate_set() error. Err=%d\n", res);
}
res = lsm6dsl_xl_power_mode_set(&IMU_Ctx, LSM6DSL_XL_HIGH_PERFORMANCE);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_xl_power_mode_set() error. Err=%d\n", res);
}
res = lsm6dsl_reset_set(&IMU_Ctx, 1);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_reset_set() error. Err=%d\n", res);
}
//vTaskDelay(pdMS_TO_TICKS(1)); // 50 us. See LSM6DSL power up behavior paragraph 5.7 http://www.st.com/content/ccc/resource/technical/document/application_note/group0/26/07/3f/bf/12/55/47/62/DM00402563/files/DM00402563.pdf/jcr:content/translations/en.DM00402563.pdf
wiced_rtos_delay_milliseconds(1);
// End of IMU Reset procedure
while(true)
{
res = lsm6dsl_device_id_get(&IMU_Ctx, ®.byte);
if (res == WICED_SUCCESS)
{
if(reg.byte == LSM6DSL_ID)
{
IMU_LOG_INFO_MSG("LSM6DSL found. Device id=0x%X\n", reg.byte);
break;
}
else
{
wiced_rtos_delay_milliseconds(1000);
}
}
else
{
IMU_LOG_ERROR_MSG("lsm6dsl_device_id_get failed\n");
return;
}
};
//maybe this line not needed
// 1st disable I2C. See https://community.st.com/s/question/0D53W00000KqH8cSAF/connecting-two-sensors-to-the-same-spi-bus-possible-contention
//
res = lsm6dsl_i2c_interface_set(&IMU_Ctx, LSM6DSL_I2C_ENABLE);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_i2c_interface_set() error. Err=%d\n", res);
}
// Accelerometer
res = lsm6dsl_xl_full_scale_set(&IMU_Ctx, LSM6DSL_8g);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_xl_full_scale_set() error. Err=%d\n", res);
}
res = lsm6dsl_xl_power_mode_set(&IMU_Ctx, LSM6DSL_XL_NORMAL);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_xl_power_mode_set() error. Err=%d\n", res);
}
// Gyro
res = lsm6dsl_gy_full_scale_set(&IMU_Ctx, LSM6DSL_2000dps);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_gy_full_scale_set() error. Err=%d\n", res);
}
res = lsm6dsl_gy_power_mode_set(&IMU_Ctx, LSM6DSL_GY_NORMAL);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_gy_power_mode_set() error. Err=%d\n", res);
}
// BDU
res = lsm6dsl_block_data_update_set(&IMU_Ctx, 1);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_block_data_update_set() error. Err=%d\n", res);
}
// DRDY Int2
res = lsm6dsl_data_ready_mode_set(&IMU_Ctx, LSM6DSL_DRDY_PULSED);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_data_ready_mode_set() error. Err=%d\n", res);
}
res = lsm6dsl_pin_int2_route_set(&IMU_Ctx, IMU_Intr2RouteAccOnly); // use INT2 as 'main' IMU irq
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_pin_int2_route_set() error. Err=%d\n", res);
}
// Pedometer
res = lsm6dsl_****_sens_set(&IMU_Ctx, 1); // Enable pedometer
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_****_sens_set() error. Err=%d\n", res);
}
res = lsm6dsl_****_step_reset_set(&IMU_Ctx, 1); // reset step counter
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_****_step_reset_set() error. Err=%d\n", res);
}
res = lsm6dsl_****_step_reset_set(&IMU_Ctx, 0); // reset step counter
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_****_step_reset_set() error. Err=%d\n", res);
}
// Set pedometer parameters
res = lsm6dsl_****_debounce_steps_set(&IMU_Ctx, IMU_PEDOEMETR_DEBOUNCE_STEPS_DEFAULT);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_****_debounce_steps_set() error. Err=%d\n", res);
}
res = lsm6dsl_****_timeout_set(&IMU_Ctx, IMU_PEDOMETER_DEBOUNCE_TIMEOUT_DEFAULT);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_****_timeout_set() error. Err=%d\n", res);
}
res = lsm6dsl_****_threshold_set(&IMU_Ctx, IMU_PEDOMETER_STEP_THD_DEFAULT);
if (res != WICED_SUCCESS)
{
IMU_LOG_ERROR_MSG("lsm6dsl_****_threshold_set() error. Err=%d\n", res);
}
IMU_isInitialized = true;
IMU_LOG_DEBUG_MSG("LSM6DSL setup completed successfully\n");
}
static void IMU_InitInterrupt(void)
{
IMU_LOG_DEBUG_MSG("IMU_InitInterrupt()\n");
// interrupt
wiced_gpio_init(IMU_INT1_GPIO, INPUT_HIGH_IMPEDANCE);
wiced_gpio_init(IMU_INT2_GPIO, INPUT_HIGH_IMPEDANCE);
wiced_gpio_input_irq_enable(IMU_INT2_GPIO, IRQ_TRIGGER_RISING_EDGE, IMU_Int2Handler, NULL);
wiced_gpio_input_irq_enable(IMU_INT1_GPIO, IRQ_TRIGGER_RISING_EDGE, IMU_Int1Handler, NULL);
}
In setup function did power_off,
The power on call when all system is power on(wake up)
BR
Harel