temphum22  2.1.0.0
temphum22.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef TEMPHUM22_H
29 #define TEMPHUM22_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define TEMPHUM22_CMD_MEAS_TH_HIGH_PREC 0xFD
74 #define TEMPHUM22_CMD_MEAS_TH_MED_PREC 0xF6
75 #define TEMPHUM22_CMD_MEAS_TH_LOW_PREC 0xE0
76 #define TEMPHUM22_CMD_READ_SERIAL_NUM 0x89
77 #define TEMPHUM22_CMD_SOFT_RESET 0x94
78 #define TEMPHUM22_CMD_ACT_HEATER_200mW_1S 0x39
79 #define TEMPHUM22_CMD_ACT_HEATER_200mW_0p1S 0x32
80 #define TEMPHUM22_CMD_ACT_HEATER_110mW_1S 0x2F
81 #define TEMPHUM22_CMD_ACT_HEATER_110mW_0p1S 0x24
82 #define TEMPHUM22_CMD_ACT_HEATER_20mW_1S 0x1E
83 #define TEMPHUM22_CMD_ACT_HEATER_20mW_0p1S 0x15
84  // temphum22_reg
86 
101 #define TEMPHUM22_MAX_RH 100.0
102 #define TEMPHUM22_MIN_RH 0.0
103 #define TEMPHUM22_DATA_RESOLUTION 65535.0
104 #define TEMPHUM22_ABS_MIN_TEMP ( -45.0 )
105 #define TEMPHUM22_ABS_MAX_TEMP ( 130.0 )
106 #define TEMPHUM22_ABS_MIN_HUM ( -6.0 )
107 #define TEMPHUM22_ABS_MAX_HUM ( 119.0 )
108 
114 #define TEMPHUM22_DEVICE_ADDRESS 0x44
115  // temphum22_set
117 
132 #define TEMPHUM22_MAP_MIKROBUS( cfg, mikrobus ) \
133  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
134  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
135  // temphum22_map // temphum22
138 
143 typedef struct
144 {
145  // Modules
146  i2c_master_t i2c;
148  // I2C slave address
149  uint8_t slave_address;
151 } temphum22_t;
152 
157 typedef struct
158 {
159  pin_name_t scl;
160  pin_name_t sda;
162  uint32_t i2c_speed;
163  uint8_t i2c_address;
166 
171 typedef enum
172 {
174  TEMPHUM22_ERROR = -1
175 
177 
194 
209 
221 err_t temphum22_send_cmd ( temphum22_t *ctx, uint8_t cmd );
222 
235 err_t temphum22_read_response ( temphum22_t *ctx, uint8_t *data_out );
236 
248 
260 err_t temphum22_read_serial_num ( temphum22_t *ctx, uint32_t *serial_num );
261 
274 err_t temphum22_read_measurement_high_precision ( temphum22_t *ctx, float *temp, float *hum );
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // TEMPHUM22_H
280  // temphum22
282 
283 // ------------------------------------------------------------------------ END
temphum22_send_cmd
err_t temphum22_send_cmd(temphum22_t *ctx, uint8_t cmd)
TempHum 22 send cmd function.
temphum22_cfg_t::scl
pin_name_t scl
Definition: temphum22.h:159
temphum22_t::slave_address
uint8_t slave_address
Definition: temphum22.h:149
temphum22_cfg_t
TempHum 22 Click configuration object.
Definition: temphum22.h:158
temphum22_cfg_setup
void temphum22_cfg_setup(temphum22_cfg_t *cfg)
TempHum 22 configuration object setup function.
TEMPHUM22_ERROR
@ TEMPHUM22_ERROR
Definition: temphum22.h:174
temphum22_read_serial_num
err_t temphum22_read_serial_num(temphum22_t *ctx, uint32_t *serial_num)
TempHum 22 read serial num function.
temphum22_init
err_t temphum22_init(temphum22_t *ctx, temphum22_cfg_t *cfg)
TempHum 22 initialization function.
temphum22_read_measurement_high_precision
err_t temphum22_read_measurement_high_precision(temphum22_t *ctx, float *temp, float *hum)
TempHum 22 read measurement high precision function.
temphum22_return_value_t
temphum22_return_value_t
TempHum 22 Click return value data.
Definition: temphum22.h:172
temphum22_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum22.h:163
temphum22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum22.h:162
temphum22_cfg_t::sda
pin_name_t sda
Definition: temphum22.h:160
TEMPHUM22_OK
@ TEMPHUM22_OK
Definition: temphum22.h:173
temphum22_t::i2c
i2c_master_t i2c
Definition: temphum22.h:146
temphum22_read_response
err_t temphum22_read_response(temphum22_t *ctx, uint8_t *data_out)
TempHum 22 read response function.
temphum22_t
TempHum 22 Click context object.
Definition: temphum22.h:144
temphum22_soft_reset
err_t temphum22_soft_reset(temphum22_t *ctx)
TempHum 22 soft reset function.