Loading...
Searching...
No Matches
sht2x.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016-2018 Kees Bakker, SODAQ
3 * SPDX-FileCopyrightText: 2017 George Psimenos
4 * SPDX-FileCopyrightText: 2018 Steffen Robertz
5 * SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8#pragma once
9
24
25#include <stdint.h>
26#include <stdbool.h>
27#include "periph/i2c.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36enum {
47};
48
60
68
75#define SHT2X_USER_RESOLUTION_MASK 0x81
76#define SHT2X_USER_EOB_MASK 0x40
77#define SHT2X_USER_HEATER_MASK 0x04
78#define SHT2X_USER_RESERVED_MASK 0x38
79#define SHT2X_USER_OTP_MASK 0x02
81
92
96typedef struct {
98} sht2x_t;
99
112int sht2x_init(sht2x_t* dev, const sht2x_params_t* params);
113
123
136int16_t sht2x_read_temperature(const sht2x_t* dev);
137
150uint16_t sht2x_read_humidity(const sht2x_t *dev);
151
163int sht2x_read_ident(const sht2x_t *dev, uint8_t *buffer, size_t buflen);
164
175int sht2x_read_userreg(const sht2x_t *dev, uint8_t *userreg);
176
186int sht2x_write_userreg(const sht2x_t *dev, uint8_t userreg);
187
188#ifdef __cplusplus
189}
190#endif
191
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
sht2x_measure_mode_t
Available Measuring modes.
Definition sht2x.h:64
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:54
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:65
@ SHT2X_MEASURE_MODE_NO_HOLD
trigger measurement, no hold master (i.e.
Definition sht2x.h:66
@ SHT2X_RES_8_12BIT
RH= 8bit, T=12bit.
Definition sht2x.h:56
@ SHT2X_RES_12_14BIT
RH=12bit, T=14bit.
Definition sht2x.h:55
@ SHT2X_RES_11_11BIT
RH=11bit, T=11bit.
Definition sht2x.h:58
@ SHT2X_RES_10_13BIT
RH=10bit, T=13bit.
Definition sht2x.h:57
@ SHT2X_ERR_USERREG
cannot write User Reg
Definition sht2x.h:44
@ SHT2X_OK
everything was fine
Definition sht2x.h:37
@ SHT2X_ERR_OTHER
fatal error
Definition sht2x.h:46
@ SHT2X_ERR_I2C_READ
I2C read error.
Definition sht2x.h:41
@ SHT2X_ERR_RES
invalid resolution
Definition sht2x.h:45
@ SHT2X_ERR_NOCAL
could not read calibration data
Definition sht2x.h:40
@ SHT2X_ERR_CRC
CRC error.
Definition sht2x.h:43
@ SHT2X_ERR_NODEV
did not detect SHT2x
Definition sht2x.h:39
@ SHT2X_ERR_I2C
error initializing the I2C bus
Definition sht2x.h:38
@ SHT2X_ERR_TIMEDOUT
timed out
Definition sht2x.h:42
Low-level I2C peripheral driver interface definition.
Device initialization parameters.
Definition sht2x.h:85
sht2x_measure_mode_t measure_mode
measurement mode used
Definition sht2x.h:89
bool is_crc_enabled
do CRC or not
Definition sht2x.h:90
i2c_t i2c_dev
I2C device.
Definition sht2x.h:86
uint8_t i2c_addr
I2C address.
Definition sht2x.h:87
sht2x_res_t resolution
resolution bits RH/temp
Definition sht2x.h:88
Device descriptor for the SHT2X sensor.
Definition sht2x.h:96
sht2x_params_t params
Device Parameters.
Definition sht2x.h:97