2025-09-21 1:34 PM
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);
}
}
}