基于STM32CUBEMX驱动TMOS模块STHS34PF80(4)----中断获取信号

概述hs34pf80的数据准备信号提供了一种机制,允许设备在新的测量数据可读取时通知系统,并触发同步操作,通过正确配置相关寄存器,可以确保系统及时捕获和处理来自设备的新数据,从而提高整体性能和响应能力。
检测人体的存在和动作,并通过特定的通信接口发送检测结果。
最近在弄st和瑞萨ra的课程,需要样片的可以加群申请:615061293 。
样品申请https://www.wjx.top/vm/ohckxjk.aspx#
视频教程https://www.bilibili.com/video/bv1nf41117s6/
参考demohttps://github.com/stmicroelectronics/stmems_standard_c_drivers/blob/master/sths34pf80_stdc/examples/sths34pf80_tmos_data_polling.c
完整代码下载https://download.csdn.net/download/qq_24312945/88219177
参考程序中断
中断生成sths34pf80具有一个可配置的内置中断生成块,允许基于温度数据样本和嵌入式智能数字算法的输出标志生成中断事件。
sths34pf80提供了一个专门的int引脚,用于通知数据是否准备好。您可以通过配置相关寄存器,将数据准备好的信号(drdy信号)路由到这个int引脚。当新的测量数据可读取时,这个引脚会被触发,从而允许系统知道数据已经准备好并可供进一步的处理和读取。
设置中断设置中断可以通过ctrl3 (22h)寄存器来配置。
这个寄存器为系统提供了有关设备当前状态的关键信息,可以用于驱动其他逻辑或触发相应的操作,如中断服务例程。例如,pres_flag可用于确定是否有人进入了一个区域,mot_flag可以用于检测人体是否运动,tamb_shock_flag可能用于环境监控系统以捕捉突然的温度变化。
通过查看func_status (25h)可以得知,pres_flag为存在检测,mot_flag为运动检测,tamb_shock_flag为环境温度冲击检测标志。
开启存在检测中断输出sths34pf80_tmos_int_or_set 的主要目的是配置sths34pf80设备的中断输出。它是用于设置和管理中断标志,其中sths34pf80_tmos_int_presence为0x4,就是使能int_msk2为1,开启pres_flag存在检测。
/* set interrupt */ sths34pf80_tmos_int_or_set(sths34pf80_address, sths34pf80_tmos_int_presence);具体操作函数如下所示。
/** * @brief selects interrupts output.[set] * * @param ctx read / write interface definitions * @param val tmos_int_none, tmos_int_tshock, tmos_int_motion, tmos_int_tshock_motion, tmos_int_presence, tmos_int_tshock_presence, tmos_int_motion_presence, tmos_int_all, * @retval interface status (mandatory: return 0 - > no error) * */uint8_t sths34pf80_tmos_int_or_set(uint8_t add, sths34pf80_tmos_int_or_t val){ sths34pf80_ctrl3_t ctrl3; int32_t ret; ret = sths34pf80_read_reg(add, sths34pf80_ctrl3, (uint8_t *)&ctrl3, 1); if (ret == hal_ok) { ctrl3.int_msk = ((uint8_t)val & 0x7u); ret = sths34pf80_write_reg(add, sths34pf80_ctrl3, (uint8_t *)&ctrl3, 1); } return ret;}配置中断管脚通过配置ctrl3 (22h)寄存器的ien[1:0] 可以设置输出模式。
ien[1:0]位在ctrl3寄存器中,它定义了应该将哪种信号路由到int管脚(即中断输出):
00:int管脚处于高阻态。
01:将drdy(数据已准备好的信号)路由到int管脚。
10:将int_or信号路由到int管脚。
这里通过将ctrl3(22h)寄存器的ien[1:0]位范围设置为10,可以将status(23h)寄存器的drdy位的值驱动到int引脚,操作如下所示。
sths34pf80_tmos_route_int_set(sths34pf80_address, sths34pf80_tmos_int_or);具体的操作函数如下所示。这个函数基本上对应之前提到的ien[1:0]位的功能,它允许用户选择要路由到中断输出管脚的特定中断信号。
/** * @defgroup interrupt pins * @brief interrupt pins * @{/ * *//** * @brief selects interrupts to be routed.[set] * * @param ctx read / write interface definitions * @param val tmos_int_hiz, tmos_int_drdy, tmos_int_or, * @retval interface status (mandatory: return 0 - > no error) * */uint8_t sths34pf80_tmos_route_int_set(uint8_t add, sths34pf80_tmos_route_int_t val){ sths34pf80_ctrl3_t ctrl3; int32_t ret; ret = sths34pf80_read_reg(add, sths34pf80_ctrl3, (uint8_t *)&ctrl3, 1); if (ret == hal_ok) { ctrl3.ien = ((uint8_t)val & 0x3u); if (val == sths34pf80_tmos_int_or) { ctrl3.int_latched = 0; /* guarantee that latched is zero in int_or case */ } ret = sths34pf80_write_reg(add, sths34pf80_ctrl3, (uint8_t *)&ctrl3, 1); } return ret;}主程序初始化如下。
/* user code begin 2 */ sths34pf80_lpf_bandwidth_t lpf_m, lpf_p, lpf_p_m, lpf_a_t; sths34pf80_tmos_drdy_status_t status; sths34pf80_tmos_func_status_t func_status; hal_delay(200); printf(123); uint8_t sths34pf80_id =sths34pf80_getchipid(sths34pf80_address); printf(sths34pf80_id=0x%xn,sths34pf80_id); if (sths34pf80_id != 0xd3) while(1);/* set averages (avg_tamb = 8, avg_tmos = 32) */ sths34pf80_avg_tobject_num_set(sths34pf80_address, sths34pf80_avg_tmos_32); sths34pf80_avg_tambient_num_set(sths34pf80_address, sths34pf80_avg_t_8); /* read filters */ sths34pf80_lpf_m_bandwidth_get(sths34pf80_address, &lpf_m); sths34pf80_lpf_p_bandwidth_get(sths34pf80_address, &lpf_p); sths34pf80_lpf_p_m_bandwidth_get(sths34pf80_address, &lpf_p_m); sths34pf80_lpf_a_t_bandwidth_get(sths34pf80_address, &lpf_a_t);printf(lpf_m: %02d, lpf_p: %02d, lpf_p_m: %02d, lpf_a_t: %02drn, lpf_m, lpf_p, lpf_p_m, lpf_a_t); /* set bdu */ sths34pf80_block_data_update_set(sths34pf80_address, 1); sths34pf80_tmos_route_int_set(sths34pf80_address, sths34pf80_tmos_int_or); sths34pf80_presence_threshold_set(sths34pf80_address, 20); //设置存在阈值。 sths34pf80_presence_hysteresis_set(sths34pf80_address, 2);//“存在滞后”(presence hysteresis)的函数 sths34pf80_motion_threshold_set(sths34pf80_address, 30);//设置动作阈值 sths34pf80_motion_hysteresis_set(sths34pf80_address, 3); ////动作滞后”(motion hysteresis)的函数 /* set interrupt */ sths34pf80_tmos_int_or_set(sths34pf80_address, sths34pf80_tmos_int_presence); sths34pf80_tmos_route_int_set(sths34pf80_address, sths34pf80_tmos_int_or); /* set odr */ sths34pf80_tmos_odr_set(sths34pf80_address, sths34pf80_tmos_odr_at_30hz); int32_t cnt = 0; /* user code end 2 */main函数如下所示。
/* infinite loop */ /* user code begin while */ while (1) {// sths34pf80_tmos_drdy_status_get(sths34pf80_address, &status);// if (status.drdy)// {// sths34pf80_tmos_func_status_get(sths34pf80_address, &func_status);// printf(-- >环境温度冲击检测标志位 %d - 存在检测标志位 %d - 运动检测标志位 %drn,func_status.tamb_shock_flag, func_status.pres_flag, func_status.mot_flag);// } printf(pa7=%d,hal_gpio_readpin ( gpioa, gpio_pin_7)); sths34pf80_tmos_func_status_t func_status; uint8_t motion; uint8_t presence; /* handle event in a thread alike code */ if(hal_gpio_readpin ( gpioa, gpio_pin_7)) { motion = 0; presence = 0; do { sths34pf80_tmos_func_status_get(sths34pf80_address, &func_status); if (func_status.pres_flag != presence) { presence = func_status.pres_flag; if (presence) { printf(start of presencern); } else { printf(end of presencern); } } if (func_status.mot_flag != motion) { motion = func_status.mot_flag; if (motion) { printf(motion detected!rn); } } } while (func_status.pres_flag); } hal_delay(1000); /* user code end while */ /* user code begin 3 */ } /* user code end 3 */测试结果在未有人的情况下。
在人体纯在情况下。


澳大利亚国立大学开发出一种“量子透镜”
免费WiFi风潮来袭,你享受到了吗?
耐压测试交流与直流之区别
小米5C真机谍照大曝光:全玻璃机身指纹解锁 堪称史上最美小米
一加手机2拆解 给人一种很扎实的感觉
基于STM32CUBEMX驱动TMOS模块STHS34PF80(4)----中断获取信号
英特尔陷困境,将推出新款芯片,是否能改变局面?
鲲鹏应用创新大赛2022在南宁圆满举行
机器学习该怎么学习
新型DSP基站设备超越LTE需求
3W-International两冲程发动机SP-28CR介绍
CES中Google把语音助手搞砸 将不大可能超过Amazon Alexa
LED二次封装是怎样进行的?有什么优势?
联发科CEO:明年将优于今年
中国电信打造5G、云﹢AI的应用创新方案研究和测试验证平台
硬件开发的基本过程
未来柔性机器人发展趋势分析
基于ARM的毫米波天线自动对准平台系统设计
结构中开孔孔口应力集中问题详解
C++创造者:成功属于意料之外