temphum24  2.1.0.0
temphum24.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 TEMPHUM24_H
29 #define TEMPHUM24_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 TEMPHUM24_CMD_TRG_OD_LP0 0x2400u
74 #define TEMPHUM24_CMD_TRG_OD_LP1 0x240Bu
75 #define TEMPHUM24_CMD_TRG_OD_LP2 0x2416u
76 #define TEMPHUM24_CMD_TRG_OD_LP3 0x24FFu
77 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP0 0x2032u
78 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP1 0x2024u
79 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP2 0x202Fu
80 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP3 0x20FFu
81 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP0 0x2130u
82 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP1 0x2126u
83 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP2 0x212Du
84 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP3 0x21FFu
85 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP0 0x2236u
86 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP1 0x2220u
87 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP2 0x222Bu
88 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP3 0x22FFu
89 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP0 0x2334u
90 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP1 0x2322u
91 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP2 0x2329u
92 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP3 0x23FFu
93 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP0 0x2737u
94 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP1 0x2721u
95 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP2 0x272Au
96 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP3 0x27FFu
97 #define TEMPHUM24_CMD_AUTO_MEAS_EXIT 0x3093u
98 #define TEMPHUM24_CMD_AUTO_MEAS_ROUT_T_RH 0xE000u
99 #define TEMPHUM24_CMD_AUTO_MEAS_MIN_T 0xE002u
100 #define TEMPHUM24_CMD_AUTO_MEAS_MAX_T 0xE003u
101 #define TEMPHUM24_CMD_AUTO_MEAS_MIN_RH 0xE004u
102 #define TEMPHUM24_CMD_AUTO_MEAS_MAX_RH 0xE005u
103 #define TEMPHUM24_CMD_PROGRAM_SET_LOW_ALERT 0x6100u
104 #define TEMPHUM24_CMD_PROGRAM_SET_HIGH_ALERT 0x611Du
105 #define TEMPHUM24_CMD_PROGRAM_CLEAR_LOW_ALERT 0x610Bu
106 #define TEMPHUM24_CMD_PROGRAM_CLEAR_HIGH_ALERT 0x6116u
107 #define TEMPHUM24_CMD_TRANSFER_ALERT_THOLDS_TO_NVM 0x6155u
108 #define TEMPHUM24_CMD_READ_SET_LOW_ALERT 0xE102u
109 #define TEMPHUM24_CMD_READ_SET_HIGH_ALERT 0xE11Fu
110 #define TEMPHUM24_CMD_READ_CLEAR_LOW_ALERT 0xE109u
111 #define TEMPHUM24_CMD_READ_CLEAR_HIGH_ALERT 0xE114u
112 #define TEMPHUM24_CMD_INT_HEATER_ENABLE 0x306Du
113 #define TEMPHUM24_CMD_INT_HEATER_DISABLE 0x3066u
114 #define TEMPHUM24_CMD_INT_HEATER_CONFIGURE 0x306Eu
115 #define TEMPHUM24_CMD_STATUS_READ 0xF32Du
116 #define TEMPHUM24_CMD_STATUS_CLEAR 0x3041u
117 #define TEMPHUM24_CMD_NVM_T_RH_OFFSET 0xA004u
118 #define TEMPHUM24_CMD_SOFT_RESET 0x30A2u
119 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_5_4 0x3683u
120 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_3_2 0x3684u
121 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_1_0 0x3685u
122 #define TEMPHUM24_CMD_READ_MANUFACTURER_ID 0x3781u
123 #define TEMPHUM24_CMD_OVERRIDE_DEFAULT 0x61BBu
124  // temphum24_cmd
126 
141 #define TEMPHUM24_MANUFACTURER_ID 0x3000u
142 
147 #define TEMPHUM24_TEMP_MIN ( -45.0f )
148 #define TEMPHUM24_TEMP_MAX ( 130.0f )
149 #define TEMPHUM24_HUM_MIN ( 0.0f )
150 #define TEMPHUM24_HUM_MAX ( 100.0f )
151 #define TEMPHUM24_DATA_RESOLUTION 0xFFFFu
152 
158 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_00 0x44
159 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_01 0x45
160 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_10 0x46
161 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_11 0x47
162  // temphum24_set
164 
179 #define TEMPHUM24_MAP_MIKROBUS( cfg, mikrobus ) \
180  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
183  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
184  // temphum24_map // temphum24
187 
192 typedef struct
193 {
194  // Output pins
195  digital_out_t rst;
197  // Input pins
198  digital_in_t alert;
200  // Modules
201  i2c_master_t i2c;
203  // I2C slave address
204  uint8_t slave_address;
206 } temphum24_t;
207 
212 typedef struct
213 {
214  pin_name_t scl;
215  pin_name_t sda;
217  pin_name_t rst;
218  pin_name_t alert;
220  uint32_t i2c_speed;
221  uint8_t i2c_address;
224 
229 typedef enum
230 {
232  TEMPHUM24_ERROR = -1
233 
235 
252 
267 
281 
293 err_t temphum24_write_cmd ( temphum24_t *ctx, uint16_t cmd );
294 
307 err_t temphum24_write_cmd_config ( temphum24_t *ctx, uint16_t cmd, uint16_t config );
308 
320 err_t temphum24_read_single ( temphum24_t *ctx, uint16_t *data_out );
321 
334 err_t temphum24_read_multi ( temphum24_t *ctx, uint16_t *data1_out, uint16_t *data2_out );
335 
349 err_t temphum24_write_then_read_single ( temphum24_t *ctx, uint16_t cmd, uint16_t *data_out );
350 
365 err_t temphum24_write_then_read_multi ( temphum24_t *ctx, uint16_t cmd, uint16_t *data1_out, uint16_t *data2_out );
366 
376 
386 
396 
406 
418 
433 err_t temphum24_read_temp_and_rh ( temphum24_t *ctx, float *temp, float *hum );
434 
449 err_t temphum24_read_temp_history ( temphum24_t *ctx, float *temp_min, float *temp_max );
450 
465 err_t temphum24_read_rh_history ( temphum24_t *ctx, float *hum_min, float *hum_max );
466 
478 
490 
502 err_t temphum24_get_serial_number ( temphum24_t *ctx, uint16_t *serial_number );
503 
504 #ifdef __cplusplus
505 }
506 #endif
507 #endif // TEMPHUM24_H
508  // temphum24
510 
511 // ------------------------------------------------------------------------ END
temphum24_enable_device
void temphum24_enable_device(temphum24_t *ctx)
TempHum 24 enable device function.
temphum24_read_multi
err_t temphum24_read_multi(temphum24_t *ctx, uint16_t *data1_out, uint16_t *data2_out)
TempHum 24 read multi function.
temphum24_t::alert
digital_in_t alert
Definition: temphum24.h:198
temphum24_check_communication
err_t temphum24_check_communication(temphum24_t *ctx)
TempHum 24 check communication function.
temphum24_read_single
err_t temphum24_read_single(temphum24_t *ctx, uint16_t *data_out)
TempHum 24 read single function.
temphum24_t
TempHum 24 Click context object.
Definition: temphum24.h:193
temphum24_cfg_t
TempHum 24 Click configuration object.
Definition: temphum24.h:213
temphum24_t::slave_address
uint8_t slave_address
Definition: temphum24.h:204
temphum24_get_alert_pin
uint8_t temphum24_get_alert_pin(temphum24_t *ctx)
TempHum 24 get alert pin function.
TEMPHUM24_ERROR
@ TEMPHUM24_ERROR
Definition: temphum24.h:232
temphum24_cfg_t::scl
pin_name_t scl
Definition: temphum24.h:214
temphum24_read_rh_history
err_t temphum24_read_rh_history(temphum24_t *ctx, float *hum_min, float *hum_max)
TempHum 24 read rh history function.
temphum24_write_cmd
err_t temphum24_write_cmd(temphum24_t *ctx, uint16_t cmd)
TempHum 24 write cmd function.
temphum24_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum24.h:221
temphum24_write_then_read_multi
err_t temphum24_write_then_read_multi(temphum24_t *ctx, uint16_t cmd, uint16_t *data1_out, uint16_t *data2_out)
TempHum 24 write then read multi function.
temphum24_get_serial_number
err_t temphum24_get_serial_number(temphum24_t *ctx, uint16_t *serial_number)
TempHum 24 read serial number function.
temphum24_cfg_setup
void temphum24_cfg_setup(temphum24_cfg_t *cfg)
TempHum 24 configuration object setup function.
TEMPHUM24_OK
@ TEMPHUM24_OK
Definition: temphum24.h:231
temphum24_return_value_t
temphum24_return_value_t
TempHum 24 Click return value data.
Definition: temphum24.h:230
temphum24_write_cmd_config
err_t temphum24_write_cmd_config(temphum24_t *ctx, uint16_t cmd, uint16_t config)
TempHum 24 write cmd config function.
temphum24_reset_device
void temphum24_reset_device(temphum24_t *ctx)
TempHum 24 reset device function.
temphum24_cfg_t::sda
pin_name_t sda
Definition: temphum24.h:215
temphum24_cfg_t::alert
pin_name_t alert
Definition: temphum24.h:218
temphum24_read_temp_history
err_t temphum24_read_temp_history(temphum24_t *ctx, float *temp_min, float *temp_max)
TempHum 24 read temp history function.
temphum24_cfg_t::rst
pin_name_t rst
Definition: temphum24.h:217
temphum24_default_cfg
err_t temphum24_default_cfg(temphum24_t *ctx)
TempHum 24 default configuration function.
temphum24_disable_device
void temphum24_disable_device(temphum24_t *ctx)
TempHum 24 disable device function.
temphum24_t::i2c
i2c_master_t i2c
Definition: temphum24.h:201
temphum24_stop_measurement
err_t temphum24_stop_measurement(temphum24_t *ctx)
TempHum 24 stop measurement function.
temphum24_t::rst
digital_out_t rst
Definition: temphum24.h:195
temphum24_start_measurement
err_t temphum24_start_measurement(temphum24_t *ctx)
TempHum 24 start measurement function.
temphum24_read_temp_and_rh
err_t temphum24_read_temp_and_rh(temphum24_t *ctx, float *temp, float *hum)
TempHum 24 read temp and rh function.
temphum24_write_then_read_single
err_t temphum24_write_then_read_single(temphum24_t *ctx, uint16_t cmd, uint16_t *data_out)
TempHum 24 write then read single function.
temphum24_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum24.h:220
temphum24_init
err_t temphum24_init(temphum24_t *ctx, temphum24_cfg_t *cfg)
TempHum 24 initialization function.