Пример #1
0
//----------------------------------------------------------------------------------
void main()
//----------------------------------------------------------------------------------
// sample program that shows how to use SHT11 functions
// 1. connection reset 
// 2. measure humidity [ticks](12 bit) and temperature [ticks](14 bit)
// 3. calculate humidity [%RH] and temperature [°C]
// 4. calculate dew point [°C]
// 5. print temperature, humidity, dew point  

{ value humi_val,temp_val;
  float dew_point;
  unsigned char error,checksum;
  unsigned int i;

  init_uart();
  s_connectionreset();
  while(1)
  { error=0;
    error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity
    error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
    if(error!=0) s_connectionreset();                 //in case of an error: connection reset
    else
    { humi_val.f=(float)humi_val.i;                   //converts integer to float
      temp_val.f=(float)temp_val.i;                   //converts integer to float
      calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
      dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
      printf("temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n",temp_val.f,humi_val.f,dew_point);
    }
    //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------      
    for (i=0;i<40000;i++);     //(be sure that the compiler doesn't eliminate this line!)
    //-----------------------------------------------------------------------------------                       
  }
} 
Пример #2
0
void humid_sht_periodic(void)
{
  uint8_t error = 0, checksum;

  if (humid_sht_status == SHT_IDLE) {
    /* init humidity read */
    s_connectionreset();
    s_start_measure(HUMI);
    humid_sht_status = SHT_MEASURING_HUMID;
  } else if (humid_sht_status == SHT_MEASURING_HUMID) {
    /* get data */
    error += s_read_measure(&humidsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(HUMI);    //restart
      //LED_TOGGLE(2);
    } else {
      error += s_start_measure(TEMP);
      humid_sht_status = SHT_MEASURING_TEMP;
    }
  } else if (humid_sht_status == SHT_MEASURING_TEMP) {
    /* get data */
    error += s_read_measure(&tempsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(TEMP);    //restart
      //LED_TOGGLE(2);
    } else {
      calc_sht(humidsht, tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = true;
      s_connectionreset();
      s_start_measure(HUMI);
      humid_sht_status = SHT_MEASURING_HUMID;
      DOWNLINK_SEND_SHT_STATUS(DefaultChannel, DefaultDevice, &humidsht, &tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = false;

#if SHT_SDLOG
  if (pprzLogFile != -1) {
    if (!log_sht_started) {
      sdLogWriteLog(pprzLogFile, "SHT75: Humid(pct) Temp(degC) GPS_fix TOW(ms) Week Lat(1e7deg) Lon(1e7deg) HMSL(mm) gspeed(cm/s) course(1e7deg) climb(cm/s)\n");
      log_sht_started = true;
    }
    sdLogWriteLog(pprzLogFile, "sht75: %9.4f %9.4f    %d %d %d   %d %d %d   %d %d %d\n",
		  fhumidsht, ftempsht,
		  gps.fix, gps.tow, gps.week,
		  gps.lla_pos.lat, gps.lla_pos.lon, gps.hmsl,
		  gps.gspeed, gps.course, -gps.ned_vel.z);
  }
#endif

    }
  }
}
Пример #3
0
/*
*********************************************************************************************************
*                         				SOFT RESET THE SENSOR
*
* Description :	Soft reset, resets the interface, clears the status register to default values
*				Wait minimum 11 ms before next command
* Arguments   : none
*
* Returns     : 1 if no response from the sensor
* Notes		  :
*********************************************************************************************************
*/
char s_softreset(void)
{
    unsigned char error=0;
    s_connectionreset();              //reset communication
    error+=s_write_byte(RESET);       //send RESET-command to sensor
    return error;                     //error=1 in case of no response from the sensor
}
Пример #4
0
//----------------------------------------------------------------------------------
u8 s_softreset(void)
//----------------------------------------------------------------------------------
// resets the sensor by a softreset 
{ 
u8 error=0; 
s_connectionreset(); //reset communication
error+=s_write_byte(RESET); //send RESET-command to sensor
return error; //error=1 in case of no response form the sensor
}
Пример #5
0
void humid_sht_periodic(void) {
  uint8_t error=0, checksum;

  if (humid_sht_status == SHT_IDLE) {
    /* init humidity read */
    s_connectionreset();
    s_start_measure(HUMI);
    humid_sht_status = SHT_MEASURING_HUMID;
  }
  else if (humid_sht_status == SHT_MEASURING_HUMID) {
    /* get data */
    error += s_read_measure(&humidsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(HUMI);    //restart
      LED_TOGGLE(2);
    }
    else {
      error += s_start_measure(TEMP);
      humid_sht_status = SHT_MEASURING_TEMP;
    }
  }
  else if (humid_sht_status == SHT_MEASURING_TEMP) {
    /* get data */
    error += s_read_measure(&tempsht, &checksum);

    if (error != 0) {
      s_connectionreset();
      s_start_measure(TEMP);    //restart
      LED_TOGGLE(2);
    }
    else {
      calc_sht(humidsht, tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = TRUE;
      s_connectionreset();
      s_start_measure(HUMI);
      humid_sht_status = SHT_MEASURING_HUMID;
      DOWNLINK_SEND_SHT_STATUS(DefaultChannel, DefaultDevice, &humidsht, &tempsht, &fhumidsht, &ftempsht);
      humid_sht_available = FALSE;
    }
  }
}
Пример #6
0
void humid_sht_periodic_orig(void)
{
  uint8_t error=0, checksum;

  s_connectionreset();

  error += s_measure(&humidsht, &checksum, HUMI);  //measure humidity
  error += s_measure(&tempsht,  &checksum, TEMP);  //measure temperature

  if (error != 0)
  {
    s_connectionreset();            //in case of an error: connection reset
  }
  else
  {
    calc_sht(humidsht, tempsht, &fhumidsht, &ftempsht);         //calculate humidity, temperature
    humid_sht_available = TRUE;
  }
}
Пример #7
0
uint8_t humid_sht_reset( void )
{
// resets the sensor by a softreset
   uint8_t error=0;

   s_connectionreset();                  //reset communication
   error+=s_write_byte(RESET);           //send RESET-command to sensor

   return error;                         //error=1 in case of no response form the sensor
}
Пример #8
0
void initialize_sht11_hanback(void)
{
RCC_APB2PeriphClockCmd(SHT11_DDR, ENABLE);
SHT11_GPIO_InitStructure.GPIO_Pin = SHT11_SCK | SHT11_SDA;
SHT11_GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
SHT11_GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(SHT11_PORT, &SHT11_GPIO_InitStructure);

s_connectionreset(); 

}
Пример #9
0
//----------------------------------------------------------------------------------
char s_softreset(void)
//----------------------------------------------------------------------------------
// resets the sensor by a softreset 
{ 
  //unsigned char error=0; 
  error_=0;
  
  s_connectionreset();              //reset communication
  error_+=s_write_byte(RESET);       //send RESET-command to sensor
  return error_;                     //error=1 in case of no response form the sensor
}
Пример #10
0
void takeHumiAnfTemperature()
{ 
  unsigned char error,checksum;
  //unsigned int i;

  //WDTCTL = WDTPW + WDTHOLD;
  s_connectionreset();

  error=0;
  error+=s_measure(&t_temp,&checksum,TEMP);
  error+=s_measure(&t_hum,&checksum,HUMI);   
  if(error!=0) s_connectionreset();                
  else
  {
    temperatureSHT11 = (float) t_temp;
    hum = (float) t_hum;
    calc_sth11(&hum, &temperatureSHT11);            //calculate humidity, temperature
    dew_point=calc_dewpoint(hum,temperatureSHT11); //calculate dew point
  }
    //1 second delay
  //__delay_cycles (16000000);
}
Пример #11
0
u16 get_sht11_hanback_data(u8 type)
{
acq_type=type;

error=0;
error+=s_measure(&sht11_humi,&checksum,HUMI); //measure humidity
error+=s_measure(&sht11_temp,&checksum,TEMP); //measure temperature
if(error!=0) s_connectionreset(); //in case of an error: connection reset
else
{ 
calc_sth11(sht11_humi,sht11_temp); //calculate humidity, temperature
if(acq_type==DEW)dew_point=calc_dewpoint(sht11_humi,sht11_temp); //calculate dew point
//char buf[10];
//puts("sht11_humi="); itoa(sht11_humi,buf,10); puts(buf); puts("\r\n");
//puts("sht11_temp="); itoa(sht11_temp,buf,10); puts(buf); puts("\r\n");
}
if(acq_type == DEW)return (u16)(dew_point*10);
else if(acq_type == HUMI)return myhumi;
else if(acq_type == TEMP)return mytemp;
else return 0;
}
//--------------------------------------------------------------------
void sht10_read(void)
//--------------------------------------------------------------------
// 读温湿度
// input:   humidity [%RH], temperature [癈]
// output:  dew point [癈]
{
	
	 unsigned char error,checksum;
	 error=0;

	 error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity

	 error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
	
	 
	 if(error!=0)	 {
		s_connectionreset();                 //in case of an error: connection reset
		humi_val.active=0;
		temp_val.active=0;
		//printf("读写SHT10,失败,重新初始化STH10\r\n");	
	 }
	 else
	 { 
			humi_val.f=(float)humi_val.i;                   //converts integer to float
			temp_val.f=(float)temp_val.i;                   //converts integer to float

			calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
		 
			humi_val.i=temp_val.i=0;//20150328

			//printf("temp:%5.1fC humi:%5.1f%%\n",temp_val.f,humi_val.f);

			//printf("读写SHT10成功\r\n");																			
			humi_val.active=1;
			temp_val.active=1;
	 }
}
Пример #13
0
//----------------------------------------------------------------------------------
void ReadHMS(void)
//----------------------------------------------------------------------------------
{
	if(timeout) timeout--;
        if(hmioerr)
        {
          if(++hmerrcnt>3) // больше трех ошибок подряд?
          {
            hmerrcnt=0; // сбросить счетчик ошибок
            hms_errflg = -2; // неисправность сенсора влажности
//            ets_printf("*");
          };
          hmioerr = 0; // сбросить флаг ошибки
          hmfuncs = 0;  // далее сбросить датчик
          SetTimeOut(50); // зададим таймаут в 50 ms
        };
        switch(hmfuncs)
        {
          default:
           if(!TestTimeOut()) break; // ожидание паузы
           s_connectionreset(); // 26t
//           s_transstart();      // 8t transmission start
           if(hmioerr) break;
           s_write_byte(HTD_WS);// 18t Status Register Write  [0x06]
           if(hmioerr) break;
           s_write_byte(0x00);  // 18t
           if(hmioerr) break;
           hmioerr=0; // сбросить флаг ошибки (см. InitHMS())
           hmfuncs=1; // далее на запрос температуры датчика
           break; // 26+8+16+18 = 68t -> 68*1.25=85 us

          case 2:  // чтение данных температуры с датчика и запрос данных о влажности
          case 5:  // чтение данных температуры с датчика и запрос данных о влажности
           if(i2c_test_sda())
           {
             if(TestTimeOut()) hmioerr++;
             break;
           }
           reg_tmp = s_read_byte() << 8; // 19t
           reg_tmp |= s_read_byte(); // 19t
           if (s_read_crc()) // 19t
           {
             hmioerr++;
             break;
           };
           s_transstart(); // 8t transmission start
           s_write_byte(HTD_MH); // 18t Read Measure Humidity [0x05] ... 0.06133 s
           hmfuncs++; // след. функция
           SetTimeOut(120); // зададим таймаут в 120 ms
           break; // 19*3+8+18=83t  83*1.25=103.75us=0.00010375 sec

          case 3: // чтение данных о влажности
          case 6: // чтение данных о влажности
           if(i2c_test_sda())
           {
            if(TestTimeOut()) hmioerr++;
            break;
           }
           reg_rh = s_read_byte()<<8; // 19t
           reg_rh |= s_read_byte();
           if (s_read_crc()) // 19t  // ~75us
           {
             hmioerr++;
             break;
           };
          case 1: // запрос температуры датчика       (цикл опроса 0.2744s)
           s_transstart(); // 8t transmission start
           s_write_byte(HTD_MT); // 18t Read Measure Temperature  [0x03] ... 0.2128 s
           hmfuncs++; // далее на чтение данных температуры с датчика
           SetTimeOut(350); // зададим таймаут в 350 ms
           break;

          case 4: // сумма, проход 1
           T.ul = reg_tmp;
           RH.ul = reg_rh;
           hmfuncs++;
           break;

          case 7: // сумма, проход 2
           T.ul += reg_tmp;
//           mouts.rt = T.ui[0];
           RH.ul += reg_rh;
//           mouts.rh = RH.ui[0];
           hmfuncs++;
           break;

          case 8: // расчет, часть 1
#if HDT14BIT
           T.d=((float)(T.ul))*0.005 - PTATD1; //calc. Temperature from ticks to [C]      36.92 0.3
#else
           T.d=((float)(T.ul))*0.002 - PTATD1; //calc. Temperature from ticks to [C]
#endif
           RH.d=(float)(RH.ul)*0.5;
#if HDT14BIT
           RH.d=(T.d-25.0)*(0.01+0.00008*RH.d)-0.0000028*RH.d*RH.d+0.0405*RH.d-4.0;
#else
           RH.d=(T.d-25.0)*(0.01+0.00128*RH.d)-0.00072*RH.d*RH.d+0.648*RH.d-4.0;
#endif
           if(RH.d>100.0) RH.d=100.0;
           else if(RH.d<0.1) RH.d=0.1;
/*           hmfuncs++;
           break;
          case 9: // расчет, часть 2
           Dp.d = (log10(RH.d)-2)/0.4343 + (17.62*T.d)/(243.12+T.d);
           Dp.d = 243.12*Dp.d/(17.62-Dp.d);


           ets_printf("T=%d, RH=%d, DP=%d\n", (int)(T.d*100.0), (int)(RH.d*100.0), (int)(Dp.d*100.0) );
*/
           // перевод float в int.01
           hms_tmp = (int)(T.d*100.0);
           hms_rh = (int)(RH.d*100.0);
           hms_count++;
       	   hms_errflg = 0; // сбросить  неисправность сенсора влажности
//           ets_printf("T=%d, RH=%d\n", hms_tmp, hms_rh);
           hmerrcnt=0; // сбросить счетчик ошибок
           hmfuncs=2; // на начало опроса
           break;
        }
}