示例#1
0
//----------------------------------------------------------------------------------
unsigned char sht_measure(sht_value *p_sht_value, unsigned char *p_checksum, unsigned char mode, unsigned char pin)
//----------------------------------------------------------------------------------
// makes a measurement (humidity/temperature) with checksum
{
	unsigned char error=0;
	unsigned char i;

	sht_value this_sht_value;
	/* sht_transstart(pin); //transmission start */
	sht_connectionreset(pin);
	switch(mode)
	{ //send command to sensor
		case TEMP : error+=sht_write_byte(MEASURE_TEMP, pin); /*usart_write("TEMP: ");*/ break;
		case HUMI : error+=sht_write_byte(MEASURE_HUMI, pin); /*usart_write("HUMI: ");*/ break;
		default : break;
	}

	for (i=0;i<500;i++) {
		if(SHT_DATA(pin)==0) break; //wait until sensor has finished the measurement
		_delay_ms(1);  	// neccesary since the AVR is so much faster than the old 8051
							// and the 210ms for 14bit measuremnt are only a rough estimate
	}

	if(SHT_DATA(pin)) error+=1; // or timeout is reached 

	this_sht_value.i = 256*sht_read_byte(ACK, pin); //read the first byte (MSB)
	this_sht_value.i +=sht_read_byte(ACK, pin); //read the second byte (LSB)
		
	*p_checksum =sht_read_byte(noACK, pin); //read checksum
	*(p_sht_value)= this_sht_value;
	return error;
}
示例#2
0
//----------------------------------------------------------------------------------
// resets the sensor by a softreset
//----------------------------------------------------------------------------------
char sht_softreset(void)
{
	unsigned char error=0;
	sht_connectionreset();              //reset communication
	error+=sht_write_byte(RESET);      //send RESET-command to sensor
	return error;                     //error=1 in case of no response form the sensor
}
示例#3
0
文件: shtxx.c 项目: vdbriel/netnode
//----------------------------------------------------------------------------------
char sht_do_measure(unsigned char Sensor){
//----------------------------------------------------------------------------------
// 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  

  unsigned int humi_val_i;
  unsigned int temp_val_i;

  Values humi_val;
  Values temp_val;

  unsigned char error,checksum;
  unsigned int i;
  float humi_val_f;
  float temp_val_f;
  
  error=sht_SetSensor(Sensor);
  
  sht_connectionreset();
  
  SHTdevice_table[CurrentSensorIndex].valid = 0;
  error+=sht_measure(HUMI);  //measure humidity
  humi_val_i = CurrentValue;
  error+=sht_measure(TEMP);  //measure temperature
  temp_val_i = CurrentValue;
  
  if(error!=0) {
      sht_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);
    SHTdevice_table[CurrentSensorIndex].humidity    = (unsigned char)humi_val_f;
    SHTdevice_table[CurrentSensorIndex].temperature = (int)(temp_val_f*100);
    SHTdevice_table[CurrentSensorIndex].valid       = 1;
  }
  return error;
} 
示例#4
0
//----------------------------------------------------------------------------------
unsigned char sht_softreset(unsigned char pin)
//----------------------------------------------------------------------------------
// resets the sensor by a softreset
{
	// rockclimber
	MAKE_SHT_SCK_PIN_OUTPUT;
	asm volatile ("nop"::);

	unsigned char error=0;
	sht_connectionreset(pin); //reset communication
	error+=sht_write_byte(RESET_SHT, pin); //send RESET_SHT-command to sensor
	return error; //error=1 in case of no response form the sensor
}