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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define TEMPHUM24_CMD_TRG_OD_LP0 0x2400u
60 #define TEMPHUM24_CMD_TRG_OD_LP1 0x240Bu
61 #define TEMPHUM24_CMD_TRG_OD_LP2 0x2416u
62 #define TEMPHUM24_CMD_TRG_OD_LP3 0x24FFu
63 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP0 0x2032u
64 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP1 0x2024u
65 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP2 0x202Fu
66 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP3 0x20FFu
67 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP0 0x2130u
68 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP1 0x2126u
69 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP2 0x212Du
70 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP3 0x21FFu
71 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP0 0x2236u
72 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP1 0x2220u
73 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP2 0x222Bu
74 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP3 0x22FFu
75 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP0 0x2334u
76 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP1 0x2322u
77 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP2 0x2329u
78 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP3 0x23FFu
79 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP0 0x2737u
80 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP1 0x2721u
81 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP2 0x272Au
82 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP3 0x27FFu
83 #define TEMPHUM24_CMD_AUTO_MEAS_EXIT 0x3093u
84 #define TEMPHUM24_CMD_AUTO_MEAS_ROUT_T_RH 0xE000u
85 #define TEMPHUM24_CMD_AUTO_MEAS_MIN_T 0xE002u
86 #define TEMPHUM24_CMD_AUTO_MEAS_MAX_T 0xE003u
87 #define TEMPHUM24_CMD_AUTO_MEAS_MIN_RH 0xE004u
88 #define TEMPHUM24_CMD_AUTO_MEAS_MAX_RH 0xE005u
89 #define TEMPHUM24_CMD_PROGRAM_SET_LOW_ALERT 0x6100u
90 #define TEMPHUM24_CMD_PROGRAM_SET_HIGH_ALERT 0x611Du
91 #define TEMPHUM24_CMD_PROGRAM_CLEAR_LOW_ALERT 0x610Bu
92 #define TEMPHUM24_CMD_PROGRAM_CLEAR_HIGH_ALERT 0x6116u
93 #define TEMPHUM24_CMD_TRANSFER_ALERT_THOLDS_TO_NVM 0x6155u
94 #define TEMPHUM24_CMD_READ_SET_LOW_ALERT 0xE102u
95 #define TEMPHUM24_CMD_READ_SET_HIGH_ALERT 0xE11Fu
96 #define TEMPHUM24_CMD_READ_CLEAR_LOW_ALERT 0xE109u
97 #define TEMPHUM24_CMD_READ_CLEAR_HIGH_ALERT 0xE114u
98 #define TEMPHUM24_CMD_INT_HEATER_ENABLE 0x306Du
99 #define TEMPHUM24_CMD_INT_HEATER_DISABLE 0x3066u
100 #define TEMPHUM24_CMD_INT_HEATER_CONFIGURE 0x306Eu
101 #define TEMPHUM24_CMD_STATUS_READ 0xF32Du
102 #define TEMPHUM24_CMD_STATUS_CLEAR 0x3041u
103 #define TEMPHUM24_CMD_NVM_T_RH_OFFSET 0xA004u
104 #define TEMPHUM24_CMD_SOFT_RESET 0x30A2u
105 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_5_4 0x3683u
106 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_3_2 0x3684u
107 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_1_0 0x3685u
108 #define TEMPHUM24_CMD_READ_MANUFACTURER_ID 0x3781u
109 #define TEMPHUM24_CMD_OVERRIDE_DEFAULT 0x61BBu
110  // temphum24_cmd
112 
127 #define TEMPHUM24_MANUFACTURER_ID 0x3000u
128 
133 #define TEMPHUM24_TEMP_MIN ( -45.0f )
134 #define TEMPHUM24_TEMP_MAX ( 130.0f )
135 #define TEMPHUM24_HUM_MIN ( 0.0f )
136 #define TEMPHUM24_HUM_MAX ( 100.0f )
137 #define TEMPHUM24_DATA_RESOLUTION 0xFFFFu
138 
144 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_00 0x44
145 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_01 0x45
146 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_10 0x46
147 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_11 0x47
148  // temphum24_set
150 
165 #define TEMPHUM24_MAP_MIKROBUS( cfg, mikrobus ) \
166  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
167  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
168  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
169  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
170  // temphum24_map // temphum24
173 
178 typedef struct
179 {
180  // Output pins
181  digital_out_t rst;
183  // Input pins
184  digital_in_t alert;
186  // Modules
187  i2c_master_t i2c;
189  // I2C slave address
190  uint8_t slave_address;
192 } temphum24_t;
193 
198 typedef struct
199 {
200  pin_name_t scl;
201  pin_name_t sda;
203  pin_name_t rst;
204  pin_name_t alert;
206  uint32_t i2c_speed;
207  uint8_t i2c_address;
210 
215 typedef enum
216 {
218  TEMPHUM24_ERROR = -1
219 
221 
238 
253 
267 
279 err_t temphum24_write_cmd ( temphum24_t *ctx, uint16_t cmd );
280 
293 err_t temphum24_write_cmd_config ( temphum24_t *ctx, uint16_t cmd, uint16_t config );
294 
306 err_t temphum24_read_single ( temphum24_t *ctx, uint16_t *data_out );
307 
320 err_t temphum24_read_multi ( temphum24_t *ctx, uint16_t *data1_out, uint16_t *data2_out );
321 
335 err_t temphum24_write_then_read_single ( temphum24_t *ctx, uint16_t cmd, uint16_t *data_out );
336 
351 err_t temphum24_write_then_read_multi ( temphum24_t *ctx, uint16_t cmd, uint16_t *data1_out, uint16_t *data2_out );
352 
362 
372 
382 
392 
404 
419 err_t temphum24_read_temp_and_rh ( temphum24_t *ctx, float *temp, float *hum );
420 
435 err_t temphum24_read_temp_history ( temphum24_t *ctx, float *temp_min, float *temp_max );
436 
451 err_t temphum24_read_rh_history ( temphum24_t *ctx, float *hum_min, float *hum_max );
452 
464 
476 
477 #ifdef __cplusplus
478 }
479 #endif
480 #endif // TEMPHUM24_H
481  // temphum24
483 
484 // ------------------------------------------------------------------------ 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:184
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:179
temphum24_cfg_t
TempHum 24 Click configuration object.
Definition: temphum24.h:199
temphum24_t::slave_address
uint8_t slave_address
Definition: temphum24.h:190
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:218
temphum24_cfg_t::scl
pin_name_t scl
Definition: temphum24.h:200
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:207
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_cfg_setup
void temphum24_cfg_setup(temphum24_cfg_t *cfg)
TempHum 24 configuration object setup function.
TEMPHUM24_OK
@ TEMPHUM24_OK
Definition: temphum24.h:217
temphum24_return_value_t
temphum24_return_value_t
TempHum 24 Click return value data.
Definition: temphum24.h:216
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:201
temphum24_cfg_t::alert
pin_name_t alert
Definition: temphum24.h:204
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:203
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:187
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:181
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:206
temphum24_init
err_t temphum24_init(temphum24_t *ctx, temphum24_cfg_t *cfg)
TempHum 24 initialization function.