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 )
71 
77 #define SHT_OK 0x00
78 #define SHT_ERROR 0xFF
79 
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
93 
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
104 
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
118  // End group macro
121 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  uint8_t clk_stretching;
130  uint8_t repeatability;
131  uint8_t mps;
132 
134 
138 typedef 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
150  uint8_t slave_address;
151 
152  // driver variables
154 
155 } sht_t;
156 
160 typedef 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  // End types group
180 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
199 void sht_cfg_setup ( sht_cfg_t *cfg );
200 
209 err_t sht_init ( sht_t *ctx, sht_cfg_t *cfg );
210 
221 void sht_generic_write ( sht_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
222 
233 void sht_generic_read ( sht_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len );
234 
242 void sht_reset ( sht_t *ctx );
243 
251 void sht_hw_reset ( sht_t *ctx );
252 
260 uint8_t sht_int_get ( sht_t *ctx );
261 
270 void sht_rst_set ( sht_t *ctx, uint8_t state );
271 
289 void sht_set_clk_strecth ( sht_t *ctx, uint8_t clk_stretching );
290 
301 void sht_set_repeats ( sht_t *ctx, uint8_t repeatability );
302 
323 void sht_set_mps ( sht_t *ctx, uint8_t measure_per_second );
324 
334 float sht_temp_ss ( sht_t *ctx );
335 
343 float sht_hum_ss ( sht_t *ctx );
344 
352 void sht_start_pm ( sht_t *ctx );
353 
368 float sht_temp_pm ( sht_t *ctx );
369 
384 float sht_hum_pm ( sht_t *ctx );
385 
394 void sht_stop_pm ( sht_t *ctx );
395 
405 void sht_software_rst ( sht_t *ctx );
406 
418 void sht_heater_control ( sht_t *ctx, uint8_t state );
419 
429 void sht_clear_status ( sht_t *ctx );
430 
441 uint8_t sht_alert_status ( sht_t *ctx );
442 
452 uint8_t sht_heater_status ( sht_t *ctx );
453 
463 uint8_t sht_hum_status ( sht_t *ctx );
464 
474 uint8_t sht_temp_status ( sht_t *ctx );
475 
486 uint8_t sht_reset_status ( sht_t *ctx );
487 
497 uint8_t sht_cmd_status ( sht_t *ctx );
498 
508 uint8_t sht_wr_chksum_status ( sht_t *ctx );
509 
510 
511 #ifdef __cplusplus
512 }
513 #endif
514 #endif // _SHT_H_
515  // End public_function group
518 
519 // ------------------------------------------------------------------------- END
sht_t::i2c
i2c_master_t i2c
Definition: sht.h:147
sht_cfg_setup
void sht_cfg_setup(sht_cfg_t *cfg)
Config Object Initialization function.
sht_t
Click ctx object definition.
Definition: sht.h:139
sht_cfg_t::scl
pin_name_t scl
Definition: sht.h:163
sht_t::vars
drv_variables_t vars
Definition: sht.h:153
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:171
drv_variables_t::repeatability
uint8_t repeatability
Definition: sht.h:130
sht_cfg_t::rst
pin_name_t rst
Definition: sht.h:167
sht_start_pm
void sht_start_pm(sht_t *ctx)
Start Periodic Measurement.
sht_t::slave_address
uint8_t slave_address
Definition: sht.h:150
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:161
sht_hum_pm
float sht_hum_pm(sht_t *ctx)
Periodic Mode Humidity.
sht_t::rst
digital_out_t rst
Definition: sht.h:141
sht_cfg_t::int_pin
pin_name_t int_pin
Definition: sht.h:168
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:128
sht_cfg_t::vars_cfg
drv_variables_t vars_cfg
Definition: sht.h:175
sht_clear_status
void sht_clear_status(sht_t *ctx)
Clears Status Register.
sht_cfg_t::sda
pin_name_t sda
Definition: sht.h:164
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:144
sht_cfg_t::i2c_address
uint8_t i2c_address
Definition: sht.h:172
drv_variables_t::mps
uint8_t mps
Definition: sht.h:131
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:129