一: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));
三:串口数据截图如下所示:

|