温湿度传感器sht10程序
- 格式:doc
- 大小:11.50 KB
- 文档页数:1
Datasheet SHT1x (SHT10, SHT11, SHT15数字温湿度传感器• 完全标定• 数字信号输出• 低功耗• 卓越的长期稳定性• SMD 封装–适于回流焊接外形尺寸图 1 SHT1x 传感器尺寸(1mm=0.039inch,“ 11”表示该传感器型号为 SHT11。
外部接口:1:GND, 2: DATA, 3: SCK, 4: VDD传感器芯片此说明书适用于 SHT1x-V4。
SHT1x-V4 是第四代硅传感芯片,除了湿度、温度敏感元件以外,还包括一个放大器, A/D 转换器, OTP 内存和数字接口。
第四代传感器在其顶部印有产品批次号,以字母及数字表示,如“ A5Z ”,见图 1。
材质传感器的核心为 CMOS 芯片,外围材料顶层采用环氧 LCP ,底层为 FR4。
传感器符合 ROHS 和WEEE 标准,因此不含 Pb, Cd, Hg, Cr(6+, PBB, PBDE 。
实验包如要进行直接的传感器测量,传感器性能检验或者温湿度实验,客户可选用 EK-H2,其中包括传感器和与电脑配套的软、硬件。
如需进行更复杂的,要求更高的测量,可选用 EK-H3。
它可以同时进行 20个点的温湿度测量。
产品概述SHT1x (包括 SHT10, SHT11 和 SHT15 属于 Sensirion 温湿度传感器家族中的贴片封装系列。
传感器将传感元件和信号处理电路集成在一块微型电路板上,输出完全标定的数字信号。
传感器采用专利的 CMOSens® 技术,确保产品具有极高的可靠性与卓越的长期稳定性。
传感器包括一个电容性聚合体测湿敏感元件、一个用能隙材料制成的测温元件,并在同一芯片上,与 14 位的 A/D 转换器以及串行接口电路实现无缝连接。
因此,该产品具有品质卓越、响应迅速、抗干扰能力强、性价比高等优点。
每个传感器芯片都在极为精确的湿度腔室中进行标定,校准系数以程序形式储存在 OTP 内存中,用于内部的信号校准。
温湿度传感器SHT10驱动程序——基于MSP430这是暑假时用430的单片机写的温湿度传感器SHT10的程序,参考了官方的51例程,分享一下~~/****************************************Copyright(c)********************************************************************************************LiPeng********************* *************************************--------------FileInfo-------------------------------------------------------------------------------** File Name: Sht10_Driver.c** Created by: LiPeng** Created date: 2008-09-15** Version: 1.0** Descriptions: The original version****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Descriptions:****------------------------------------------------------------------------------------------------------** System Function: Sht10 Driver------温湿度传感器SHT10驱动** 使用MSP430-F413连接方式:** VCC: P6.3** SCK: P6.4** SDA: P6.5*********************************************************************** ***********************************/#include <msp430x14x.h>/*宏定义,延时函数,参数为1时相应延时分别为1us和1ms*/#define CPU_F (double)1000000#define delay_us(x) __delay_cycles((long)(CPU_F * (double)x/1000000.0)) #define delay_ms(x) __delay_cycles((long)(CPU_F * (double)x/1000.0))/*常量定义*/#define uint unsigned int#define uchar unsigned char#define ulong unsigned long//adr command r/w#define STATUS_REG_W 0x06 //000 0011 0#define STATUS_REG_R 0x07 //000 0011 1#define MEASURE_TEMP 0x03 //000 0001 1#define MEASURE_HUMI 0x05 //000 0010 1#define RESET 0x1e //000 1111 0#define bitselect 0x01 //选择温度与湿度的低位读#define noACK 0#define ACK 1#define HUMIDITY 2#define TEMPERATURE 1#define SCK BIT4#define SDA BIT5#define SVCC BIT3#define SCK_H P6OUT|=SCK#define SCK_L P6OUT&=~SCK#define SDA_H P6OUT|=SDA#define SDA_L P6OUT&=~SDA#define SVCC_H P6OUT|=SVCC#define SVCC_L P6OUT&=~SVCCtypedef union{unsigned int i;float f;}value;uint table_temp[3];uint table_humi[3];uint temten;uint humi_true;/******************************************************************** ****************************************Function Name: S_Init**Description: 初始化**Input Parameters: 无**Output Parameters: 无*************************************/void S_Init(){P6SEL&=~(SCK+SDA+SVCC); //选择P6.3 P6.4 为IO端口,输出 P6.5输入P6DIR|=(SCK+SVCC);P6DIR&=~SDA;BCSCTL1=(XT2OFF+RSEL2); //关闭XT2,1MHz DOCDCOCTL=DCO2; //设定DCO频率为1MHz}/******************************************************************** ****************************************Function Name: S_Transstart**Description: 发送开始时序**** generates a transmission start** _____ ________** DATA: |_______|** ___ ___** SCK : ___| |___| |______**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/void S_Transstart(){P6DIR|=SDA;SDA_H;SCK_L;_NOP();SCK_H;_NOP();SDA_L;_NOP();SCK_L;_NOP();_NOP();_NOP();SCK_H;_NOP();SDA_H;_NOP();SCK_L;P6DIR&=~SDA;}****************************************Function Name: S_WriteByte**Description: 写时序**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/char S_WriteByte(unsigned char value){unsigned char i,error=0;P6DIR|=SDA;for(i=0x80;i>0;i/=2) //shift bit for masking{if(i&value)SDA_H; //masking value with i , write to SENSI-BUSelseSDA_L;SCK_H; //clk for SENSI-BUS_NOP();_NOP();_NOP(); //pulswith approx. 5 usSCK_L;}SDA_H; //release DATA-lineP6DIR&=~SDA; //Change SDA to be inputSCK_H; //clk #9 for ackerror=P6IN; //check ack (DATA will be pulled down by SHT11)error&=SDA;P6DIR|=SDA;SCK_L;if(error)return 1; //error=1 in case of no acknowledgereturn 0;}/******************************************************************** ****************************************Function Name: S_ReadByte**Description: 读时序**Input Parameters: ack--->reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"**Output Parameters: 无********************************************************************* *************************************/char S_ReadByte(unsigned char ack){unsigned char i,val=0;P6DIR|=SDA;SDA_H; //release DATA-lineP6DIR&=~SDA;for(i=0x80;i>0;i/=2) //shift bit for masking{SCK_H; //clk for SENSI-BUSif(P6IN&SDA)val=(val|i); //read bitSCK_L;}P6DIR|=SDA;if(ack) //in case of "ack==1" pull down DATA-LineSDA_L;elseSDA_H;SCK_H; //clk #9 for ack_NOP();_NOP();_NOP(); //pulswith approx. 5 usSCK_L;SDA_H; //release DATA-lineP6DIR&=~SDA;return val;}/******************************************************************** ****************************************Function Name: S_Connectionreset**Description: 通讯复位时序** communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart** _____________________________________________________ ________** DATA: |_______|** _ _ _ _ _ _ _ _ _ ___ ___** SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ **Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/void S_Connectionreset(){unsigned char ClkCnt;P6DIR|=SDA;SDA_H;SCK_L; //Initial statefor(ClkCnt=0;ClkCnt<9;ClkCnt++) //9 SCK cycles{SCK_H;SCK_L;}S_Transstart(); //transmission start}/******************************************************************** ****************************************Function Name: S_Softreset**Description: 软件复位时序resets the sensor by a softreset**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/char S_Softreset(){unsigned char error=0;S_Connectionreset(); //reset communicationerror+=S_WriteByte(RESET); //send RESET-command to sensorreturn error; //error=1 in case of no response form the sensor}/******************************************************************** ****************************************Function Name: S_WriteStatusReg**Description: 写状态寄存器**Input Parameters: *p_value**Output Parameters: 无********************************************************************* *************************************/char S_WriteStatusReg(unsigned char *p_value){unsigned char error=0;S_Transstart(); //transmission starterror+=S_WriteByte(STATUS_REG_W); //send command to sensorerror+=S_WriteByte(*p_value); //send value of status registerreturn error; //error>=1 in case of no response form the sensor}/******************************************************************** ****************************************Function Name: S_Mearsure**Description: 读时序 makes a measurement (humidity/temperature) withchecksum**Input Parameters: *p_value ,*p_checknum ,mode**Output Parameters: 无********************************************************************* *************************************/unsigned char S_Measure(unsigned char *p_value, unsigned char*p_checksum, unsigned char mode){unsigned error=0;unsigned int i;S_Transstart(); //transmission startswitch(mode){ //send command to sensorcase TEMPERATURE: error+=S_WriteByte(MEASURE_TEMP); break;case HUMIDITY: error+=S_WriteByte(MEASURE_HUMI); break;}P6DIR&=~SDA;for(i=0;i<65535;i++) //wait until sensor has finished the measurement if((P6IN&SDA)==0)break;if(P6IN&SDA)error+=1; //or timeout (~2 sec.) is reached*(p_value)=S_ReadByte(ACK); //read the first byte (MSB)*(p_value+1)=S_ReadByte(ACK); //read the second byte (LSB)*p_checksum=S_ReadByte(noACK); //read checksumreturn(error);}/******************************************************************** ****************************************Function Name: S_Calculate**Description: 计算**Input Parameters: humi [Ticks] (12 bit)** temp [Ticks] (14 bit)**Output Parameters: humi [%RH]** temp [癈]********************************************************************* *************************************/void S_Calculate(unsigned int *p_humidity ,unsigned int *p_temperature) {const float C1=-4.0; // for 8 Bitconst float C2=+0.648; // for 8 Bitconst float C3=-0.0000072; // for 8 Bitconst float D1=-39.6; // for 12 Bit @ 3Vconst float D2=+0.04; // for 12 Bit @ 3Vconst float T1=0.01; // for 8 bitconst float T2=0.00128; // for 8 bitfloat rh=*p_humidity; // rh: Humidity [Ticks] 12 Bitfloat t=*p_temperature; // t: Temperature [Ticks] 14 Bitfloat rh_lin; // rh_lin: Humidity linearfloat rh_true; // rh_true: Temperature compensated humidityfloat t_C; // t_C : Temperature [癈]t_C=t*D2+D1; //calc. temperature from ticks to [癈]rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]if(rh_true>100)rh_true=100; //cut if the value is outside ofif(rh_true<0.1)rh_true=0.1; //the physical possible range*p_temperature=t_C; //return temperature [癈]*p_humidity=rh_true; //return humidity[%RH]}void main(){value humi_val,temp_val;unsigned char error,checksum;unsigned int i,temphigh,templow;unsigned int RegCMD=0x01;WDTCTL=WDTPW+WDTHOLD; //Stop watchdog timer to prevent time out resetS_Init();SVCC_H;S_Connectionreset();S_WriteStatusReg((unsigned char *)&RegCMD);while(1){error=0;error+=S_Measure((unsigned char*) &humi_val.i,&checksum,HUMIDITY);//measure humidityerror+=S_Measure((unsigned char*) &temp_val.i,&checksum,TEMPERATURE); //measure temperatureif(error!=0)S_Connectionreset(); //in case of an error: connection resetelse{templow=(humi_val.i&0xff00);humi_val.i=templow>>8;temphigh=((temp_val.i&0xf)<<8);templow=((temp_val.i&0xff00)>>8);temp_val.i=temphigh+templow;S_Calculate(&humi_val.i,&temp_val.i); //calculate humidity, temperature//temp_val_NOP();//printf("temp:%5.1fC humi:%5.1f%% dewpoint:%5.1fC\n",temp_val.f,humi_val.f,dew_point);}//----------wait approx. 0.8s to avoid heating upSHTxx------------------------------for (i=0;i<40000;i++); //(be sure that the compiler doesn't eliminate this line!)//-----------------------------------------------------------------------------------}}。
SHT10温湿度传感器的通信协议命令包含:1.读取站号命令2.写站号命令3.读取数据4.手动矫正数据串口参数设置:读站号命令(固定命令)主站从站地址功能码H地址L地址 H数据L数据 CRC00 03 00 01 00 01 CRClo CRChi 从站从站地址功能码H地址L地址H数据CRC00 03 02 00 XX CRClo CRChi 注:返回帧与主站相同设备地址:(XX=01-FF)示例:命令00 03 00 01 00 01 D4 1B(固定命令)回复00 03 02 00 FF C5 C4 (设备默认站号FF)写站号命令主站从站地址功能码H地址L地址寄存器个数寄存器个数数据长度数据CRC00 10 00 01 00 01 02 00 XX CRClo CRChi 注:(XX=0X01-0XFF)从站从站地址功能码 H地址L地址寄存器个数CRC00 10 00 01 00 01 CRClo CRChi 示例:命令00 10 00 01 00 01 02 00 33 EA 04回复00 10 00 01 00 01 51 D8读数据主站从站地址功能码 H地址L地址寄存器个数寄存器个数CRCXX 03 00 00 00 02 CRClo CRChi注:(XX=0X01-0XFF)从站从站地址功能码数据长度数据数据CRCXX 03 04 19 AD 1B E4 CRClo CRCh 示例命令FF 03 00 00 00 02 D1 D5回复FF 03 04 19 AD 1B E4 79 FA注:温度:第4,5个字节19 AD温度=读数/100-40度湿度:第5,6个字节1B E4。
STM32F407 IO 口模拟驱动SHT10 温湿度传感器C程序#include "sys.h"#include "delay.h"#include "usart.h"#include "led.h"#include "beep.h"#include "key.h"#include "max5481.h"#include "stmflash.h"/////////////////////////////////////////////////////////////////////////////////////#define uchar u8#define uint u16/////////////////////////////////////////////////////////////////////////////////////long loop_coun = 0;int wiper_value = 0;int bug_tx_coun = 0;int bug_tx_once_flag = 1;volatile u32 bug_coun = 0;//虫子数量volatile char bug_coun_flag = 0;u8 BUG_F_Buffer[4]=//虫子个数存储数组{0x00,0x00,0x00,0x00,};#define BUG_F_LENTH sizeof(BUG_F_Buffer)//数组长度#define SIZE (BUG_F_LENTH / 4) + ((BUG_F_LENTH % 4)? 1 : 0)u8 bug_data_temp[BUG_F_LENTH]={0}; int led_run_coun = 0;char all_active_on_off_flag = 0;int pump_on_off_flag = 0;int mag_id_40_on_off_flag = 0;uint temp_data_a = 0;uint temp_data_b = 0;uint temp_data_c = 0;uint temp_data_d = 0;#define QITITANCE_ID 0X01//气体探测板的id号uchar get_co2_cmd_value_buffer[]=//得到CO2 含量{QITITANCE_ID,0x03,0x00,0x00,//第0个寄存器0x00,0x01,//要读取的数据长度0x84,0x0A,//CRC};uchar get_o2_cmd_value_buffer[]=//得到氧气含量{QITITANCE_ID,0x03,0x00,0x01,//第1个寄存器0x00,0x01,//要读取的数据长度0xD5,0xCA,//CRC};uchar get_ph3_cmd_value_buffer[]=//得到磷化氢含量{QITITANCE_ID,0x03,0x00,0x02,//第0个寄存器0x00,0x01,//要读取的数据长度0x25,0xCA,//CRC};uchar get_3_gas_cmd_value_buffer[8]=//得到三种气体含量{QITITANCE_ID,0x03,0x00,0x00,//第0个寄存器0x00,0x03,//要读取的数据长度0x05,0xCB,//CRC};uchar temp_cmd_value_buffer[]=//临时数组{QITITANCE_ID,0x03,0x02,0x00,0x00,};volatile int get_gas_coun = 0;struct SYS_3_GAS_VALUE{int sys_co2;int sys_o2;int sys_ph3;}sys_3_gas_value;int sys_co2 = 0;//325 代表为3.25% 的含量int sys_o2 = 0;//205 代表为20.5% 的含量int sys_ph3 = 0;//260 代表为260ppm 的含量uchar get_gas_crc_h_byte = 0;uchar get_gas_crc_l_byte = 0;uint get_gas_crc = 0;int rec_usart_1_data_judge_flag = 0;int zhu_base_time_coun = 0;//68 06 16//01 03 00 00 00 03 05 CB//01 03 06 00 02 00 CA 00 00 78 8Bint led_run_enable_active_flag = 0;int led_run_on_coun = 0;int rec_usart_2_data_judge_flag = 0;int led_run_uart_2_enable_on_flag = 0;int led_run_uart_2_coun = 0;uchar uart_2_crc_h_byte = 0;uchar uart_2_crc_l_byte = 0;u8 USART_TX_BUF[100]=//485的发送数组{};u8 USART_TX_BUF_2[72]=//网口的发送数组64+8=72个字节前8个字节为0 最后1个为crc值{};int dcf_is_on_coun = 0 ;// 命令中1的个数当大于5的时候,认为命令不合理,放弃执行int dcf_is_on_off_buffer[40]={0};int led_run_uart_2_tx_coun = 0;int uart_2_tx_enable_led_flash_flag = 0;int led_bug_coun = 0;#define UART2_TIME_OUT_MIN_VALUE 600 // 默认10分钟10*60int temp_dcf_id_v = 0;uint humidity_sys = 0;uint temp_sys = 0;float bug_parameter_humidity = 0.0;float bug_parameter_temperature = 0.0;uint test_a = 0;uint test_b = 0;//qqqqqqqqqqqqqqqqqqqqqqq/////////////////////////////////////////////////////////////////////////////////////void power_on_event(void)//eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{int i;int led_flash_times = 2;//led 闪灯的次数for(i=0;i<led_flash_times;i++){led_run_1;beep_1;delay_ms(200);led_run_0;beep_0;delay_ms(200);}//max_5481_set_wiper_use_24_clock(2,0);//从NV存储器中调出wiper的值。
温湿度传感器SHT10驱动程序——基于MSP430这是暑假时用430的单片机写的温湿度传感器SHT10的程序,参考了官方的51例程,分享一下~~/****************************************Copyright(c)********************************************************************************************LiPeng********************* *************************************--------------FileInfo-------------------------------------------------------------------------------** File Name: Sht10_Driver.c** Created by: LiPeng** Created date: 2008-09-15** Version: 1.0** Descriptions: The original version****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Descriptions:****------------------------------------------------------------------------------------------------------** System Function: Sht10 Driver------温湿度传感器SHT10驱动** 使用MSP430-F413连接方式:** VCC: P6.3** SCK: P6.4** SDA: P6.5*********************************************************************** ***********************************/#include <msp430x14x.h>/*宏定义,延时函数,参数为1时相应延时分别为1us和1ms*/#define CPU_F (double)1000000#define delay_us(x) __delay_cycles((long)(CPU_F * (double)x/1000000.0)) #define delay_ms(x) __delay_cycles((long)(CPU_F * (double)x/1000.0))/*常量定义*/#define uint unsigned int#define uchar unsigned char#define ulong unsigned long//adr command r/w#define STATUS_REG_W 0x06 //000 0011 0#define STATUS_REG_R 0x07 //000 0011 1#define MEASURE_TEMP 0x03 //000 0001 1#define MEASURE_HUMI 0x05 //000 0010 1#define RESET 0x1e //000 1111 0#define bitselect 0x01 //选择温度与湿度的低位读#define noACK 0#define ACK 1#define HUMIDITY 2#define TEMPERATURE 1#define SCK BIT4#define SDA BIT5#define SVCC BIT3#define SCK_H P6OUT|=SCK#define SCK_L P6OUT&=~SCK#define SDA_H P6OUT|=SDA#define SDA_L P6OUT&=~SDA#define SVCC_H P6OUT|=SVCC#define SVCC_L P6OUT&=~SVCCtypedef union{unsigned int i;float f;}value;uint table_temp[3];uint table_humi[3];uint temten;uint humi_true;/******************************************************************** ****************************************Function Name: S_Init**Description: 初始化**Input Parameters: 无**Output Parameters: 无*************************************/void S_Init(){P6SEL&=~(SCK+SDA+SVCC); //选择P6.3 P6.4 为IO端口,输出 P6.5输入P6DIR|=(SCK+SVCC);P6DIR&=~SDA;BCSCTL1=(XT2OFF+RSEL2); //关闭XT2,1MHz DOCDCOCTL=DCO2; //设定DCO频率为1MHz}/******************************************************************** ****************************************Function Name: S_Transstart**Description: 发送开始时序**** generates a transmission start** _____ ________** DATA: |_______|** ___ ___** SCK : ___| |___| |______**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/void S_Transstart(){P6DIR|=SDA;SDA_H;SCK_L;_NOP();SCK_H;_NOP();SDA_L;_NOP();SCK_L;_NOP();_NOP();_NOP();SCK_H;_NOP();SDA_H;_NOP();SCK_L;P6DIR&=~SDA;}****************************************Function Name: S_WriteByte**Description: 写时序**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/char S_WriteByte(unsigned char value){unsigned char i,error=0;P6DIR|=SDA;for(i=0x80;i>0;i/=2) //shift bit for masking{if(i&value)SDA_H; //masking value with i , write to SENSI-BUSelseSDA_L;SCK_H; //clk for SENSI-BUS_NOP();_NOP();_NOP(); //pulswith approx. 5 usSCK_L;}SDA_H; //release DATA-lineP6DIR&=~SDA; //Change SDA to be inputSCK_H; //clk #9 for ackerror=P6IN; //check ack (DATA will be pulled down by SHT11)error&=SDA;P6DIR|=SDA;SCK_L;if(error)return 1; //error=1 in case of no acknowledgereturn 0;}/******************************************************************** ****************************************Function Name: S_ReadByte**Description: 读时序**Input Parameters: ack--->reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"**Output Parameters: 无********************************************************************* *************************************/char S_ReadByte(unsigned char ack){unsigned char i,val=0;P6DIR|=SDA;SDA_H; //release DATA-lineP6DIR&=~SDA;for(i=0x80;i>0;i/=2) //shift bit for masking{SCK_H; //clk for SENSI-BUSif(P6IN&SDA)val=(val|i); //read bitSCK_L;}P6DIR|=SDA;if(ack) //in case of "ack==1" pull down DATA-LineSDA_L;elseSDA_H;SCK_H; //clk #9 for ack_NOP();_NOP();_NOP(); //pulswith approx. 5 usSCK_L;SDA_H; //release DATA-lineP6DIR&=~SDA;return val;}/******************************************************************** ****************************************Function Name: S_Connectionreset**Description: 通讯复位时序** communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart** _____________________________________________________ ________** DATA: |_______|** _ _ _ _ _ _ _ _ _ ___ ___** SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ **Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/void S_Connectionreset(){unsigned char ClkCnt;P6DIR|=SDA;SDA_H;SCK_L; //Initial statefor(ClkCnt=0;ClkCnt<9;ClkCnt++) //9 SCK cycles{SCK_H;SCK_L;}S_Transstart(); //transmission start}/******************************************************************** ****************************************Function Name: S_Softreset**Description: 软件复位时序resets the sensor by a softreset**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/char S_Softreset(){unsigned char error=0;S_Connectionreset(); //reset communicationerror+=S_WriteByte(RESET); //send RESET-command to sensorreturn error; //error=1 in case of no response form the sensor}/******************************************************************** ****************************************Function Name: S_WriteStatusReg**Description: 写状态寄存器**Input Parameters: *p_value**Output Parameters: 无********************************************************************* *************************************/char S_WriteStatusReg(unsigned char *p_value){unsigned char error=0;S_Transstart(); //transmission starterror+=S_WriteByte(STATUS_REG_W); //send command to sensorerror+=S_WriteByte(*p_value); //send value of status registerreturn error; //error>=1 in case of no response form the sensor}/******************************************************************** ****************************************Function Name: S_Mearsure**Description: 读时序 makes a measurement (humidity/temperature) withchecksum**Input Parameters: *p_value ,*p_checknum ,mode**Output Parameters: 无********************************************************************* *************************************/unsigned char S_Measure(unsigned char *p_value, unsigned char*p_checksum, unsigned char mode){unsigned error=0;unsigned int i;S_Transstart(); //transmission startswitch(mode){ //send command to sensorcase TEMPERATURE: error+=S_WriteByte(MEASURE_TEMP); break;case HUMIDITY: error+=S_WriteByte(MEASURE_HUMI); break;}P6DIR&=~SDA;for(i=0;i<65535;i++) //wait until sensor has finished the measurement if((P6IN&SDA)==0)break;if(P6IN&SDA)error+=1; //or timeout (~2 sec.) is reached*(p_value)=S_ReadByte(ACK); //read the first byte (MSB)*(p_value+1)=S_ReadByte(ACK); //read the second byte (LSB)*p_checksum=S_ReadByte(noACK); //read checksumreturn(error);}/******************************************************************** ****************************************Function Name: S_Calculate**Description: 计算**Input Parameters: humi [Ticks] (12 bit)** temp [Ticks] (14 bit)**Output Parameters: humi [%RH]** temp [癈]********************************************************************* *************************************/void S_Calculate(unsigned int *p_humidity ,unsigned int *p_temperature) {const float C1=-4.0; // for 8 Bitconst float C2=+0.648; // for 8 Bitconst float C3=-0.0000072; // for 8 Bitconst float D1=-39.6; // for 12 Bit @ 3Vconst float D2=+0.04; // for 12 Bit @ 3Vconst float T1=0.01; // for 8 bitconst float T2=0.00128; // for 8 bitfloat rh=*p_humidity; // rh: Humidity [Ticks] 12 Bitfloat t=*p_temperature; // t: Temperature [Ticks] 14 Bitfloat rh_lin; // rh_lin: Humidity linearfloat rh_true; // rh_true: Temperature compensated humidityfloat t_C; // t_C : Temperature [癈]t_C=t*D2+D1; //calc. temperature from ticks to [癈]rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]if(rh_true>100)rh_true=100; //cut if the value is outside ofif(rh_true<0.1)rh_true=0.1; //the physical possible range*p_temperature=t_C; //return temperature [癈]*p_humidity=rh_true; //return humidity[%RH]}void main(){value humi_val,temp_val;unsigned char error,checksum;unsigned int i,temphigh,templow;unsigned int RegCMD=0x01;WDTCTL=WDTPW+WDTHOLD; //Stop watchdog timer to prevent time out resetS_Init();SVCC_H;S_Connectionreset();S_WriteStatusReg((unsigned char *)&RegCMD);while(1){error=0;error+=S_Measure((unsigned char*) &humi_val.i,&checksum,HUMIDITY);//measure humidityerror+=S_Measure((unsigned char*) &temp_val.i,&checksum,TEMPERATURE); //measure temperatureif(error!=0)S_Connectionreset(); //in case of an error: connection resetelse{templow=(humi_val.i&0xff00);humi_val.i=templow>>8;temphigh=((temp_val.i&0xf)<<8);templow=((temp_val.i&0xff00)>>8);temp_val.i=temphigh+templow;S_Calculate(&humi_val.i,&temp_val.i); //calculate humidity, temperature//temp_val_NOP();//printf("temp:%5.1fC humi:%5.1f%% dewpoint:%5.1fC\n",temp_val.f,humi_val.f,dew_point);}//----------wait approx. 0.8s to avoid heating upSHTxx------------------------------for (i=0;i<40000;i++); //(be sure that the compiler doesn't eliminate this line!)//-----------------------------------------------------------------------------------}}。
1应用范围
SHT10(SHT11、SHT15)防护型温湿度传感器采用原装进口温湿度测量元件(内置SHT10/11/15)为核心部件,具有非常高的一致性、可完全互换,全量程标定,两线数字输出,湿度精度可高达±2%RH。
铜烧结网的防护加强了探头的耐温、耐压、耐损能力,可广泛适用于农业温室大棚、花卉、苗圃、草坪,养殖、仓储等各种需要测量环境温湿度的场所。
2技术参数
¾湿度测量范围:0~100%RH
¾温度测量范围:-40~+123.8℃
¾湿度测量精度: ±4.5%RH
¾温度测量精度: ±0.5℃
¾响应时间:8s(tau63%)
¾低功耗 80μW(12位测量,1次/s)
3接线方式
航空插头的管脚定义与SHT10的管脚定义相同,具体如下:
红色线VCC-电源正极(航空插头管脚4)
黄色线GND-电源负极(航空插头管脚1)
绿色线DATA-数据(航空插头管脚2)
蓝色线SCK-时序(航空插头管脚3)
4产品外观如图
4芯航空插头接插件连接,轻松更换,轻松维护。
引言SHT1x 系列属于Sensorion 传感器家族中的贴片封装系列。
传感器将传感元件和信号处理电路集成在一块微型电路板上,输出完全标定的数据信号。
传感器采用专利的CMOSens 技术,确保产品具有极高的可靠性与卓越的长期稳定性。
传感器包括一个电容聚合体测湿敏感元件、一个能隙材料制成的测温元件,并在同一芯片上,与14位的A/D 转换及串行接口电路实现无缝连接。
因此,该产品具有品质卓越、响应迅速、抗干扰能力强、性价比高等优点,广泛应用于化工、机械、家电等温度及湿度的测量中[1]。
1 SHT10温湿度检测设计要点《开发使用SHTxx 温湿度传感器注意事项》之中提到了包装、运输、焊接、防静电的要求,以及编程使用中应该注意的问题[2],都是设计开发要注意的事项,下面结合空调机组SHT10温湿度检测板的开发过程,分别从安装、硬件、软件方面总结设计要点。
1.1 SHT10温湿度检测板安装设计要点SHT10温湿度检测板安装在空调机组上长期运行,如不进行防尘处理,灰尘积聚在SHT10传感器上,会影响检测精度;冷凝水积聚在检测板上,会造成主板氧化受潮,导致主板失效。
SHT10温湿度检测板安装时注意垂直安装,防止板上积水造成SHT10温湿度检测设计要点及故障分析缪玉珍(珠海格力电器股份有限公司制冷技术研究院 珠海 519070)氧化。
主板在生产时要刷防潮胶进行防护,防止主板在潮湿环境下氧化。
1.2 SHT10温湿度检测板硬件设计要点SHT10温湿度检测板硬件设计要注意在电源处加电容进行滤波去耦,在SHT10传感器的四周开槽隔热,同时也要注意上拉电阻的使用[1]。
规格书上要求数据线DATA 上接10~20K 的上拉电阻,用示波器观察SHT10工作正常,每次发送温度及湿度测试命令,都有数据回传。
在EMC 测试中,却出现不能读到温度及湿度测试数据,报“回风探头故障”,有时能自动恢复,有时不能自动恢复。
用示波器观察EMC 测试中的DATA 与SCK 波形,发现时钟SCK 信号的脉冲输出不全,导致SHT10的I 2C 通讯不正常。