2014-08-27 18:47:31 +02:00
|
|
|
/*
|
2013-08-16 10:20:23 +02:00
|
|
|
* Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved.
|
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-08-27 18:47:31 +02:00
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/**
|
2017-07-02 23:21:36 +02:00
|
|
|
* @defgroup drivers_sht11 SHT11 Humidity and Temperature Sensor
|
2015-09-25 21:06:17 +02:00
|
|
|
* @ingroup drivers_sensors
|
2015-11-19 17:13:33 +01:00
|
|
|
* @brief Driver for Sensirion SHT11 Humidity and Temperature Sensor
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2013-11-27 17:54:30 +01:00
|
|
|
* @brief SHT11 Device Driver
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2013-11-27 17:54:30 +01:00
|
|
|
* @author Freie Universität Berlin, Computer Systems & Telematics
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2013-11-27 17:54:30 +01:00
|
|
|
|
2017-08-29 18:00:46 +02:00
|
|
|
#ifndef SHT11_H
|
|
|
|
#define SHT11_H
|
|
|
|
|
2010-11-04 18:16:39 +01:00
|
|
|
#include <stdint.h>
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-10-13 15:49:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-03-06 17:43:56 +01:00
|
|
|
#define SHT11_NO_ACK (0) /**< don't ack read in `read_byte` */
|
|
|
|
#define SHT11_ACK (1) /**< do acknowledge read in `read_byte` */
|
|
|
|
/* adr command r/w */
|
|
|
|
#define SHT11_STATUS_REG_W (0x06) /**< will write to status register */
|
|
|
|
#define SHT11_STATUS_REG_R (0x07) /**< will read from status register */
|
|
|
|
#define SHT11_MEASURE_TEMP (0x03) /**< tell sensor to measure temperature */
|
|
|
|
#define SHT11_MEASURE_HUMI (0x05) /**< tell sensor to measure humidity */
|
|
|
|
#define SHT11_RESET (0x1E) /**< reset the sensor */
|
|
|
|
|
|
|
|
/** time to wait after toggling the data line */
|
2015-08-14 13:30:49 +02:00
|
|
|
#define SHT11_DATA_WAIT (1)
|
2017-03-06 17:43:56 +01:00
|
|
|
/** time to wait after toggling the clock line */
|
2015-08-14 13:30:49 +02:00
|
|
|
#define SHT11_CLK_WAIT (1)
|
2010-10-29 17:32:03 +02:00
|
|
|
|
2017-03-06 17:43:56 +01:00
|
|
|
/** set measurement timeout to 1 second */
|
2010-09-22 15:10:42 +02:00
|
|
|
#define SHT11_MEASURE_TIMEOUT (1000)
|
|
|
|
|
2010-11-01 17:38:03 +01:00
|
|
|
/**
|
2013-06-21 22:36:48 +02:00
|
|
|
* @brief sht11 measureable data
|
2010-11-01 17:38:03 +01:00
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
typedef struct {
|
2013-11-27 17:54:30 +01:00
|
|
|
float temperature; /**< temperature value */
|
|
|
|
float relhum; /**< linear relative humidity */
|
|
|
|
float relhum_temp; /**< temperature compensated relative humidity */
|
2010-09-22 15:10:42 +02:00
|
|
|
} sht11_val_t;
|
|
|
|
|
|
|
|
/**
|
2013-11-27 17:54:30 +01:00
|
|
|
* @brief SHT11 modes that can be measured
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2013-06-21 22:36:48 +02:00
|
|
|
TEMPERATURE = 1,
|
|
|
|
HUMIDITY = 2
|
2010-09-22 15:10:42 +02:00
|
|
|
} sht11_mode_t;
|
|
|
|
|
|
|
|
/**
|
2013-11-27 17:54:30 +01:00
|
|
|
* @brief Initialize SHT11 ports
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
|
|
|
void sht11_init(void);
|
|
|
|
|
|
|
|
/**
|
2013-11-27 17:54:30 +01:00
|
|
|
* @brief Read sensor
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2010-11-01 17:38:03 +01:00
|
|
|
* @param value The struct to be filled with measured values
|
|
|
|
* @param mode Specifies type of data to be read
|
|
|
|
*
|
|
|
|
* @return 1 on success, 0 otherwise
|
|
|
|
*
|
2010-09-22 15:10:42 +02:00
|
|
|
* Example:
|
2010-11-01 17:38:03 +01:00
|
|
|
* \code sht11_val sht11;
|
|
|
|
* sht11_read_sensor(&sht11, HUMIDITY|TEMPERATURE);
|
2010-09-22 15:10:42 +02:00
|
|
|
* printf("%-6.2f °C %5.2f %% %5.2f %%\n", sht11.temperature, sht11.relhum, sht11.relhum_temp); \endcode
|
|
|
|
*/
|
|
|
|
uint8_t sht11_read_sensor(sht11_val_t *value, sht11_mode_t mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Write status register
|
2013-06-21 22:36:48 +02:00
|
|
|
*
|
2010-09-22 15:10:42 +02:00
|
|
|
* @param p_value The value to write
|
|
|
|
*
|
|
|
|
* @return 1 on success, 0 otherwise
|
|
|
|
*/
|
|
|
|
uint8_t sht11_write_status(uint8_t *p_value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read status register with checksum
|
|
|
|
*
|
|
|
|
* @param p_value The read value
|
|
|
|
* @param p_checksum The received checksum
|
|
|
|
*
|
|
|
|
* return 1 on success, 0 otherwise
|
|
|
|
*/
|
|
|
|
uint8_t sht11_read_status(uint8_t *p_value, uint8_t *p_checksum);
|
|
|
|
|
2014-10-13 15:49:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-18 15:07:35 +01:00
|
|
|
#endif /* SHT11_H */
|
2017-08-29 18:00:46 +02:00
|
|
|
/** @} */
|