sht2x.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016,2017,2018 Kees Bakker, SODAQ
3  * Copyright (C) 2017 George Psimenos
4  * Copyright (C) 2018 Steffen Robertz
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
26 #ifndef SHT2X_H
27 #define SHT2X_H
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include "periph/i2c.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
40 enum {
41  SHT2X_OK = 0,
50  SHT2X_ERR_OTHER = -999,
51 };
52 
58 typedef enum {
63 } sht2x_res_t;
64 
68 typedef enum {
72 
79 #define SHT2X_USER_RESOLUTION_MASK 0x81
80 #define SHT2X_USER_EOB_MASK 0x40
81 #define SHT2X_USER_HEATER_MASK 0x04
82 #define SHT2X_USER_RESERVED_MASK 0x38
83 #define SHT2X_USER_OTP_MASK 0x02
84 
89 typedef struct {
91  uint8_t i2c_addr;
96 
100 typedef struct {
102 } sht2x_t;
103 
116 int sht2x_init(sht2x_t* dev, const sht2x_params_t* params);
117 
126 int sht2x_reset(sht2x_t* dev);
127 
140 int16_t sht2x_read_temperature(const sht2x_t* dev);
141 
154 uint16_t sht2x_read_humidity(const sht2x_t *dev);
155 
167 int sht2x_read_ident(const sht2x_t *dev, uint8_t *buffer, size_t buflen);
168 
179 int sht2x_read_userreg(const sht2x_t *dev, uint8_t *userreg);
180 
190 int sht2x_write_userreg(const sht2x_t *dev, uint8_t userreg);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* SHT2X_H */
197 
SHT2X_RES_11_11BIT
@ SHT2X_RES_11_11BIT
RH=11bit, T=11bit.
Definition: sht2x.h:62
sht2x_read_humidity
uint16_t sht2x_read_humidity(const sht2x_t *dev)
Read humidity value from the given SHT2X device, returned in centi RH.
sht2x_res_t
sht2x_res_t
Available resolutions.
Definition: sht2x.h:58
sht2x_params_t::is_crc_enabled
bool is_crc_enabled
do CRC or not
Definition: sht2x.h:94
sht2x_params_t
Device initialization parameters.
Definition: sht2x.h:89
SHT2X_OK
@ SHT2X_OK
everything was fine
Definition: sht2x.h:41
SHT2X_ERR_TIMEDOUT
@ SHT2X_ERR_TIMEDOUT
timed out
Definition: sht2x.h:46
sht2x_params_t::i2c_dev
i2c_t i2c_dev
I2C device
Definition: sht2x.h:90
SHT2X_RES_8_12BIT
@ SHT2X_RES_8_12BIT
RH= 8bit, T=12bit.
Definition: sht2x.h:60
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
sht2x_init
int sht2x_init(sht2x_t *dev, const sht2x_params_t *params)
Initialize the given SHT2X device.
sht2x_read_ident
int sht2x_read_ident(const sht2x_t *dev, uint8_t *buffer, size_t buflen)
Read identification code from the given SHT2X device.
sht2x_t
Device descriptor for the SHT2X sensor.
Definition: sht2x.h:100
sht2x_params_t::measure_mode
sht2x_measure_mode_t measure_mode
measurement mode used
Definition: sht2x.h:93
SHT2X_ERR_OTHER
@ SHT2X_ERR_OTHER
fatal error
Definition: sht2x.h:50
sht2x_read_temperature
int16_t sht2x_read_temperature(const sht2x_t *dev)
Read temperature value from the given SHT2X device, returned in centi °C.
sht2x_params_t::i2c_addr
uint8_t i2c_addr
I2C address
Definition: sht2x.h:91
SHT2X_RES_10_13BIT
@ SHT2X_RES_10_13BIT
RH=10bit, T=13bit.
Definition: sht2x.h:61
SHT2X_ERR_I2C
@ SHT2X_ERR_I2C
error initializing the I2C bus
Definition: sht2x.h:42
SHT2X_MEASURE_MODE_NO_HOLD
@ SHT2X_MEASURE_MODE_NO_HOLD
trigger measurement, no hold master (i.e.
Definition: sht2x.h:70
SHT2X_ERR_CRC
@ SHT2X_ERR_CRC
CRC error.
Definition: sht2x.h:47
SHT2X_ERR_NODEV
@ SHT2X_ERR_NODEV
did not detect SHT2x
Definition: sht2x.h:43
SHT2X_RES_12_14BIT
@ SHT2X_RES_12_14BIT
RH=12bit, T=14bit.
Definition: sht2x.h:59
sht2x_write_userreg
int sht2x_write_userreg(const sht2x_t *dev, uint8_t userreg)
Write User Register to the given SHT2X device.
SHT2X_MEASURE_MODE_HOLD
@ SHT2X_MEASURE_MODE_HOLD
trigger measurement, hold master
Definition: sht2x.h:69
sht2x_t::params
sht2x_params_t params
Device Parameters.
Definition: sht2x.h:101
sht2x_reset
int sht2x_reset(sht2x_t *dev)
Reset the SHT2X device.
SHT2X_ERR_NOCAL
@ SHT2X_ERR_NOCAL
could not read calibration data
Definition: sht2x.h:44
sht2x_read_userreg
int sht2x_read_userreg(const sht2x_t *dev, uint8_t *userreg)
Read User Register from the given SHT2X device.
sht2x_measure_mode_t
sht2x_measure_mode_t
Available Measuring modes.
Definition: sht2x.h:68
i2c.h
Low-level I2C peripheral driver interface definition.
SHT2X_ERR_I2C_READ
@ SHT2X_ERR_I2C_READ
I2C read error.
Definition: sht2x.h:45
SHT2X_ERR_USERREG
@ SHT2X_ERR_USERREG
cannot write User Reg
Definition: sht2x.h:48
SHT2X_ERR_RES
@ SHT2X_ERR_RES
invalid resolution
Definition: sht2x.h:49
sht2x_params_t::resolution
sht2x_res_t resolution
resolution bits RH/temp
Definition: sht2x.h:92