Hello community,
my sths34pf80 is connected with a wireless MCU through I2C in fast mode.
during the initial process the function " sths34pf80_presence_threshold_set(&presenceHandle, 200); " is called, sometimes there is no problem, the sths34pf80 can be successfully initialized, it can detect presence and motion.
But it also happens oft: if the ctrl1.odr is 8, then it hangs by excuting sths34pf80_odr_safe_set
(if ctrl.odr is 0, the initial will be successful.)
int32_t sths34pf80_presence_threshold_set(const sths34pf80_ctx_t *ctx, uint16_t val)
{
sths34pf80_ctrl1_t ctrl1;
uint8_t odr;
uint8_t buff[2];
int32_t ret;
if ((val & 0x8000U) != 0x0U) {
/* threshold values are on 15 bits */
return -1;
}
/* Save current odr and enter PD mode */
ret = sths34pf80_read_reg(ctx, STHS34PF80_CTRL1, (uint8_t *)&ctrl1, 1);
odr = ctrl1.odr;
printf("threshold set...1:%d\n", odr);
ret += sths34pf80_odr_safe_set(ctx, ctrl1, 0);
buff[1] = (uint8_t)(val / 256U);
buff[0] = (uint8_t)(val - (buff[1] * 256U));
ret += sths34pf80_func_cfg_write(ctx, STHS34PF80_PRESENCE_THS, &buff[0], 2);
ret += sths34pf80_algo_reset(ctx);
/* Set saved odr back */
printf("threshold set...2:%d\n", ret);
ret += sths34pf80_odr_safe_set(ctx, ctrl1, odr);
printf("threshold set...3:%d\n", ret);
return ret;
}
here is the output from the console:

Here is the signal on SCL and SDA:
