temphum17  2.0.0.0
temphum17.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 TEMPHUM17_H
29 #define TEMPHUM17_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 TEMPHUM17_REG_HUMIDITY_SENSOR_RESOLUTION_READ 0x06
60 #define TEMPHUM17_REG_HUMIDITY_SENSOR_RESOLUTION_WRITE 0x46
61 #define TEMPHUM17_REG_TEMPERATURE_SENSOR_RESOLUTION_READ 0x11
62 #define TEMPHUM17_REG_TEMPERATURE_SENSOR_RESOLUTION_WRITE 0x51
63 #define TEMPHUM17_REG_SENSOR_ID_UPPER_READ 0x1E
64 #define TEMPHUM17_REG_SENSOR_ID_LOWER_READ 0x1F
65  // temphum17_reg
67 
82 #define TEMPHUM17_CMD_ENTER_PROGRAMMING_MODE 0xA0
83 #define TEMPHUM17_CMD_DUMMY 0x00
84 #define TEMPHUM17_CMD_ENTER_MEASUREMENTS_MODE 0x80
85  // temphum17_cmd
86 
101 #define TEMPHUM17_STATUS_VALID_DATA 0x00
102 #define TEMPHUM17_STATUS_STALE_DATA 0x01
103  // temphum17_status
104 
119 #define TEMPHUM17_RESOLUTION_8_BITS 0x00
120 #define TEMPHUM17_RESOLUTION_10_BITS 0x01
121 #define TEMPHUM17_RESOLUTION_12_BITS 0x02
122 #define TEMPHUM17_RESOLUTION_14_BITS 0x03
123 
129 #define TEMPHUM17_SET_DEV_ADDR 0x44
130  // temphum17_set
132 
147 #define TEMPHUM17_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
149  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
150  // temphum17_map // temphum17
153 
158 typedef struct
159 {
160  // Modules
161 
162  i2c_master_t i2c;
164  // I2C slave address
165 
166  uint8_t slave_address;
168 } temphum17_t;
169 
174 typedef struct
175 {
176  pin_name_t scl;
177  pin_name_t sda;
180  uint32_t i2c_speed;
181  uint8_t i2c_address;
184 
189 typedef enum
190 {
192  TEMPHUM17_ERROR = -1
193 
195 
214 
231 err_t temphum17_init ( temphum17_t *ctx, temphum17_cfg_t *cfg );
232 
248 err_t temphum17_default_cfg ( temphum17_t *ctx );
249 
267 err_t temphum17_generic_write ( temphum17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
268 
286 err_t temphum17_generic_read ( temphum17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
287 
302 err_t temphum17_wake_up ( temphum17_t *ctx );
303 
335 err_t temphum17_get_raw_data ( temphum17_t *ctx, uint8_t resolution, int16_t *temp, uint16_t *hum, uint8_t *status );
336 
367 err_t temphum17_get_temp_hum ( temphum17_t *ctx, uint8_t resolution, float *temperature, float *humidity );
368 
385 
402 
423 err_t temphum17_set_relative_humidity_resolution ( temphum17_t *ctx, uint8_t resolution );
424 
445 err_t temphum17_set_temperature_resolution ( temphum17_t *ctx, uint8_t resolution );
446 
447 #ifdef __cplusplus
448 }
449 #endif
450 #endif // TEMPHUM17_H
451  // temphum17
453 
454 // ------------------------------------------------------------------------ END
temphum17_enter_measurements_mode
err_t temphum17_enter_measurements_mode(temphum17_t *ctx)
Temp&Hum 17 enter measurements mode function.
temphum17_wake_up
err_t temphum17_wake_up(temphum17_t *ctx)
Temp&Hum 17 wake up function.
temphum17_cfg_t
Temp&Hum 17 Click configuration object.
Definition: temphum17.h:173
temphum17_init
err_t temphum17_init(temphum17_t *ctx, temphum17_cfg_t *cfg)
Temp&Hum 17 initialization function.
temphum17_get_raw_data
err_t temphum17_get_raw_data(temphum17_t *ctx, uint8_t resolution, int16_t *temp, uint16_t *hum, uint8_t *status)
Temp&Hum 17 get raw data function.
temphum17_set_relative_humidity_resolution
err_t temphum17_set_relative_humidity_resolution(temphum17_t *ctx, uint8_t resolution)
Temp&Hum 17 set relative humidity resolution function.
temphum17_cfg_setup
void temphum17_cfg_setup(temphum17_cfg_t *cfg)
Temp&Hum 17 configuration object setup function.
temphum17_enter_programming_mode
err_t temphum17_enter_programming_mode(temphum17_t *ctx)
Temp&Hum 17 enter programming mode function.
temphum17_t
Temp&Hum 17 Click context object.
Definition: temphum17.h:157
temphum17_generic_write
err_t temphum17_generic_write(temphum17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Temp&Hum 17 I2C writing function.
temphum17_default_cfg
err_t temphum17_default_cfg(temphum17_t *ctx)
Temp&Hum 17 default configuration function.
temphum17_set_temperature_resolution
err_t temphum17_set_temperature_resolution(temphum17_t *ctx, uint8_t resolution)
Temp&Hum 17 set temperature resolution function.
temphum17_get_temp_hum
err_t temphum17_get_temp_hum(temphum17_t *ctx, uint8_t resolution, float *temperature, float *humidity)
Temp&Hum 17 get temperature and humidity function.
TEMPHUM17_OK
Definition: temphum17.h:190
TEMPHUM17_ERROR
Definition: temphum17.h:191
temphum17_return_value_t
temphum17_return_value_t
Temp&Hum 17 Click return value data.
Definition: temphum17.h:188
temphum17_generic_read
err_t temphum17_generic_read(temphum17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Temp&Hum 17 I2C reading function.