temphum25  2.1.0.0
temphum25.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 TEMPHUM25_H
29 #define TEMPHUM25_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 TEMPHUM25_CMD_MEAS_SSH_REP_HIGH_CS_EN 0x2C06
74 #define TEMPHUM25_CMD_MEAS_SSH_REP_MID_CS_EN 0x2C0D
75 #define TEMPHUM25_CMD_MEAS_SSH_REP_LOW_CS_EN 0x2C10
76 #define TEMPHUM25_CMD_MEAS_SSH_REP_HIGH_CS_DIS 0x2400
77 #define TEMPHUM25_CMD_MEAS_SSH_REP_MID_CS_DIS 0x240B
78 #define TEMPHUM25_CMD_MEAS_SSH_REP_LOW_CS_DIS 0x2416
79 #define TEMPHUM25_CMD_MEAS_CONT_REP_HIGH_MPS_0_5 0x2032
80 #define TEMPHUM25_CMD_MEAS_CONT_REP_MID_MPS_0_5 0x2024
81 #define TEMPHUM25_CMD_MEAS_CONT_REP_LOW_MPS_0_5 0x202F
82 #define TEMPHUM25_CMD_MEAS_CONT_REP_HIGH_MPS_1 0x2130
83 #define TEMPHUM25_CMD_MEAS_CONT_REP_MID_MPS_1 0x2126
84 #define TEMPHUM25_CMD_MEAS_CONT_REP_LOW_MPS_1 0x212D
85 #define TEMPHUM25_CMD_MEAS_CONT_REP_HIGH_MPS_2 0x2236
86 #define TEMPHUM25_CMD_MEAS_CONT_REP_MID_MPS_2 0x2220
87 #define TEMPHUM25_CMD_MEAS_CONT_REP_LOW_MPS_2 0x222B
88 #define TEMPHUM25_CMD_MEAS_CONT_REP_HIGH_MPS_4 0x2334
89 #define TEMPHUM25_CMD_MEAS_CONT_REP_MID_MPS_4 0x2322
90 #define TEMPHUM25_CMD_MEAS_CONT_REP_LOW_MPS_4 0x2329
91 #define TEMPHUM25_CMD_MEAS_CONT_REP_HIGH_MPS_10 0x2737
92 #define TEMPHUM25_CMD_MEAS_CONT_REP_MID_MPS_10 0x2721
93 #define TEMPHUM25_CMD_MEAS_CONT_REP_LOW_MPS_10 0x272A
94 #define TEMPHUM25_CMD_MEAS_CONT_ART 0x2B32
95 #define TEMPHUM25_CMD_CONT_MEAS_STOP 0x3093
96 #define TEMPHUM25_CMD_FETCH_DATA 0xE000
97 #define TEMPHUM25_CMD_SOFT_RESET 0x30A2
98 #define TEMPHUM25_CMD_HEATER_ENABLE 0x306D
99 #define TEMPHUM25_CMD_HEATER_DISABLE 0x3066
100 #define TEMPHUM25_CMD_GET_SERIAL_NUM_0 0x3780
101 #define TEMPHUM25_CMD_GET_SERIAL_NUM_1 0x3682
102 #define TEMPHUM25_CMD_READ_STATUS 0xF32D
103 #define TEMPHUM25_CMD_CLEAR_STATUS 0x3041
104  // temphum25_reg
106 
121 #define TEMPHUM25_MAX_RH 100.0f
122 #define TEMPHUM25_MIN_RH 0.0f
123 #define TEMPHUM25_DATA_RESOLUTION 65535.0f
124 #define TEMPHUM25_ABS_MIN_TEMP ( -45.0f )
125 #define TEMPHUM25_ABS_MAX_TEMP ( 130.0f )
126 
132 #define TEMPHUM25_DEVICE_ADDRESS_0 0x44
133 #define TEMPHUM25_DEVICE_ADDRESS_1 0x45
134  // temphum25_set
136 
151 #define TEMPHUM25_MAP_MIKROBUS( cfg, mikrobus ) \
152  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
154  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
155  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
156  // temphum25_map // temphum25
159 
164 typedef struct
165 {
166  // Output pins
167  digital_out_t rst;
169  // Input pins
170  digital_in_t alert;
172  // Modules
173  i2c_master_t i2c;
175  // I2C slave address
176  uint8_t slave_address;
178 } temphum25_t;
179 
184 typedef struct
185 {
186  pin_name_t scl;
187  pin_name_t sda;
189  pin_name_t rst;
190  pin_name_t alert;
192  uint32_t i2c_speed;
193  uint8_t i2c_address;
196 
201 typedef enum
202 {
204  TEMPHUM25_ERROR = -1
205 
207 
224 
239 
251 err_t temphum25_send_command ( temphum25_t *ctx, uint16_t cmd );
252 
265 err_t temphum25_start_measurement ( temphum25_t *ctx, uint16_t meas_cmd );
266 
278 
291 err_t temphum25_read_measurement ( temphum25_t *ctx, float *temperature, float *humidity );
292 
304 err_t temphum25_read_serial_num ( temphum25_t *ctx, uint32_t *serial_num );
305 
317 err_t temphum25_read_status ( temphum25_t *ctx, uint16_t *status );
318 
330 
342 
354 
366 
376 void temphum25_set_rst_pin ( temphum25_t *ctx, uint8_t state );
377 
387 
397 
398 #ifdef __cplusplus
399 }
400 #endif
401 #endif // TEMPHUM25_H
402  // temphum25
404 
405 // ------------------------------------------------------------------------ END
temphum25_cfg_t::alert
pin_name_t alert
Definition: temphum25.h:190
temphum25_cfg_t::rst
pin_name_t rst
Definition: temphum25.h:189
temphum25_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum25.h:193
temphum25_get_alert_pin
uint8_t temphum25_get_alert_pin(temphum25_t *ctx)
TempHum 25 get alert pin function.
temphum25_read_status
err_t temphum25_read_status(temphum25_t *ctx, uint16_t *status)
TempHum 25 read status function.
temphum25_t::i2c
i2c_master_t i2c
Definition: temphum25.h:173
temphum25_cfg_t
TempHum 25 Click configuration object.
Definition: temphum25.h:185
temphum25_cfg_t::sda
pin_name_t sda
Definition: temphum25.h:187
temphum25_init
err_t temphum25_init(temphum25_t *ctx, temphum25_cfg_t *cfg)
TempHum 25 initialization function.
temphum25_cfg_t::scl
pin_name_t scl
Definition: temphum25.h:186
temphum25_enable_heater
err_t temphum25_enable_heater(temphum25_t *ctx)
TempHum 25 enable heater function.
temphum25_cfg_setup
void temphum25_cfg_setup(temphum25_cfg_t *cfg)
TempHum 25 configuration object setup function.
temphum25_stop_measurement
err_t temphum25_stop_measurement(temphum25_t *ctx)
TempHum 25 stop measurement function.
temphum25_reset_device
void temphum25_reset_device(temphum25_t *ctx)
TempHum 25 reset device function.
temphum25_t::rst
digital_out_t rst
Definition: temphum25.h:167
temphum25_start_measurement
err_t temphum25_start_measurement(temphum25_t *ctx, uint16_t meas_cmd)
TempHum 25 start measurement function.
temphum25_disable_heater
err_t temphum25_disable_heater(temphum25_t *ctx)
TempHum 25 disable heater function.
temphum25_t::slave_address
uint8_t slave_address
Definition: temphum25.h:176
temphum25_t::alert
digital_in_t alert
Definition: temphum25.h:170
temphum25_clear_status
err_t temphum25_clear_status(temphum25_t *ctx)
TempHum 25 clear status function.
temphum25_soft_reset
err_t temphum25_soft_reset(temphum25_t *ctx)
TempHum 25 soft reset function.
temphum25_read_measurement
err_t temphum25_read_measurement(temphum25_t *ctx, float *temperature, float *humidity)
TempHum 25 read measurement function.
TEMPHUM25_ERROR
@ TEMPHUM25_ERROR
Definition: temphum25.h:204
temphum25_return_value_t
temphum25_return_value_t
TempHum 25 Click return value data.
Definition: temphum25.h:202
temphum25_set_rst_pin
void temphum25_set_rst_pin(temphum25_t *ctx, uint8_t state)
TempHum 25 set rst pin function.
temphum25_read_serial_num
err_t temphum25_read_serial_num(temphum25_t *ctx, uint32_t *serial_num)
TempHum 25 read serial num function.
temphum25_t
TempHum 25 Click context object.
Definition: temphum25.h:165
TEMPHUM25_OK
@ TEMPHUM25_OK
Definition: temphum25.h:203
temphum25_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum25.h:192
temphum25_send_command
err_t temphum25_send_command(temphum25_t *ctx, uint16_t cmd)
TempHum 25 send command function.