Defines | |
| #define | STATUS_REG_W 0x06 |
| #define | STATUS_REG_R 0x07 |
| #define | MEASURE_TEMP 0x03 |
| #define | MEASURE_HUMI 0x05 |
| #define | RESET 0x1e |
| #define | TEMP 1 |
| #define | HUMI 2 |
| #define | ERROR 0 |
| #define | DONE 1 |
| #define | SHT_TIME 2 |
| #define | C1 -4.0 |
| #define | C2 0.0405 |
| #define | C3 -0.0000028 |
| #define | T1 0.01 |
| #define | T2 0.00008 |
| #define | D1 -39.66 |
| #define | D2 0.01 |
Functions | |
| void | HumiSensor_Init (int humsen) |
| signed char | SHT7x_Measure (unsigned int *DataToSend, unsigned char flag, unsigned char *FCSoriginator, unsigned char *FCSclient, int humsen) |
| unsigned char | HumidSensor_Cmd (unsigned int *rhumidity, unsigned int *rtemperature, float *humidity, float *temperature, unsigned char *OrigFCS, unsigned char *DeviceFCS, int humsen) |
| void | SHT7x_Correction (float *p_humidity, float *p_temperature) |
| unsigned char | ReverseStatus (unsigned char value) |
| unsigned char | ReverseByte (unsigned char dataBeReversed) |
| unsigned char | SHT7x_StatusRead (unsigned char *StatusRead, int humsen) |
| unsigned char | SHT7x_StatusWrite (unsigned char StatusWrite, int humsen) |
| #define C1 -4.0 |
| #define C2 0.0405 |
| #define C3 -0.0000028 |
| #define D1 -39.66 |
| #define D2 0.01 |
| #define DONE 1 |
| #define ERROR 0 |
| #define HUMI 2 |
| #define MEASURE_HUMI 0x05 |
| #define MEASURE_TEMP 0x03 |
| #define RESET 0x1e |
| #define SHT_TIME 2 |
| #define STATUS_REG_R 0x07 |
| #define STATUS_REG_W 0x06 |
| #define T1 0.01 |
| #define T2 0.00008 |
| #define TEMP 1 |
| unsigned char HumidSensor_Cmd | ( | unsigned int * | rhumidity, | |
| unsigned int * | rtemperature, | |||
| float * | humidity, | |||
| float * | temperature, | |||
| unsigned char * | OrigFCS, | |||
| unsigned char * | DeviceFCS, | |||
| int | humsen | |||
| ) |
00032 { 00033 00034 float xdata temp_humi, temp_tempe; 00035 unsigned char xdata TempStatus,HumiStatus; 00036 unsigned int xdata rtemp,rhumi; 00037 unsigned char xdata temp_FCSOrig,temp_FCSDevice; 00038 00039 TempStatus = SHT7x_Measure(&rtemp, TEMP, &temp_FCSOrig, &temp_FCSDevice, humsen); //measure temperature 00040 HumiStatus = SHT7x_Measure(&rhumi, HUMI, &temp_FCSOrig, &temp_FCSDevice, humsen); //measure humidity 00041 00042 *DeviceFCS = temp_FCSDevice; 00043 *OrigFCS = temp_FCSOrig; 00044 *rtemperature = rtemp; 00045 *rhumidity = rhumi; 00046 00047 temp_humi = (float) rhumi; 00048 temp_tempe = (float) rtemp; 00049 SHT7x_Correction(&temp_humi,&temp_tempe); //calculate humidity, temperature 00050 *humidity = temp_humi; 00051 *temperature = temp_tempe; 00052 00053 if((TempStatus == ERROR) || (HumiStatus == ERROR)){ 00054 SHT7x_ConnectionReset(humsen); //in case of an error: connection reset 00055 // delay_ms(800); 00056 return ERROR; 00057 } 00058 00059 //wait approx. 0.8s to avoid heating up SHTxx 00060 //delay_ms(800); 00061 return DONE; 00062 }
| void HumiSensor_Init | ( | int | humsen | ) |
| unsigned char ReverseByte | ( | unsigned char | dataBeReversed | ) |
| unsigned char ReverseStatus | ( | unsigned char | value | ) |
| void SHT7x_Correction | ( | float * | p_humidity, | |
| float * | p_temperature | |||
| ) |
00158 { 00159 // Assuming VDD to be 3.5V but the actual voltage is 3.3V 00160 *p_temperature = (*p_temperature * D2) + D1 ; 00161 *p_humidity = (*p_humidity) * (*p_humidity * C3) + *p_humidity * C2 + C1; 00162 00163 *p_humidity=(*p_temperature - 25)*(T1+ *p_humidity * T2)+ *p_humidity; //calc. Temperature compensated humidity [%RH] 00164 00165 if(*p_humidity > 100) 00166 *p_humidity = 100; // Cut if the value is outside of 00167 00168 if(*p_humidity <0.1) 00169 *p_humidity = 0.1; // the physical possible range 00170 00171 }
| signed char SHT7x_Measure | ( | unsigned int * | DataToSend, | |
| unsigned char | flag, | |||
| unsigned char * | FCSoriginator, | |||
| unsigned char * | FCSclient, | |||
| int | humsen | |||
| ) |
00072 { 00073 unsigned char xdata check_flag, status = DONE; 00074 unsigned char xdata FCSdevice, FCSorig, MSBdata, LSBdata; 00075 unsigned int xdata measurements=0; 00076 unsigned long xdata SHT_time =0, temp_check=0; 00077 00078 00079 SHT7x_TransStart(humsen); //transmission start 00080 00081 switch(flag) { //send command to sensor 00082 case TEMP: 00083 status = SHT7x_WriteByte(MEASURE_TEMP, humsen); 00084 check_flag = MEASURE_TEMP; 00085 break; 00086 00087 case HUMI : 00088 status = SHT7x_WriteByte(MEASURE_HUMI, humsen); //if device does not ack, returns error 00089 check_flag = MEASURE_HUMI; 00090 break; 00091 00092 default : 00093 break; 00094 } 00095 00096 SHT_time = uptime(); 00097 00098 do { 00099 if(humsen==1) { 00100 if(SHT7x_DATA1 == 0) { 00101 temp_check = 1; 00102 break; //wait until sensor has finished the measurement 00103 } 00104 } 00105 #ifdef MORETHANONEHUM 00106 else if(humsen==2) { 00107 if(SHT7x_DATA2 == 0) { 00108 temp_check = 1; 00109 break; //wait until sensor has finished the measurement 00110 } 00111 } 00112 #endif 00113 }while ((uptime() - SHT_time) < SHT_TIME); 00114 00115 00116 if(temp_check == 0){ 00117 SHT7x_ConnectionReset(humsen); 00118 return ERROR; // timeout is reached 00119 } 00120 00121 //14bit temperature measurements 00122 //12bit humidity measurements 00123 MSBdata = SHT7x_ReadByte(ACK, humsen); //read the first byte (MSB) 00124 LSBdata = SHT7x_ReadByte(ACK, humsen); //read the second byte (LSB) 00125 FCSdevice = SHT7x_ReadByte(ACK, humsen); //read the last byte (checksum) 00126 FCSdevice = ReverseByte (FCSdevice); 00127 00128 //Calculate originator's side write FCS 00129 FCSorig = SHT7x_FCS_Step(LSBdata 00130 , SHT7x_FCS_Step(MSBdata 00131 , SHT7x_FCS_Step(check_flag 00132 , 0x00))); 00133 00134 *FCSclient = FCSdevice; 00135 *FCSoriginator = FCSorig; 00136 00137 // Checking the checksum 00138 if (FCSdevice != FCSorig) { 00139 SHT7x_ConnectionReset(humsen); 00140 return ERROR; 00141 } 00142 00143 measurements = (MSBdata <<8) | (LSBdata); 00144 00145 if(flag == TEMP) 00146 measurements &= 0x3fff; 00147 else 00148 measurements &= 0x0fff; 00149 00150 *DataToSend = measurements; 00151 return status; 00152 }
| unsigned char SHT7x_StatusRead | ( | unsigned char * | StatusRead, | |
| int | humsen | |||
| ) |
| unsigned char SHT7x_StatusWrite | ( | unsigned char | StatusWrite, | |
| int | humsen | |||
| ) |
1.4.7