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

【STEVAL-STWINKT1B】:04读取STTS751温度

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

一:STTS751温度模块基础知识

STTS751是一款数字温度传感器,可通过兼容2线式SMBus2.0总线进行通信。该传感器能够以用户可配置的分辨率进行温度测量,分辨率范围介于9至12比特之间。在9比特模式下,最小步长为0.5°C,而在12比特模式下则为0.0625°C。在默认分辨率(10比特,0.25°C/LSB)下,转换时间大约为21毫秒。

这种开漏式EVENT输出功能用于指示一种报警状态,即所测量的温度已超出用户预设的高限或跌至低限以下。当EVENT引脚被激活时,主机可通过使用SMBus警报响应地址(ARA)协议进行响应,而STTS751则会通过发送其从机地址来做出回应。

STTS751是一款6针设备,支持用户可配置的从站地址。通过位于Addr/Therm引脚上的上拉电阻器,可以指定四种不同的从站地址之一。两个订货号(STTS751-0和STTS751-1)提供了两套不同的从站地址,使总可用数量增至八种。如此一来,最多可达八种设备可共享同一根2线SMBus信号线而不会产生歧义,从而便于对应用中的多个温度区域进行监测。两线接口可支持高达400kHz的传输速率。

二:软件代码:**

2.1 初始化函数

  stmdev_ctx_t dev_ctx;
  dev_ctx.write_reg = platform_write;
  dev_ctx.read_reg = platform_read;
//  dev_ctx.mdelay = platform_delay;
  dev_ctx.handle = &SENSOR_BUS;
  /* Initialize platform specific hardware */
  platform_init();
  /* Check device ID */
  stts751_device_id_get(&dev_ctx, &whoamI);

  if ( (whoamI.product_id != STTS751_ID_0xxxx) ||
       //(whoamI.product_id != STTS751_ID_1xxxx) ||
       (whoamI.manufacturer_id != STTS751_ID_MAN) ||
       (whoamI.revision_id != STTS751_REV) )
    while (1); /* manage here device not found */

  /* Enable interrupt on high(=49.5 degC)/low(=-4.5 degC) temperature. */
  float_t temperature_high_limit = 49.5f;
  stts751_high_temperature_threshold_set(&dev_ctx,
                                         stts751_from_celsius_to_lsb(temperature_high_limit));
  float_t temperature_low_limit = -4.5f;
  stts751_low_temperature_threshold_set(&dev_ctx,
                                        stts751_from_celsius_to_lsb(temperature_low_limit));
  stts751_pin_event_route_set(&dev_ctx,  PROPERTY_ENABLE);
  /* Set Output Data Rate */
  stts751_temp_data_rate_set(&dev_ctx, STTS751_TEMP_ODR_1Hz);
  /* Set Resolution */
  stts751_resolution_set(&dev_ctx, STTS751_11bit);

2.2在100ms或者是其他时间任务中,添加对数据的读取

    uint8_t flag;
                HAL_Delay(200);
    stts751_flag_busy_get(&dev_ctx, &flag);

    if (flag) {
      /* Read temperature data */
      memset(&data_raw_temperature, 0, sizeof(int16_t));
      stts751_temperature_raw_get(&dev_ctx, &data_raw_temperature);
      temperature_degC = stts751_from_lsb_to_celsius(
                           data_raw_temperature);
      snprintf((char *)tx_buffer, sizeof(tx_buffer), "ST-STTS751 Temperature [degC]:%3.2f°C\r\n",
              temperature_degC);
      tx_com(tx_buffer, strlen((char const *)tx_buffer));

三:串口数据截图如下所示:

03-2.png

收藏 评论0 发布时间:2026-3-30 13:02

举报

0个回答

所属标签

相似分享

官网相关资源

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