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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define TEMPHUM22_CMD_MEAS_TH_HIGH_PREC 0xFD
70 #define TEMPHUM22_CMD_MEAS_TH_MED_PREC 0xF6
71 #define TEMPHUM22_CMD_MEAS_TH_LOW_PREC 0xE0
72 #define TEMPHUM22_CMD_READ_SERIAL_NUM 0x89
73 #define TEMPHUM22_CMD_SOFT_RESET 0x94
74 #define TEMPHUM22_CMD_ACT_HEATER_200mW_1S 0x39
75 #define TEMPHUM22_CMD_ACT_HEATER_200mW_0p1S 0x32
76 #define TEMPHUM22_CMD_ACT_HEATER_110mW_1S 0x2F
77 #define TEMPHUM22_CMD_ACT_HEATER_110mW_0p1S 0x24
78 #define TEMPHUM22_CMD_ACT_HEATER_20mW_1S 0x1E
79 #define TEMPHUM22_CMD_ACT_HEATER_20mW_0p1S 0x15
80  // temphum22_reg
82 
97 #define TEMPHUM22_MAX_RH 100.0
98 #define TEMPHUM22_MIN_RH 0.0
99 #define TEMPHUM22_DATA_RESOLUTION 65535.0
100 #define TEMPHUM22_ABS_MIN_TEMP ( -45.0 )
101 #define TEMPHUM22_ABS_MAX_TEMP ( 130.0 )
102 #define TEMPHUM22_ABS_MIN_HUM ( -6.0 )
103 #define TEMPHUM22_ABS_MAX_HUM ( 119.0 )
104 
110 #define TEMPHUM22_DEVICE_ADDRESS 0x44
111  // temphum22_set
113 
128 #define TEMPHUM22_MAP_MIKROBUS( cfg, mikrobus ) \
129  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
130  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
131  // temphum22_map // temphum22
134 
139 typedef struct
140 {
141  // Modules
142  i2c_master_t i2c;
144  // I2C slave address
145  uint8_t slave_address;
147 } temphum22_t;
148 
153 typedef struct
154 {
155  pin_name_t scl;
156  pin_name_t sda;
158  uint32_t i2c_speed;
159  uint8_t i2c_address;
162 
167 typedef enum
168 {
170  TEMPHUM22_ERROR = -1
171 
173 
190 
205 
217 err_t temphum22_send_cmd ( temphum22_t *ctx, uint8_t cmd );
218 
231 err_t temphum22_read_response ( temphum22_t *ctx, uint8_t *data_out );
232 
244 
256 err_t temphum22_read_serial_num ( temphum22_t *ctx, uint32_t *serial_num );
257 
270 err_t temphum22_read_measurement_high_precision ( temphum22_t *ctx, float *temp, float *hum );
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 #endif // TEMPHUM22_H
276  // temphum22
278 
279 // ------------------------------------------------------------------------ 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:155
temphum22_t::slave_address
uint8_t slave_address
Definition: temphum22.h:145
temphum22_cfg_t
TempHum 22 Click configuration object.
Definition: temphum22.h:154
temphum22_cfg_setup
void temphum22_cfg_setup(temphum22_cfg_t *cfg)
TempHum 22 configuration object setup function.
TEMPHUM22_ERROR
@ TEMPHUM22_ERROR
Definition: temphum22.h:170
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:168
temphum22_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum22.h:159
temphum22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum22.h:158
temphum22_cfg_t::sda
pin_name_t sda
Definition: temphum22.h:156
TEMPHUM22_OK
@ TEMPHUM22_OK
Definition: temphum22.h:169
temphum22_t::i2c
i2c_master_t i2c
Definition: temphum22.h:142
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:140
temphum22_soft_reset
err_t temphum22_soft_reset(temphum22_t *ctx)
TempHum 22 soft reset function.