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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SHT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define SHT_OK 0x00
64 #define SHT_ERROR 0xFF
65 
67 #define SHT_I2C_ADDR0 0x44
68 #define SHT_I2C_ADDR1 0x45
69 
74 #define SHT_MPS_05 0x20 // 0.5 measurements per second
75 #define SHT_MPS_1 0x21 // 1 measurements per second
76 #define SHT_MPS_2 0x22 // 2 measurements per second
77 #define SHT_MPS_4 0x23 // 4 measurements per second
78 #define SHT_MPS_10 0x27 // 10 measurements per second
79 
85 #define SHT_RPT_HIGH 0 // High repeatability
86 #define SHT_RPT_MEDIUM 1 // Medium repeatability
87 #define SHT_RPT_LOW 2 // Low repeatability
88 #define SHT_STR_ENABLE 0x2C // Stretching enabled
89 #define SHT_STR_DISABLE 0x24 // Stretching disabled
90 
96 #define SHT_CRC_POLYNOMIAL 0x31
97 #define SHT_FETCH_DATA 0xE000
98 #define SHT_PERIODIC_ART 0x2B32
99 #define SHT_BREAK 0x3093
100 #define SHT_SOFT_RESET 0x30A2
101 #define SHT_HEATER 0x30
102 #define SHT_READ_STATUS 0xF32D
103 #define SHT_CLEAR_STATUS1 0x3041
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  uint8_t clk_stretching;
116  uint8_t repeatability;
117  uint8_t mps;
118 
120 
124 typedef struct
125 {
126  // Output pins
127  digital_out_t rst;
128 
129  // Input pins
130  digital_in_t int_pin;
131 
132  // Modules
133  i2c_master_t i2c;
134 
135  // ctx variable
136  uint8_t slave_address;
137 
138  // driver variables
140 
141 } sht_t;
142 
146 typedef struct
147 {
148  // Communication gpio pins
149  pin_name_t scl;
150  pin_name_t sda;
151 
152  // Additional gpio pins
153  pin_name_t rst;
154  pin_name_t int_pin;
155 
156  // static variable
157  uint32_t i2c_speed;
158  uint8_t i2c_address;
159 
160  // driver variables config
162 
163 } sht_cfg_t;
164  // End types group
166 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
185 void sht_cfg_setup ( sht_cfg_t *cfg );
186 
195 err_t sht_init ( sht_t *ctx, sht_cfg_t *cfg );
196 
207 void sht_generic_write ( sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
208 
219 void sht_generic_read ( sht_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len );
220 
228 void sht_reset ( sht_t *ctx );
229 
237 void sht_hw_reset ( sht_t *ctx );
238 
246 uint8_t sht_int_get ( sht_t *ctx );
247 
256 void sht_rst_set ( sht_t *ctx, uint8_t state );
257 
275 void sht_set_clk_strecth ( sht_t *ctx, uint8_t clk_stretching );
276 
287 void sht_set_repeats ( sht_t *ctx, uint8_t repeatability );
288 
309 void sht_set_mps ( sht_t *ctx, uint8_t measure_per_second );
310 
320 float sht_temp_ss ( sht_t *ctx );
321 
329 float sht_hum_ss ( sht_t *ctx );
330 
338 void sht_start_pm ( sht_t *ctx );
339 
354 float sht_temp_pm ( sht_t *ctx );
355 
370 float sht_hum_pm ( sht_t *ctx );
371 
380 void sht_stop_pm ( sht_t *ctx );
381 
391 void sht_software_rst ( sht_t *ctx );
392 
404 void sht_heater_control ( sht_t *ctx, uint8_t state );
405 
415 void sht_clear_status ( sht_t *ctx );
416 
427 uint8_t sht_alert_status ( sht_t *ctx );
428 
438 uint8_t sht_heater_status ( sht_t *ctx );
439 
449 uint8_t sht_hum_status ( sht_t *ctx );
450 
460 uint8_t sht_temp_status ( sht_t *ctx );
461 
472 uint8_t sht_reset_status ( sht_t *ctx );
473 
483 uint8_t sht_cmd_status ( sht_t *ctx );
484 
494 uint8_t sht_wr_chksum_status ( sht_t *ctx );
495 
496 
497 #ifdef __cplusplus
498 }
499 #endif
500 #endif // _SHT_H_
501  // End public_function group
504 
505 // ------------------------------------------------------------------------- END
sht_t::i2c
i2c_master_t i2c
Definition: sht.h:133
sht_cfg_setup
void sht_cfg_setup(sht_cfg_t *cfg)
Config Object Initialization function.
sht_t
Click ctx object definition.
Definition: sht.h:125
sht_cfg_t::scl
pin_name_t scl
Definition: sht.h:149
sht_t::vars
drv_variables_t vars
Definition: sht.h:139
sht_init
err_t sht_init(sht_t *ctx, sht_cfg_t *cfg)
Initialization function.
sht_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: sht.h:157
drv_variables_t::repeatability
uint8_t repeatability
Definition: sht.h:116
sht_cfg_t::rst
pin_name_t rst
Definition: sht.h:153
sht_start_pm
void sht_start_pm(sht_t *ctx)
Start Periodic Measurement.
sht_t::slave_address
uint8_t slave_address
Definition: sht.h:136
sht_set_mps
void sht_set_mps(sht_t *ctx, uint8_t measure_per_second)
Measurements per Second.
sht_heater_status
uint8_t sht_heater_status(sht_t *ctx)
Heater State.
sht_temp_status
uint8_t sht_temp_status(sht_t *ctx)
Temperature Alert.
sht_reset
void sht_reset(sht_t *ctx)
Resets settings.
sht_hum_status
uint8_t sht_hum_status(sht_t *ctx)
Humidity Alert.
sht_hw_reset
void sht_hw_reset(sht_t *ctx)
Resets device.
sht_cfg_t
Click configuration structure definition.
Definition: sht.h:147
sht_hum_pm
float sht_hum_pm(sht_t *ctx)
Periodic Mode Humidity.
sht_t::rst
digital_out_t rst
Definition: sht.h:127
sht_cfg_t::int_pin
pin_name_t int_pin
Definition: sht.h:154
sht_software_rst
void sht_software_rst(sht_t *ctx)
Software Reset.
sht_generic_read
void sht_generic_read(sht_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len)
Generic read function.
sht_temp_ss
float sht_temp_ss(sht_t *ctx)
Single Shot Temperature Measurement.
sht_temp_pm
float sht_temp_pm(sht_t *ctx)
Periodic Mode Temperature.
sht_heater_control
void sht_heater_control(sht_t *ctx, uint8_t state)
Heater State.
sht_set_clk_strecth
void sht_set_clk_strecth(sht_t *ctx, uint8_t clk_stretching)
Sets the clock stretching state.
sht_alert_status
uint8_t sht_alert_status(sht_t *ctx)
Alert Status.
sht_set_repeats
void sht_set_repeats(sht_t *ctx, uint8_t repeatability)
Sets the repeatability value.
drv_variables_t
Definition: sht.h:114
sht_cfg_t::vars_cfg
drv_variables_t vars_cfg
Definition: sht.h:161
sht_clear_status
void sht_clear_status(sht_t *ctx)
Clears Status Register.
sht_cfg_t::sda
pin_name_t sda
Definition: sht.h:150
sht_rst_set
void sht_rst_set(sht_t *ctx, uint8_t state)
Int status.
sht_int_get
uint8_t sht_int_get(sht_t *ctx)
Int status.
sht_cmd_status
uint8_t sht_cmd_status(sht_t *ctx)
Command Status.
sht_reset_status
uint8_t sht_reset_status(sht_t *ctx)
System Reset.
sht_stop_pm
void sht_stop_pm(sht_t *ctx)
Stop Periodic Measurement.
sht_wr_chksum_status
uint8_t sht_wr_chksum_status(sht_t *ctx)
Checksum Status.
sht_t::int_pin
digital_in_t int_pin
Definition: sht.h:130
sht_cfg_t::i2c_address
uint8_t i2c_address
Definition: sht.h:158
drv_variables_t::mps
uint8_t mps
Definition: sht.h:117
sht_hum_ss
float sht_hum_ss(sht_t *ctx)
Single Shot Humidity Measurement.
sht_generic_write
void sht_generic_write(sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
drv_variables_t::clk_stretching
uint8_t clk_stretching
Definition: sht.h:115