你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STEVAL-STWINKT1B】:03读取HTS221温湿度

[复制链接]
〃聪聪哥哥 发布时间:2026-3-30 11:22

一:HTS221温湿度

HTS221是意法半导体推出的一款超紧凑型数字温湿度传感器,它集成了16位ADC和数字接口,能直接将物理信号转换为数字量输出

HTS221是一款超小型的相对湿度和温度传感器。它包含一个传感元件以及一个混合信号专用集成电路(ASIC),能够通过数字串行接口提供测量信息。

传感元件由一种能够检测相对湿度变化的聚合物介电平面电容器结构组成,并采用专用的ST工艺制造。

HTS221提供小型顶部开孔的贴片网格阵列(HLGA)封装,保证在-40°C至+120°C温度范围内工作。

特点:

0至100%相对湿度范围

供电电压:1.7至3.6V

低功耗:2安培@1赫兹ODR可选ODR

从1Hz到12.5 Hz高相对湿度

灵敏度:0.004%rH/LSB

湿度精度:+3.5%rH,20至+80%rH

温度精度:+0.5°C,15至+40°C

嵌入式16位ADC

16位湿度和温度输出数据

SPI和I2C接口

工厂校准

小巧的2x2x0.9mm封装

标准符合ECOPACK环保包装

二:STM32 cube MX软件配置:

03-3cubeMX配置图.png

三:软件实现过程

3.1 初始化过程:

void hts221_init( void )
{
  /* Initialize platform specific hardware */
  platform_init();
  /* Initialize mems driver interface */
  hts221_dev_ctx.write_reg = platform_write;
  hts221_dev_ctx.read_reg = platform_read;
//  hts221_dev_ctx.mdelay = platform_delay;
  hts221_dev_ctx.handle = &SENSOR_BUS;
  /* Check device ID */
  whoamI = 0;
  hts221_device_id_get(&hts221_dev_ctx, &whoamI);

  if ( whoamI != HTS221_ID )
    while (1); /*manage here device not found */

  /* Read humidity calibration coefficient */

  hts221_hum_adc_point_0_get(&hts221_dev_ctx, &lin_hum.x0);
  hts221_hum_rh_point_0_get(&hts221_dev_ctx, &lin_hum.y0);
  hts221_hum_adc_point_1_get(&hts221_dev_ctx, &lin_hum.x1);
  hts221_hum_rh_point_1_get(&hts221_dev_ctx, &lin_hum.y1);
  /* Read temperature calibration coefficient */

  hts221_temp_adc_point_0_get(&hts221_dev_ctx, &lin_temp.x0);
  hts221_temp_deg_point_0_get(&hts221_dev_ctx, &lin_temp.y0);
  hts221_temp_adc_point_1_get(&hts221_dev_ctx, &lin_temp.x1);
  hts221_temp_deg_point_1_get(&hts221_dev_ctx, &lin_temp.y1);
  /* Enable Block Data Update */
  hts221_block_data_update_set(&hts221_dev_ctx, PROPERTY_ENABLE);
  /* Set Output Data Rate */
  hts221_data_rate_set(&hts221_dev_ctx, HTS221_ODR_1Hz);
  /* Device power on */
  hts221_power_on_set(&hts221_dev_ctx, PROPERTY_ENABLE);
}

3.2 采用轮询读取的方式进行数据采集:

void hts221_read_data_polling(void)
{
    /* Read samples in polling mode */
  /* Read output only if new value is available */
  hts221_reg_t reg;

  hts221_status_get(&hts221_dev_ctx, ®.status_reg);

  if (reg.status_reg.h_da) 
                {
    /* Read humidity data */
                        memset(&data_raw_humidity, 0x00, sizeof(int16_t));

                        hts221_humidity_raw_get(&hts221_dev_ctx, &data_raw_humidity);

                        humidity_perc = linear_interpolation(&lin_hum, data_raw_humidity);
                        sprintf((char *)tx_buffer, "ST-HTS221 HumiData [%%]:%3.2f\r\n", humidity_perc);
                        tx_com( tx_buffer, strlen( (char const *)tx_buffer ) );
  }

  if (reg.status_reg.t_da) {
    /* Read temperature data */
    memset(&data_raw_temperature, 0x00, sizeof(int16_t));
    hts221_temperature_raw_get(&hts221_dev_ctx, &data_raw_temperature);
    temperature_degC = linear_interpolation(&lin_temp,
                                            data_raw_temperature);
    sprintf((char *)tx_buffer, "ST-HTS221 Temperature [degC]:%6.2f\r\n",
            temperature_degC );
    tx_com( tx_buffer, strlen( (char const *)tx_buffer ) );
  }
}

四:串口数据采集数据如下所示:

03-1.png

03-1.png
收藏 评论0 发布时间:2026-3-30 11:22

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版