2022-10-27 02:04 AM
Hi,
Because of internal pullups on several st accs I changed it with this acc and, now I have a problem with sleep-state or sleep-state-ia bits in wake_up_src or state or state_dup regisers. This bits after the sleep duration doesn't give a response or gives unstable response which I couldn't understand. I tried directly same codes on github also on application note and also with my settings but results are the same. Example init sequence is below.
void acc_init_sequence(void)
{
lis2ds12_pin_int1_route_t int1_route;
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.handle = SPI1;
systick_delay_ms(k_BOOT_TIME);
lis2ds12_device_id_get(&dev_ctx, &whoamI);
if (whoamI != LIS2DS12_ID)
while (1);
/* Restore default configuration */
lis2ds12_reset_set(&dev_ctx, PROPERTY_ENABLE);
do
{
lis2ds12_reset_get(&dev_ctx, &rst);
} while (rst);
// /* Start device configuration. */
// lis2ds12_i2c_interface_set(&dev_ctx, LIS2DS12_I2C_DISABLE);
// lis2ds12_spi_mode_set(&dev_ctx, LIS2DS12_SPI_4_WIRE);
// lis2ds12_cs_mode_set(&dev_ctx, LIS2DS12_PULL_UP_DISCONNECTED);
// lis2ds12_sh_pin_mode_set(&dev_ctx, LIS2DS12_EXT_PULL_UP);
// lis2ds12_pin_mode_set(&dev_ctx, LIS2DS12_PUSH_PULL);
// lis2ds12_xl_data_rate_set(&dev_ctx, LIS2DS12_XL_ODR_200Hz_LP);
// lis2ds12_xl_full_scale_set(&dev_ctx, LIS2DS12_2g);
////
// lis2ds12_sleep_mode_set(&dev_ctx, PROPERTY_ENABLE);
//
// /*
// 1 LSB = 1/ODR
// */
// lis2ds12_wkup_dur_set(&dev_ctx, 0); // 1 * (1/ODR) = 40 ms
// /*
// Default value is SLEEP_ DUR[3:0] = 0000 (which is 16/ODR)
// 1 LSB = 512/ODR
// */
// lis2ds12_act_sleep_dur_set(&dev_ctx, 1); // 16*/ODR = 160 ms ---- 512/ODR
// /*
// LSB = FS/64 of FS
// */
// lis2ds12_wkup_threshold_set(&dev_ctx, 10); // 8*(FS/64) = (250 mg )-( 10 312.5mg ) - (18 - 500mg)
// uint8_t data = 0xC0;
// lis2ds12_write_reg(&dev_ctx, LIS2DS12_CTRL1, &data, 1);
// data = 0x01; // pull-up disconnected on CS
// lis2ds12_write_reg(&dev_ctx, LIS2DS12_FIFO_CTRL, &data, 1);
// data = 0x00; // pull-up disconnected on I2C
// lis2ds12_write_reg(&dev_ctx, LIS2DS12_FUNC_CTRL, &data, 1);
// data = 0x4A; // sleep inactivity enable | 312.5 mg
// lis2ds12_write_reg(&dev_ctx, LIS2DS12_WAKE_UP_THS, &data, 1);
// data = 0x41; // 20ms wake-up dur | 5.12 sec sleep duration
// lis2ds12_write_reg(&dev_ctx, LIS2DS12_WAKE_UP_DUR, &data, 1);
// data = 0x20; // route wake-up event int1
// lis2ds12_write_reg(&dev_ctx, LIS2DS12_CTRL4, &data, 1);
uint8_t data = 0x50;
lis2ds12_write_reg(&dev_ctx, LIS2DS12_CTRL1, &data, 1);
data = 0x42;
lis2ds12_write_reg(&dev_ctx, LIS2DS12_WAKE_UP_DUR, &data, 1);
lis2ds12_write_reg(&dev_ctx, LIS2DS12_WAKE_UP_THS, &data, 1);
data = 0x20;
lis2ds12_write_reg(&dev_ctx, LIS2DS12_CTRL4, &data, 1);
// lis2ds12_pin_int1_route_get(&dev_ctx, &int1_route);
// int1_route.int1_wu = PROPERTY_ENABLE;
// lis2ds12_pin_int1_route_set(&dev_ctx, int1_route);
}