temphum14  2.0.0.0
temphum14.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 TEMPHUM14_H
29 #define TEMPHUM14_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 
75 #define TEMPHUM14_I2C_SLAVE_ADDR_GND 0x40
76 #define TEMPHUM14_I2C_SLAVE_ADDR_VCC 0x41
77 
82 #define TEMPHUM14_CMD_RESET 0x1E
83 #define TEMPHUM14_CMD_HEATER_ON 0x04
84 #define TEMPHUM14_CMD_HEATER_OFF 0x02
85 #define TEMPHUM14_CMD_READ_T_AND_RH 0x00
86 #define TEMPHUM14_CMD_READ_RH 0x10
87 #define TEMPHUM14_CMD_CONVERSION 0x40
88 #define TEMPHUM14_CMD_READ_DIAGNOSTIC 0x08
89 #define TEMPHUM14_CMD_READ_SERIAL_NUMBER 0x0A
90 
95 #define TEMPHUM14_CONVERSION_HUM_OSR_0_007 0x18
96 #define TEMPHUM14_CONVERSION_HUM_OSR_0_010 0x10
97 #define TEMPHUM14_CONVERSION_HUM_OSR_0_014 0x08
98 #define TEMPHUM14_CONVERSION_HUM_OSR_0_020 0x00
99 #define TEMPHUM14_CONVERSION_TEMP_0_012 0x06
100 #define TEMPHUM14_CONVERSION_TEMP_0_016 0x04
101 #define TEMPHUM14_CONVERSION_TEMP_0_025 0x02
102 #define TEMPHUM14_CONVERSION_TEMP_0_040 0x00
103 
108 #define TEMPHUM14_BIT_MASK_HUM_OSR 0x18
109 #define TEMPHUM14_BIT_MASK_TEMP_OSR 0x06
110 
115 #define TEMPHUM14_HEATER_DISABLE 0x00
116 #define TEMPHUM14_HEATER_ENABLE 0x01
117 
122 #define TEMPHUM14_STATUS_OFF 0x00
123 #define TEMPHUM14_STATUS_ON 0x01
124 
125 // Calculation
130 #define TEMPHUM14_CALC_16_BIT_DIVIDER 65535.0
131 #define TEMPHUM14_CALC_TEMP_MULTI_FACT 165.000
132 #define TEMPHUM14_CALC_TEMP_SUB_FACT 40.0000
133 #define TEMPHUM14_CALC_HUM_MULTI_FACT 100.000
134  // temphum14_reg
136 
137 
152 #define TEMPHUM14_MAP_MIKROBUS( cfg, mikrobus ) \
153  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
154  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
155  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
156  // temphum14_map // temphum14
159 
164 typedef struct
165 {
166  // Output pins
167  digital_out_t rst;
169  // Modules
170  i2c_master_t i2c;
172  // I2C slave address
173  uint8_t slave_address;
175 } temphum14_t;
176 
181 typedef struct
182 {
183  pin_name_t scl;
184  pin_name_t sda;
186  pin_name_t rst;
188  uint32_t i2c_speed;
189  uint8_t i2c_address;
192 
197 typedef enum
198 {
200  TEMPHUM14_ERROR = -1
201 
203 
204 typedef struct
205 {
206  uint8_t nvm_error;
207  uint8_t hum_un_over;
208  uint8_t hum_h_err;
209  uint8_t hum_l_err;
210  uint8_t temp_un_over;
211  uint8_t temp_h_err;
212  uint8_t temp_l_err;
213  uint8_t heater_on;
215 
232 
247 
263 err_t temphum14_generic_write ( temphum14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
264 
280 err_t temphum14_generic_read ( temphum14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
281 
292 
303 void temphum14_set_cmd ( temphum14_t *ctx, uint8_t cmd );
304 
319 void temphum14_set_conversion ( temphum14_t *ctx, uint8_t hum_osr, uint8_t temp_osr );
320 
331 void temphum14_read_t_and_rh ( temphum14_t *ctx, uint8_t *p_rx_data );
332 
344 void temphum14_get_temp_and_hum ( temphum14_t *ctx, float *temp, float *hum );
345 
356 void temphum14_read_rh ( temphum14_t *ctx, uint8_t *p_rx_data );
357 
369 
380 
391 void temphum14_set_heater ( temphum14_t *ctx, uint8_t en_heater );
392 
404 
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 #endif // TEMPHUM14_H
420  // temphum14
422 
423 // ------------------------------------------------------------------------ END
temphum14_diagn_t::hum_h_err
uint8_t hum_h_err
Definition: temphum14.h:208
temphum14_set_heater
void temphum14_set_heater(temphum14_t *ctx, uint8_t en_heater)
Enable heater function.
temphum14_get_diagnostic
void temphum14_get_diagnostic(temphum14_t *ctx, temphum14_diagn_t *diag_data)
Get diagnostic status function.
temphum14_cfg_t
Temp Hum 14 Click configuration object.
Definition: temphum14.h:182
temphum14_diagn_t::nvm_error
uint8_t nvm_error
Definition: temphum14.h:206
temphum14_generic_read
err_t temphum14_generic_read(temphum14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Temp Hum 14 I2C reading function.
temphum14_get_hum
float temphum14_get_hum(temphum14_t *ctx)
Get humidity data function.
temphum14_t::slave_address
uint8_t slave_address
Definition: temphum14.h:173
temphum14_diagn_t::hum_un_over
uint8_t hum_un_over
Definition: temphum14.h:207
temphum14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum14.h:188
temphum14_set_cmd
void temphum14_set_cmd(temphum14_t *ctx, uint8_t cmd)
Send command function.
temphum14_diagn_t::temp_h_err
uint8_t temp_h_err
Definition: temphum14.h:211
TEMPHUM14_ERROR
@ TEMPHUM14_ERROR
Definition: temphum14.h:200
temphum14_hw_reset
void temphum14_hw_reset(temphum14_t *ctx)
HW reset function.
temphum14_diagn_t::heater_on
uint8_t heater_on
Definition: temphum14.h:213
temphum14_get_temp_and_hum
void temphum14_get_temp_and_hum(temphum14_t *ctx, float *temp, float *hum)
Get temperature and humidity data function.
temphum14_diagn_t::temp_l_err
uint8_t temp_l_err
Definition: temphum14.h:212
temphum14_diagn_t::hum_l_err
uint8_t hum_l_err
Definition: temphum14.h:209
temphum14_read_t_and_rh
void temphum14_read_t_and_rh(temphum14_t *ctx, uint8_t *p_rx_data)
Read temperature and humidity data function.
temphum14_cfg_t::rst
pin_name_t rst
Definition: temphum14.h:186
temphum14_cfg_setup
void temphum14_cfg_setup(temphum14_cfg_t *cfg)
Temp Hum 14 configuration object setup function.
temphum14_init
err_t temphum14_init(temphum14_t *ctx, temphum14_cfg_t *cfg)
Temp Hum 14 initialization function.
TEMPHUM14_OK
@ TEMPHUM14_OK
Definition: temphum14.h:199
temphum14_cfg_t::scl
pin_name_t scl
Definition: temphum14.h:183
temphum14_diagn_t
Definition: temphum14.h:205
temphum14_set_conversion
void temphum14_set_conversion(temphum14_t *ctx, uint8_t hum_osr, uint8_t temp_osr)
Set conversion function.
temphum14_get_serial_number
uint32_t temphum14_get_serial_number(temphum14_t *ctx)
Get serial number function.
temphum14_diagn_t::temp_un_over
uint8_t temp_un_over
Definition: temphum14.h:210
temphum14_read_rh
void temphum14_read_rh(temphum14_t *ctx, uint8_t *p_rx_data)
Read humidity data function.
temphum14_generic_write
err_t temphum14_generic_write(temphum14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Temp Hum 14 I2C writing function.
temphum14_t
Temp Hum 14 Click context object.
Definition: temphum14.h:165
temphum14_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum14.h:189
temphum14_return_value_t
temphum14_return_value_t
Temp Hum 14 Click return value data.
Definition: temphum14.h:198
temphum14_t::i2c
i2c_master_t i2c
Definition: temphum14.h:170
temphum14_t::rst
digital_out_t rst
Definition: temphum14.h:167
temphum14_cfg_t::sda
pin_name_t sda
Definition: temphum14.h:184
temphum14_soft_reset
void temphum14_soft_reset(temphum14_t *ctx)
Soft reset function.