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 
11 #pragma once
12 
28 #include <stdint.h>
29 #include <stdbool.h>
30 #include "periph/i2c.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
39 enum {
40  SHT2X_OK = 0,
49  SHT2X_ERR_OTHER = -999,
50 };
51 
57 typedef enum {
62 } sht2x_res_t;
63 
67 typedef enum {
71 
78 #define SHT2X_USER_RESOLUTION_MASK 0x81
79 #define SHT2X_USER_EOB_MASK 0x40
80 #define SHT2X_USER_HEATER_MASK 0x04
81 #define SHT2X_USER_RESERVED_MASK 0x38
82 #define SHT2X_USER_OTP_MASK 0x02
88 typedef struct {
90  uint8_t i2c_addr;
95 
99 typedef struct {
101 } sht2x_t;
102 
115 int sht2x_init(sht2x_t* dev, const sht2x_params_t* params);
116 
126 
139 int16_t sht2x_read_temperature(const sht2x_t* dev);
140 
153 uint16_t sht2x_read_humidity(const sht2x_t *dev);
154 
166 int sht2x_read_ident(const sht2x_t *dev, uint8_t *buffer, size_t buflen);
167 
178 int sht2x_read_userreg(const sht2x_t *dev, uint8_t *userreg);
179 
189 int sht2x_write_userreg(const sht2x_t *dev, uint8_t userreg);
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:144
sht2x_measure_mode_t
Available Measuring modes.
Definition: sht2x.h:67
int16_t sht2x_read_temperature(const sht2x_t *dev)
Read temperature value from the given SHT2X device, returned in centi °C.
int sht2x_read_userreg(const sht2x_t *dev, uint8_t *userreg)
Read User Register from the given SHT2X device.
uint16_t sht2x_read_humidity(const sht2x_t *dev)
Read humidity value from the given SHT2X device, returned in centi RH.
sht2x_res_t
Available resolutions.
Definition: sht2x.h:57
int sht2x_write_userreg(const sht2x_t *dev, uint8_t userreg)
Write User Register to the given SHT2X device.
int sht2x_reset(sht2x_t *dev)
Reset the SHT2X device.
int sht2x_read_ident(const sht2x_t *dev, uint8_t *buffer, size_t buflen)
Read identification code from the given SHT2X device.
int sht2x_init(sht2x_t *dev, const sht2x_params_t *params)
Initialize the given SHT2X device.
@ SHT2X_MEASURE_MODE_HOLD
trigger measurement, hold master
Definition: sht2x.h:68
@ SHT2X_MEASURE_MODE_NO_HOLD
trigger measurement, no hold master (i.e.
Definition: sht2x.h:69
@ SHT2X_RES_8_12BIT
RH= 8bit, T=12bit.
Definition: sht2x.h:59
@ SHT2X_RES_12_14BIT
RH=12bit, T=14bit.
Definition: sht2x.h:58
@ SHT2X_RES_11_11BIT
RH=11bit, T=11bit.
Definition: sht2x.h:61
@ SHT2X_RES_10_13BIT
RH=10bit, T=13bit.
Definition: sht2x.h:60
@ SHT2X_ERR_USERREG
cannot write User Reg
Definition: sht2x.h:47
@ SHT2X_OK
everything was fine
Definition: sht2x.h:40
@ SHT2X_ERR_OTHER
fatal error
Definition: sht2x.h:49
@ SHT2X_ERR_I2C_READ
I2C read error.
Definition: sht2x.h:44
@ SHT2X_ERR_RES
invalid resolution
Definition: sht2x.h:48
@ SHT2X_ERR_NOCAL
could not read calibration data
Definition: sht2x.h:43
@ SHT2X_ERR_CRC
CRC error.
Definition: sht2x.h:46
@ SHT2X_ERR_NODEV
did not detect SHT2x
Definition: sht2x.h:42
@ SHT2X_ERR_I2C
error initializing the I2C bus
Definition: sht2x.h:41
@ SHT2X_ERR_TIMEDOUT
timed out
Definition: sht2x.h:45
Low-level I2C peripheral driver interface definition.
Device initialization parameters.
Definition: sht2x.h:88
sht2x_measure_mode_t measure_mode
measurement mode used
Definition: sht2x.h:92
bool is_crc_enabled
do CRC or not
Definition: sht2x.h:93
i2c_t i2c_dev
I2C device
Definition: sht2x.h:89
uint8_t i2c_addr
I2C address
Definition: sht2x.h:90
sht2x_res_t resolution
resolution bits RH/temp
Definition: sht2x.h:91
Device descriptor for the SHT2X sensor.
Definition: sht2x.h:99
sht2x_params_t params
Device Parameters.
Definition: sht2x.h:100