sht 2.0.0.0
sht.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 SHT_H
36#define SHT_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#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define SHT_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define SHT_OK 0x00
78#define SHT_ERROR 0xFF
81#define SHT_I2C_ADDR0 0x44
82#define SHT_I2C_ADDR1 0x45
83
88#define SHT_MPS_05 0x20 // 0.5 measurements per second
89#define SHT_MPS_1 0x21 // 1 measurements per second
90#define SHT_MPS_2 0x22 // 2 measurements per second
91#define SHT_MPS_4 0x23 // 4 measurements per second
92#define SHT_MPS_10 0x27 // 10 measurements per second
99#define SHT_RPT_HIGH 0 // High repeatability
100#define SHT_RPT_MEDIUM 1 // Medium repeatability
101#define SHT_RPT_LOW 2 // Low repeatability
102#define SHT_STR_ENABLE 0x2C // Stretching enabled
103#define SHT_STR_DISABLE 0x24 // Stretching disabled
110#define SHT_CRC_POLYNOMIAL 0x31
111#define SHT_FETCH_DATA 0xE000
112#define SHT_PERIODIC_ART 0x2B32
113#define SHT_BREAK 0x3093
114#define SHT_SOFT_RESET 0x30A2
115#define SHT_HEATER 0x30
116#define SHT_READ_STATUS 0xF32D
117#define SHT_CLEAR_STATUS1 0x3041
120 // End group macro
121// --------------------------------------------------------------- PUBLIC TYPES
127typedef struct
128{
131 uint8_t mps;
132
134
138typedef struct
139{
140 // Output pins
141 digital_out_t rst;
142
143 // Input pins
144 digital_in_t int_pin;
145
146 // Modules
147 i2c_master_t i2c;
148
149 // ctx variable
151
152 // driver variables
154
155} sht_t;
156
160typedef struct
161{
162 // Communication gpio pins
163 pin_name_t scl;
164 pin_name_t sda;
165
166 // Additional gpio pins
167 pin_name_t rst;
168 pin_name_t int_pin;
169
170 // static variable
171 uint32_t i2c_speed;
172 uint8_t i2c_address;
173
174 // driver variables config
176
177} sht_cfg_t;
178
179 // End types group
180// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181
187#ifdef __cplusplus
188extern "C"{
189#endif
190
200
209err_t sht_init ( sht_t *ctx, sht_cfg_t *cfg );
210
221void sht_generic_write ( sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
222
233void sht_generic_read ( sht_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len );
234
242void sht_reset ( sht_t *ctx );
243
251void sht_hw_reset ( sht_t *ctx );
252
260uint8_t sht_int_get ( sht_t *ctx );
261
270void sht_rst_set ( sht_t *ctx, uint8_t state );
271
289void sht_set_clk_strecth ( sht_t *ctx, uint8_t clk_stretching );
290
301void sht_set_repeats ( sht_t *ctx, uint8_t repeatability );
302
323void sht_set_mps ( sht_t *ctx, uint8_t measure_per_second );
324
334float sht_temp_ss ( sht_t *ctx );
335
343float sht_hum_ss ( sht_t *ctx );
344
352void sht_start_pm ( sht_t *ctx );
353
368float sht_temp_pm ( sht_t *ctx );
369
384float sht_hum_pm ( sht_t *ctx );
385
394void sht_stop_pm ( sht_t *ctx );
395
406
418void sht_heater_control ( sht_t *ctx, uint8_t state );
419
430
441uint8_t sht_alert_status ( sht_t *ctx );
442
452uint8_t sht_heater_status ( sht_t *ctx );
453
463uint8_t sht_hum_status ( sht_t *ctx );
464
474uint8_t sht_temp_status ( sht_t *ctx );
475
486uint8_t sht_reset_status ( sht_t *ctx );
487
497uint8_t sht_cmd_status ( sht_t *ctx );
498
509
510
511#ifdef __cplusplus
512}
513#endif
514#endif // _SHT_H_
515
516 // End public_function group
518
519// ------------------------------------------------------------------------- END
void sht_hw_reset(sht_t *ctx)
Resets device.
void sht_rst_set(sht_t *ctx, uint8_t state)
Int status.
uint8_t sht_cmd_status(sht_t *ctx)
Command Status.
void sht_heater_control(sht_t *ctx, uint8_t state)
Heater State.
void sht_generic_write(sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void sht_software_rst(sht_t *ctx)
Software Reset.
float sht_temp_ss(sht_t *ctx)
Single Shot Temperature Measurement.
uint8_t sht_reset_status(sht_t *ctx)
System Reset.
uint8_t sht_wr_chksum_status(sht_t *ctx)
Checksum Status.
void sht_stop_pm(sht_t *ctx)
Stop Periodic Measurement.
void sht_start_pm(sht_t *ctx)
Start Periodic Measurement.
uint8_t sht_int_get(sht_t *ctx)
Int status.
void sht_reset(sht_t *ctx)
Resets settings.
uint8_t sht_alert_status(sht_t *ctx)
Alert Status.
float sht_hum_pm(sht_t *ctx)
Periodic Mode Humidity.
uint8_t sht_heater_status(sht_t *ctx)
Heater State.
void sht_generic_read(sht_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float sht_hum_ss(sht_t *ctx)
Single Shot Humidity Measurement.
void sht_clear_status(sht_t *ctx)
Clears Status Register.
err_t sht_init(sht_t *ctx, sht_cfg_t *cfg)
Initialization function.
void sht_set_repeats(sht_t *ctx, uint8_t repeatability)
Sets the repeatability value.
void sht_set_clk_strecth(sht_t *ctx, uint8_t clk_stretching)
Sets the clock stretching state.
void sht_set_mps(sht_t *ctx, uint8_t measure_per_second)
Measurements per Second.
uint8_t sht_temp_status(sht_t *ctx)
Temperature Alert.
void sht_cfg_setup(sht_cfg_t *cfg)
Config Object Initialization function.
float sht_temp_pm(sht_t *ctx)
Periodic Mode Temperature.
uint8_t sht_hum_status(sht_t *ctx)
Humidity Alert.
Definition sht.h:128
uint8_t clk_stretching
Definition sht.h:129
uint8_t repeatability
Definition sht.h:130
uint8_t mps
Definition sht.h:131
Click configuration structure definition.
Definition sht.h:161
drv_variables_t vars_cfg
Definition sht.h:175
uint32_t i2c_speed
Definition sht.h:171
pin_name_t scl
Definition sht.h:163
pin_name_t int_pin
Definition sht.h:168
pin_name_t sda
Definition sht.h:164
pin_name_t rst
Definition sht.h:167
uint8_t i2c_address
Definition sht.h:172
Click ctx object definition.
Definition sht.h:139
digital_in_t int_pin
Definition sht.h:144
i2c_master_t i2c
Definition sht.h:147
drv_variables_t vars
Definition sht.h:153
digital_out_t rst
Definition sht.h:141
uint8_t slave_address
Definition sht.h:150