Files
ETH_TCP_Demo/app/sht40.h

35 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* SHT40 温湿度传感器驱动
* 功能通过I2C1读取SHT40传感器的温湿度数据
* 依赖STM32 HAL库
* 跨平台仅适用于STM32F4系列使用HAL库的I2C接口
*/
#ifndef __SHT40_H__
#define __SHT40_H__
#include <stdint.h>
#include "stm32f4xx_hal.h"
/* SHT40 I2C地址 */
#define SHT40_I2C_ADDR 0x44
/* SHT40命令 */
#define SHT40_CMD_MEASURE_HIGH_PRECISION 0xFD // 高精度测量(高重复性)
#define SHT40_CMD_MEASURE_MED_PRECISION 0xF6 // 中精度测量(中重复性)
#define SHT40_CMD_MEASURE_LOW_PRECISION 0xE0 // 低精度测量(低重复性)
#define SHT40_CMD_RESET 0x89 // 软复位
#define SHT40_CMD_READ_SERIAL 0x00 // 读取序列号
#define SHT40_CMD_HEATER_HIGH 0x94 // 加热器开启高功率200mW
#define SHT40_CMD_HEATER_MED 0x91 // 加热器开启中功率110mW
#define SHT40_CMD_HEATER_LOW 0x8D // 加热器开启低功率20mW
/* 函数声明 */
int sht40_init(void);
int sht40_read_temperature_humidity(float *temperature, float *humidity);
int sht40_read_temperature_humidity_with_precision(float *temperature, float *humidity, uint8_t precision);
int sht40_reset(void);
int sht40_read_serial(uint32_t *serial);
int sht40_heater_enable(uint8_t power_level);
#endif