cancel
Showing results for 
Search instead for 
Did you mean: 

sths34pf80 does not work

Lilly123
Associate

Hi,

I am evaluating sths34pf80 but unfortuantely I am not able to make it work. I am referiing to the code in the github 
https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/sths34pf80_STdC

The below code is from example sths34pf80_tmos_presence_detection.

 
  /* Wait sensor boot time */
  platform_delay(BOOT_TIME);

  /* Check device ID */
  sths34pf80_device_id_get(&dev_ctx, &whoami);
  if (whoami != STHS34PF80_ID)
    while (1);

  /* Set averages (AVG_TAMB = 8, AVG_TMOS = 32) */
  sths34pf80_avg_tobject_num_set(&dev_ctx, STHS34PF80_AVG_TMOS_32);
  sths34pf80_avg_tambient_num_set(&dev_ctx, STHS34PF80_AVG_T_8);

  /* read filters */
  sths34pf80_lpf_m_bandwidth_get(&dev_ctx, &lpf_m);
  sths34pf80_lpf_p_bandwidth_get(&dev_ctx, &lpf_p);
  sths34pf80_lpf_p_m_bandwidth_get(&dev_ctx, &lpf_p_m);
  sths34pf80_lpf_a_t_bandwidth_get(&dev_ctx, &lpf_a_t);

  snprintf((char *)tx_buffer, sizeof(tx_buffer),
           "lpf_m: %02d, lpf_p: %02d, lpf_p_m: %02d, lpf_a_t: %02d\r\n", lpf_m, lpf_p, lpf_p_m, lpf_a_t);
  tx_com(tx_buffer, strlen((char const *)tx_buffer));

  /* Set BDU */
  sths34pf80_block_data_update_set(&dev_ctx, 1);

  sths34pf80_presence_threshold_set(&dev_ctx, 200);
  sths34pf80_presence_hysteresis_set(&dev_ctx, 20);
  sths34pf80_motion_threshold_set(&dev_ctx, 300);
  sths34pf80_motion_hysteresis_set(&dev_ctx, 30);

  sths34pf80_algo_reset(&dev_ctx);

  /* Set interrupt */
  sths34pf80_int_or_set(&dev_ctx, STHS34PF80_INT_PRESENCE);
  sths34pf80_route_int_set(&dev_ctx, STHS34PF80_INT_OR);

  /* Set ODR */
  sths34pf80_odr_set(&dev_ctx, STHS34PF80_ODR_AT_4Hz);

  /* Presence event detected in irq handler */
  while (1)
  {
    sths34pf80_func_status_t func_status;
    uint8_t motion;
    uint8_t presence;

    /* handle event in a "thread" alike code */
    if (1)
    {
      wakeup_thread = 0;
      motion = 0;
      presence = 0;

      do
      {
        sths34pf80_func_status_get(&dev_ctx, &func_status);

        if (func_status.pres_flag != presence)
        {
          presence = func_status.pres_flag;

          if (presence)
          {
            snprintf((char *)tx_buffer, sizeof(tx_buffer), "Start of Presence\r\n");
            tx_com(tx_buffer, strlen((char const *)tx_buffer));
          }
          else
          {
            snprintf((char *)tx_buffer, sizeof(tx_buffer), "End of Presence\r\n");
            tx_com(tx_buffer, strlen((char const *)tx_buffer));
          }
        }

        if (func_status.mot_flag != motion)
        {
          motion = func_status.mot_flag;

          if (motion)
          {
            snprintf((char *)tx_buffer, sizeof(tx_buffer), "Motion Detected!\r\n");
            tx_com(tx_buffer, strlen((char const *)tx_buffer));
          }
        }
      } while (func_status.pres_flag);
    }
  }
}
 
I can read the Device ID correctly and all the I²C transactions are working. For now, I’m not using interrupts, so I modified line 41 accordingly. I also changed line 38 to set the ODR as STHS34PF80_ODR_AT_4Hz, because sths34pf80_odr_set() fails when I use STHS34PF80_ODR_AT_30Hz.

I am expecting the breakpoints to hit  line number 60 or line number 76 when I bring my hand closer to the sensor but it does not. Can you please help me get this working? I am using STEVAL-MKI231KA.
1 REPLY 1
Federica Bossi
ST Employee

Hi @Lilly123 ,

Could you log the Tobject and see if it changes when you put your hand near the sensor?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.