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 "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 TEMPHUM24_CMD_TRG_OD_LP0 0x2400u
70 #define TEMPHUM24_CMD_TRG_OD_LP1 0x240Bu
71 #define TEMPHUM24_CMD_TRG_OD_LP2 0x2416u
72 #define TEMPHUM24_CMD_TRG_OD_LP3 0x24FFu
73 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP0 0x2032u
74 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP1 0x2024u
75 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP2 0x202Fu
76 #define TEMPHUM24_CMD_AUTO_MEAS_HALF_HZ_LP3 0x20FFu
77 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP0 0x2130u
78 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP1 0x2126u
79 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP2 0x212Du
80 #define TEMPHUM24_CMD_AUTO_MEAS_1_HZ_LP3 0x21FFu
81 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP0 0x2236u
82 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP1 0x2220u
83 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP2 0x222Bu
84 #define TEMPHUM24_CMD_AUTO_MEAS_2_HZ_LP3 0x22FFu
85 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP0 0x2334u
86 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP1 0x2322u
87 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP2 0x2329u
88 #define TEMPHUM24_CMD_AUTO_MEAS_4_HZ_LP3 0x23FFu
89 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP0 0x2737u
90 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP1 0x2721u
91 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP2 0x272Au
92 #define TEMPHUM24_CMD_AUTO_MEAS_10_HZ_LP3 0x27FFu
93 #define TEMPHUM24_CMD_AUTO_MEAS_EXIT 0x3093u
94 #define TEMPHUM24_CMD_AUTO_MEAS_ROUT_T_RH 0xE000u
95 #define TEMPHUM24_CMD_AUTO_MEAS_MIN_T 0xE002u
96 #define TEMPHUM24_CMD_AUTO_MEAS_MAX_T 0xE003u
97 #define TEMPHUM24_CMD_AUTO_MEAS_MIN_RH 0xE004u
98 #define TEMPHUM24_CMD_AUTO_MEAS_MAX_RH 0xE005u
99 #define TEMPHUM24_CMD_PROGRAM_SET_LOW_ALERT 0x6100u
100 #define TEMPHUM24_CMD_PROGRAM_SET_HIGH_ALERT 0x611Du
101 #define TEMPHUM24_CMD_PROGRAM_CLEAR_LOW_ALERT 0x610Bu
102 #define TEMPHUM24_CMD_PROGRAM_CLEAR_HIGH_ALERT 0x6116u
103 #define TEMPHUM24_CMD_TRANSFER_ALERT_THOLDS_TO_NVM 0x6155u
104 #define TEMPHUM24_CMD_READ_SET_LOW_ALERT 0xE102u
105 #define TEMPHUM24_CMD_READ_SET_HIGH_ALERT 0xE11Fu
106 #define TEMPHUM24_CMD_READ_CLEAR_LOW_ALERT 0xE109u
107 #define TEMPHUM24_CMD_READ_CLEAR_HIGH_ALERT 0xE114u
108 #define TEMPHUM24_CMD_INT_HEATER_ENABLE 0x306Du
109 #define TEMPHUM24_CMD_INT_HEATER_DISABLE 0x3066u
110 #define TEMPHUM24_CMD_INT_HEATER_CONFIGURE 0x306Eu
111 #define TEMPHUM24_CMD_STATUS_READ 0xF32Du
112 #define TEMPHUM24_CMD_STATUS_CLEAR 0x3041u
113 #define TEMPHUM24_CMD_NVM_T_RH_OFFSET 0xA004u
114 #define TEMPHUM24_CMD_SOFT_RESET 0x30A2u
115 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_5_4 0x3683u
116 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_3_2 0x3684u
117 #define TEMPHUM24_CMD_READ_NIST_ID_BYTES_1_0 0x3685u
118 #define TEMPHUM24_CMD_READ_MANUFACTURER_ID 0x3781u
119 #define TEMPHUM24_CMD_OVERRIDE_DEFAULT 0x61BBu
120  // temphum24_cmd
122 
137 #define TEMPHUM24_MANUFACTURER_ID 0x3000u
138 
143 #define TEMPHUM24_TEMP_MIN ( -45.0f )
144 #define TEMPHUM24_TEMP_MAX ( 130.0f )
145 #define TEMPHUM24_HUM_MIN ( 0.0f )
146 #define TEMPHUM24_HUM_MAX ( 100.0f )
147 #define TEMPHUM24_DATA_RESOLUTION 0xFFFFu
148 
154 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_00 0x44
155 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_01 0x45
156 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_10 0x46
157 #define TEMPHUM24_DEVICE_ADDRESS_A1A0_11 0x47
158  // temphum24_set
160 
175 #define TEMPHUM24_MAP_MIKROBUS( cfg, mikrobus ) \
176  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
177  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
178  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
179  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
180  // temphum24_map // temphum24
183 
188 typedef struct
189 {
190  // Output pins
191  digital_out_t rst;
193  // Input pins
194  digital_in_t alert;
196  // Modules
197  i2c_master_t i2c;
199  // I2C slave address
200  uint8_t slave_address;
202 } temphum24_t;
203 
208 typedef struct
209 {
210  pin_name_t scl;
211  pin_name_t sda;
213  pin_name_t rst;
214  pin_name_t alert;
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
220 
225 typedef enum
226 {
228  TEMPHUM24_ERROR = -1
229 
231 
248 
263 
277 
289 err_t temphum24_write_cmd ( temphum24_t *ctx, uint16_t cmd );
290 
303 err_t temphum24_write_cmd_config ( temphum24_t *ctx, uint16_t cmd, uint16_t config );
304 
316 err_t temphum24_read_single ( temphum24_t *ctx, uint16_t *data_out );
317 
330 err_t temphum24_read_multi ( temphum24_t *ctx, uint16_t *data1_out, uint16_t *data2_out );
331 
345 err_t temphum24_write_then_read_single ( temphum24_t *ctx, uint16_t cmd, uint16_t *data_out );
346 
361 err_t temphum24_write_then_read_multi ( temphum24_t *ctx, uint16_t cmd, uint16_t *data1_out, uint16_t *data2_out );
362 
372 
382 
392 
402 
414 
429 err_t temphum24_read_temp_and_rh ( temphum24_t *ctx, float *temp, float *hum );
430 
445 err_t temphum24_read_temp_history ( temphum24_t *ctx, float *temp_min, float *temp_max );
446 
461 err_t temphum24_read_rh_history ( temphum24_t *ctx, float *hum_min, float *hum_max );
462 
474 
486 
498 err_t temphum24_get_serial_number ( temphum24_t *ctx, uint16_t *serial_number );
499 
500 #ifdef __cplusplus
501 }
502 #endif
503 #endif // TEMPHUM24_H
504  // temphum24
506 
507 // ------------------------------------------------------------------------ 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:194
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:189
temphum24_cfg_t
TempHum 24 Click configuration object.
Definition: temphum24.h:209
temphum24_t::slave_address
uint8_t slave_address
Definition: temphum24.h:200
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:228
temphum24_cfg_t::scl
pin_name_t scl
Definition: temphum24.h:210
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:217
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:227
temphum24_return_value_t
temphum24_return_value_t
TempHum 24 Click return value data.
Definition: temphum24.h:226
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:211
temphum24_cfg_t::alert
pin_name_t alert
Definition: temphum24.h:214
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:213
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:197
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:191
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:216
temphum24_init
err_t temphum24_init(temphum24_t *ctx, temphum24_cfg_t *cfg)
TempHum 24 initialization function.