Skip to main content
Explorer II
January 26, 2024
Solved

STHS34PF80 threshold set

  • January 26, 2024
  • 5 replies
  • 2335 views

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:
Danny0007_0-1706307943338.png

Here is the signal on SCL and SDA:

Danny0007_1-1706308318480.png

 

    This topic has been closed for replies.
    Best answer by Federica Bossi

    Hi @Danny0007 ,

    Here is the link: https://github.com/STMicroelectronics/sths34pf80-pid

    Let me know if you solve.

    5 replies

    Danny0007Author
    Explorer II
    January 27, 2024
    after removing the last odr safe set function, everything works fine.
    could someone confirm if this is really necessary, if not, I will remove it forever in my code.  
    //ret += sths34pf80_odr_safe_set(ctx, ctrl1, odr);
    Technical Moderator
    February 2, 2024

    Hi @Danny0007 ,

    This has been fixed in the last driver version that you find here.

    Let me know if everything is ok without your workaround that we don't suggest. Thanks :)

    Danny0007Author
    Explorer II
    February 2, 2024

    Hi @Federica Bossi 

    thanks for reply.

    I tested the new release, it´s better than before, but still not perfect, because every time after I pressed reset, one time can be correctly initialised, the other time is still hanged at this function: sths34pf80_odr_safe_set(ctx, ctrl1, odr); 

    so only half of time is working. before maybe less.

    Danny0007_0-1706907004094.png

    and if I remove this line, everything works fine again... it´s my old workaroud, but not suggested.

     

     

    Technical Moderator
    February 7, 2024

    Hi @Danny0007 ,

    Thanks for noticed us this issue, we fixed it in the new version. Could you try to use it and let me know if everything works fine?

    Also remember to add the callback to mdelay in the platform:
    /* Initialize mems driver interface */
    dev_ctx.write_reg = platform_write;
    dev_ctx.read_reg = platform_read;
    dev_ctx.mdelay = platform_delay;
    dev_ctx.handle = &SENSOR_BUS;

    Danny0007Author
    Explorer II
    February 7, 2024

    Hi @Federica Bossi 

    I added the mdelay and tested it, but for me it´s the same old.
    here is my function:

    Danny0007_1-1707339819330.png

     

     

    Technical Moderator
    February 8, 2024

    Hi @Danny0007 ,

     

    Have you updated the STHS34PF80 to the latest commit fe9905f3?

    Danny0007Author
    Explorer II
    February 8, 2024

    Hi @Federica Bossi 

    could you give me a direct link? which repo do you mean?

    Technical Moderator
    February 9, 2024

    Hi @Danny0007 ,

    Here is the link: https://github.com/STMicroelectronics/sths34pf80-pid

    Let me know if you solve.

    Danny0007Author
    Explorer II
    February 9, 2024

    Hi @Federica Bossi 

    Yes, it´s fixed! works fine after every reset.

    Thanks a lot!:thumbs_up: