sht1x 2.0.0.0
sht1x.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef SHT1X_H
36#define SHT1X_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define SHT1X_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl= MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda= MIKROBUS( mikrobus, MIKROBUS_SDA )
68
75#define SHT1X_RETVAL uint8_t
76
77#define SHT1X_OK 0x00
78#define SHT1X_INIT_ERROR 0xFF
85#define SHT1X_MEAS_TEMP 0x03
86#define SHT1X_MEAS_HUMI 0x05
87#define SHT1X_STAT_REG_W 0x06
88#define SHT1X_STAT_REG_R 0x07
89#define SHT1X_SOFT_RESET 0x1E
96#define SHT1X_SR_MASK 0x07
103#define SHT1X_NACK 0
104#define SHT1X_ACK 1
111#define SHT1X_D1 -40.1
112#define SHT1X_D2h 0.01
113#define SHT1X_D2l 0.04
114#define SHT1X_V3_C1 -4.0000
115#define SHT1X_V3_C2h 0.0405
116#define SHT1X_V3_C3h -2.8000E-6
117#define SHT1X_V3_C2l 0.6480
118#define SHT1X_V3_C3l -7.2000E-4
119#define SHT1X_V4_C1 -2.0468
120#define SHT1X_V4_C2h 0.0367
121#define SHT1X_V4_C3h -1.5955E-6
122#define SHT1X_V4_C2l 0.5872
123#define SHT1X_V4_C3l -4.0845E-4
124#define SHT1X_T1 0.01
125#define SHT1X_T2h 0.00008
126#define SHT1X_T2l 0.00128
131 // End group macro
132// --------------------------------------------------------------- PUBLIC TYPES
141typedef struct
142{
143 // Output pins
144
145 digital_out_t scl;
146 digital_out_t sda;
147
148} sht1x_t;
149
153typedef struct
154{
155 // Additional gpio pins
156
157 pin_name_t scl;
158 pin_name_t sda;
159
161
162 // End types group
163// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164
170#ifdef __cplusplus
171extern "C"{
172#endif
173
183
192
202
212
221
229void sht1x_sda_low ( sht1x_t *ctx );
230
242uint8_t sht1x_get_sda ( sht1x_t *ctx );
243
252
260void sht1x_scl_low ( sht1x_t *ctx );
261
272float sht1x_calc_temp ( sht1x_t *ctx, uint16_t t );
273
285float sht1x_calc_humi ( sht1x_t *ctx, uint16_t h, uint16_t t );
286
287#ifdef __cplusplus
288}
289#endif
290#endif // _SHT1X_H_
291
292 // End public_function group
294
295// ------------------------------------------------------------------------- END
#define SHT1X_RETVAL
Definition sht1x.h:75
void sht1x_scl_low(sht1x_t *ctx)
Set SCL low function.
float sht1x_calc_temp(sht1x_t *ctx, uint16_t t)
Calculate temperature function.
void sht1x_sda_low(sht1x_t *ctx)
Set SDA low function.
void sht1x_cfg_setup(sht1x_cfg_t *cfg)
Config Object Initialization function.
void sht1x_input_sda(sht1x_t *ctx, sht1x_cfg_t *cfg)
Set pin on input.
void sht1x_sda_high(sht1x_t *ctx)
Set SDA high function.
uint8_t sht1x_get_sda(sht1x_t *ctx)
Check SDA state function.
void sht1x_scl_high(sht1x_t *ctx)
Set SCL high function.
SHT1X_RETVAL sht1x_init(sht1x_t *ctx, sht1x_cfg_t *cfg)
Initialization function.
float sht1x_calc_humi(sht1x_t *ctx, uint16_t h, uint16_t t)
Calculate humidity function.
void sht1x_output_sda(sht1x_t *ctx, sht1x_cfg_t *cfg)
Set pin on output.
Click configuration structure definition.
Definition sht1x.h:154
pin_name_t scl
Definition sht1x.h:157
pin_name_t sda
Definition sht1x.h:158
Click ctx object definition.
Definition sht1x.h:142
digital_out_t sda
Definition sht1x.h:146
digital_out_t scl
Definition sht1x.h:145