temphum21  2.0.0.0
temphum21.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 TEMPHUM21_H
29 #define TEMPHUM21_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 TEMPHUM21_STATUS_NORMAL_OP 0x00
60 #define TEMPHUM21_STATUS_STALE_DATA 0x01
61 #define TEMPHUM21_STATUS_COMMAND_MODE 0x02
62 #define TEMPHUM21_STATUS_BIT_MASK 0x03
63 
68 #define TEMPHUM21_DATA_RES 0x3FFF
69 #define TEMPHUM21_TEMP_RES 165.0
70 #define TEMPHUM21_TEMP_OFFSET 40.0
71 #define TEMPHUM21_HUM_RES 100.0
72 
78 #define TEMPHUM21_SET_DEV_ADDR 0x27
79  // temphum21_set
81 
96 #define TEMPHUM21_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
98  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
99  cfg.all = MIKROBUS( mikrobus, MIKROBUS_AN ); \
100  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_INT )
101  // temphum21_map // temphum21
104 
109 typedef struct
110 {
111  // Input pins
112  digital_in_t all;
113  digital_in_t alh;
115  // Modules
116  i2c_master_t i2c;
118  // I2C slave address
119  uint8_t slave_address;
121 } temphum21_t;
122 
127 typedef struct
128 {
129  pin_name_t scl;
130  pin_name_t sda;
132  pin_name_t all;
133  pin_name_t alh;
135  uint32_t i2c_speed;
136  uint8_t i2c_address;
139 
144 typedef enum
145 {
147  TEMPHUM21_ERROR = -1
148 
150 
167 
182 
194 
209 err_t temphum21_read_measurement ( temphum21_t *ctx, float *temperature, float *humidity );
210 
220 
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 #endif // TEMPHUM21_H
235  // temphum21
237 
238 // ------------------------------------------------------------------------ END
temphum21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum21.h:135
temphum21_cfg_setup
void temphum21_cfg_setup(temphum21_cfg_t *cfg)
TempHum 21 configuration object setup function.
temphum21_return_value_t
temphum21_return_value_t
TempHum 21 Click return value data.
Definition: temphum21.h:145
temphum21_read_measurement
err_t temphum21_read_measurement(temphum21_t *ctx, float *temperature, float *humidity)
TempHum 21 read measurement function.
temphum21_cfg_t::sda
pin_name_t sda
Definition: temphum21.h:130
temphum21_cfg_t::all
pin_name_t all
Definition: temphum21.h:132
temphum21_cfg_t::scl
pin_name_t scl
Definition: temphum21.h:129
temphum21_cfg_t
TempHum 21 Click configuration object.
Definition: temphum21.h:128
TEMPHUM21_OK
@ TEMPHUM21_OK
Definition: temphum21.h:146
temphum21_get_alh_pin
uint8_t temphum21_get_alh_pin(temphum21_t *ctx)
TempHum 21 get alh pin function.
temphum21_t::all
digital_in_t all
Definition: temphum21.h:112
temphum21_t::i2c
i2c_master_t i2c
Definition: temphum21.h:116
temphum21_t::slave_address
uint8_t slave_address
Definition: temphum21.h:119
temphum21_get_all_pin
uint8_t temphum21_get_all_pin(temphum21_t *ctx)
TempHum 21 get all pin function.
temphum21_cfg_t::alh
pin_name_t alh
Definition: temphum21.h:133
temphum21_init
err_t temphum21_init(temphum21_t *ctx, temphum21_cfg_t *cfg)
TempHum 21 initialization function.
TEMPHUM21_ERROR
@ TEMPHUM21_ERROR
Definition: temphum21.h:147
temphum21_request_measurement
err_t temphum21_request_measurement(temphum21_t *ctx)
TempHum 21 request measurement function.
temphum21_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum21.h:136
temphum21_t::alh
digital_in_t alh
Definition: temphum21.h:113
temphum21_t
TempHum 21 Click context object.
Definition: temphum21.h:110