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_RETVAL uint8_t
64 
65 #define SHT_OK 0x00
66 #define SHT_INIT_ERROR 0xFF
67 
69 #define SHT_I2C_ADDR0 0x44
70 #define SHT_I2C_ADDR1 0x45
71 
77 // 0.5 measurements per second
78 #define SHT_MPS_05 0x20
79 
80 // 1 measurements per second
81 #define SHT_MPS_1 0x21
82 
83 // 2 measurements per second
84 #define SHT_MPS_2 0x22
85 
86 // 4 measurements per second
87 #define SHT_MPS_4 0x23
88 
89 // 10 measurements per second
90 #define SHT_MPS_10 0x27
91 
98 // High repeatability
99 #define SHT_RPT_HIGH 0
100 
101 // Medium repeatability
102 #define SHT_RPT_MEDIUM 1
103 
104 // Low repeatability
105 #define SHT_RPT_LOW 2
106 
107 // Stretching enabled
108 #define SHT_STR_ENABLE 0x2C
109 
110 // Stretching disabled
111 #define SHT_STR_DISABLE 0x24
112 
119 #define SHT_CRC_POLYNOMIAL 0x31
120 #define SHT_FETCH_DATA 0xE000
121 #define SHT_PERIODIC_ART 0x2B32
122 #define SHT_BREAK 0x3093
123 #define SHT_SOFT_RESET 0x30A2
124 #define SHT_HEATER 0x30
125 #define SHT_READ_STATUS 0xF32D
126 #define SHT_CLEAR_STATUS1 0x3041
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
136 typedef struct
137 {
138  uint8_t clk_stretching;
139  uint8_t repeatability;
140  uint8_t mps;
141 
143 
144 
148 typedef struct
149 {
150  // Output pins
151 
152  digital_out_t rst;
153  // Input pins
154 
155  digital_in_t int_pin;
156 
157  // Modules
158 
159  i2c_master_t i2c;
160 
161  // ctx variable
162 
163  uint8_t slave_address;
164 
165  // driver variables
166 
168 
169 } sht_t;
170 
174 typedef struct
175 {
176  // Communication gpio pins
177 
178  pin_name_t scl;
179  pin_name_t sda;
180 
181  // Additional gpio pins
182 
183  pin_name_t rst;
184  pin_name_t int_pin;
185 
186  // static variable
187 
188  uint32_t i2c_speed;
189  uint8_t i2c_address;
190 
191  //driver variable's config
192 
194 
195 } sht_cfg_t;
196  // End types group
198 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
199 
205 #ifdef __cplusplus
206 extern "C"{
207 #endif
208 
217 void sht_cfg_setup ( sht_cfg_t *cfg );
218 
227 SHT_RETVAL sht_init ( sht_t *ctx, sht_cfg_t *cfg );
228 
239 void sht_generic_write ( sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240 
251 void sht_generic_read ( sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
252 
260 void sht_reset ( sht_t *ctx );
261 
269 void sht_hw_reset ( sht_t *ctx );
270 
278 uint8_t sht_int_get ( sht_t *ctx );
279 
288 void sht_rst_set ( sht_t *ctx, uint8_t state );
289 
307 void sht_set_clk_strecth ( sht_t *ctx, uint8_t clk_stretching );
308 
320 void sht_set_repeats ( sht_t *ctx, uint8_t repeatability );
321 
345 void sht_set_mps ( sht_t *ctx, uint8_t measure_per_second );
346 
356 float sht_temp_ss ( sht_t *ctx );
357 
365 float sht_hum_ss ( sht_t *ctx );
366 
374 void sht_start_pm ( sht_t *ctx );
375 
390 float sht_temp_pm ( sht_t *ctx );
391 
406 float sht_hum_pm ( sht_t *ctx );
407 
416 void sht_stop_pm ( sht_t *ctx );
417 
427 void sht_software_rst ( sht_t *ctx );
428 
440 void sht_heater_control ( sht_t *ctx, uint8_t state );
441 
451 void sht_clear_status ( sht_t *ctx );
452 
463 uint8_t sht_alert_status ( sht_t *ctx );
464 
475 uint8_t sht_heater_status ( sht_t *ctx );
476 
487 uint8_t sht_hum_status ( sht_t *ctx );
488 
501 uint8_t sht_temp_status ( sht_t *ctx );
502 
516 uint8_t sht_reset_status ( sht_t *ctx );
517 
530 uint8_t sht_cmd_status ( sht_t *ctx );
531 
544 uint8_t sht_wr_chksum_status ( sht_t *ctx );
545 
546 
547 #ifdef __cplusplus
548 }
549 #endif
550 #endif // _SHT_H_
551  // End public_function group
554 
555 // ------------------------------------------------------------------------- END
sht_t::i2c
i2c_master_t i2c
Definition: sht.h:159
sht_cfg_setup
void sht_cfg_setup(sht_cfg_t *cfg)
Config Object Initialization function.
sht_t
Click ctx object definition.
Definition: sht.h:148
sht_cfg_t::scl
pin_name_t scl
Definition: sht.h:178
sht_t::vars
drv_variables_t vars
Definition: sht.h:167
SHT_RETVAL
#define SHT_RETVAL
Definition: sht.h:63
sht_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: sht.h:188
drv_variables_t::repeatability
uint8_t repeatability
Definition: sht.h:139
sht_cfg_t::rst
pin_name_t rst
Definition: sht.h:183
sht_start_pm
void sht_start_pm(sht_t *ctx)
Start Periodic Measurement.
sht_t::slave_address
uint8_t slave_address
Definition: sht.h:163
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_init
SHT_RETVAL sht_init(sht_t *ctx, sht_cfg_t *cfg)
Initialization function.
sht_cfg_t
Click configuration structure definition.
Definition: sht.h:174
sht_hum_pm
float sht_hum_pm(sht_t *ctx)
Periodic Mode Humidity.
sht_t::rst
digital_out_t rst
Definition: sht.h:152
sht_cfg_t::int_pin
pin_name_t int_pin
Definition: sht.h:184
sht_software_rst
void sht_software_rst(sht_t *ctx)
Software Reset.
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)
drv_variables_t
Definition: sht.h:136
sht_cfg_t::vars_cfg
drv_variables_t vars_cfg
Definition: sht.h:193
sht_clear_status
void sht_clear_status(sht_t *ctx)
Clears Status Register.
sht_cfg_t::sda
pin_name_t sda
Definition: sht.h:179
sht_generic_read
void sht_generic_read(sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
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:155
sht_cfg_t::i2c_address
uint8_t i2c_address
Definition: sht.h:189
drv_variables_t::mps
uint8_t mps
Definition: sht.h:140
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:138