主页 > 互联网 > 内容页

当前焦点!英飞凌PSC62 低功耗温湿度数据采集

2023-05-30 09:11:07 来源:华仔的编程随笔


(资料图片)

目的

驱动hs3003温湿度传感器,采集完数据后进入深度睡眠模式,以达到节能的目的。

实现步聚

1、打开rtthreadsettings, 添加hs300x模块:

2、添加初始化代码:

#define HS300X_I2C_BUS  "i2c1"int rt_hw_hs300x_port(void){    struct rt_sensor_config cfg;    cfg.intf.dev_name  = HS300X_I2C_BUS;    cfg.intf.user_data = (void *)HS300X_I2C_ADDR;    rt_hw_hs300x_init("hs300x", &cfg);    return RT_EOK;}INIT_ENV_EXPORT(rt_hw_hs300x_port);

3、修改主程序代码如下:

#include #include #include "sensor_renesas_hs300x.h"#include "drv_gpio.h"#define LED_PIN     GET_PIN(0, 0)#define USE_SECONDS_FOR_ALARM30#define LONG_GLITCH_DELAY_MS        100u    /* in ms */#define RTC_INTERRUPT_PRIORITY      3uvoid set_rtc_alarm_date_time(void);cyhal_rtc_t rtc_obj;extern struct hs300x_device temp_humi_dev;int main(void){    cy_rslt_t result;    float temp_f, humi_f;    __enable_irq();    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);    rt_thread_mdelay(500);    /* Initialize RTC */    cyhal_rtc_enable_event(&rtc_obj, CYHAL_RTC_ALARM, RTC_INTERRUPT_PRIORITY, true);    for (;;)    {        rt_kprintf("Go to DeepSleep mode\\r\\n");        set_rtc_alarm_date_time();        cyhal_system_delay_ms(LONG_GLITCH_DELAY_MS);//        /* Go to deep sleep */        cyhal_syspm_deepsleep();        rt_kprintf("Wakeup from DeepSleep mode\\r\\n");        hs300x_read_data(&temp_humi_dev, &humi_f, &temp_f);//        /* Set the RTC generate alarm after 10 seconds */        rt_kprintf("Temp:%2d.%df, Humi:%2d%%\\r\\n",(int)temp_f,(int)(temp_f*10)%10, (int)humi_f);    }}

实验效果

[I/I2C] I2C bus [i2c1] registered \\ | /- RT -     Thread Operating System / | \\     4.1.1 build May 28 2023 12:08:51 2006 - 2022 Copyright by RT-Threadteam[D/drv.rtc] rtc init success[D/drv.rtc] RTC: get rtc_time 946684800[D/drv.rtc] RTC: get rtc_time 946684800[D/drv.rtc] RTC: get rtc_time 946684800[I/sensor] rt_sensor[temp_hs300x] init success[I/sensor] rt_sensor[humi_hs300x] init successmsh >Go to DeepSleep modeWakeup from DeepSleep modeTemp:29.6f, Humi:77%Go to DeepSleep mode

电流表测试深度睡眠相比休眠模式少15MA左右,因为板载的DAP等其他元件在用电,所以还不能测试出来工作电路的电流情况。审核编辑:汤梓红

标签:

上一篇:中国铝业(601600)5月29日主力资金净卖出894.74万元
下一篇:最后一页