temphum11  2.0.0.0
temphum11.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef TEMPHUM11_H
36 #define TEMPHUM11_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TEMPHUM11_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
56 
62 #define TEMPHUM11_RETVAL uint8_t
63 
64 #define TEMPHUM11_OK 0x00
65 #define TEMPHUM11_INIT_ERROR 0xFF
66 
72 #define TEMPHUM11_REG_TEMPERATURE 0x00
73 #define TEMPHUM11_REG_HUMIDITY 0x01
74 #define TEMPHUM11_REG_CONFIGURATION 0x02
75 #define TEMPHUM11_REG_SERIAL_ID_0 0xFB
76 #define TEMPHUM11_REG_SERIAL_ID_1 0xFC
77 #define TEMPHUM11_REG_SERIAL_ID_2 0xFD
78 #define TEMPHUM11_REG_MANUFACTURER_ID 0xFE
79 #define TEMPHUM11_REG_DEVICE_ID 0xFF
80 
86 #define TEMPHUM11_NORMAL_OPERATION 0x0000
87 #define TEMPHUM11_SOFTWARE_RESET 0x8000
88 #define TEMPHUM11_HEATER_DISABLED 0x0000
89 #define TEMPHUM11_HEATER_ENABLED 0x2000
90 #define TEMPHUM11_TEMP_HUM_ACQUIRED 0x0000
91 #define TEMPHUM11_TEMP_FIRST 0x1000
92 #define TEMPHUM11_BAT_VOLT_BIGGER_THAN_2p8 0x0000
93 #define TEMPHUM11_BAT_VOLT_SMALLER_THAN_2p8 0x0800
94 #define TEMPHUM11_TEMP_RESOLUTION_14bit 0x0000
95 #define TEMPHUM11_TEMP_RESOLUTION_11bit 0x0400
96 #define TEMPHUM11_HUM_RESOLUTION_14bit 0x0000
97 #define TEMPHUM11_HUM_RESOLUTION_11bit 0x0100
98 #define TEMPHUM11_HUM_RESOLUTION_8bit 0x0200
99 
105 #define TEMPHUM11_DEVICE_SLAVE_ADDR 0x40
106 
112 #define TEMPHUM11_DEVICE_ID 0x1050
113 #define TEMPHUM11_MANUFACTURER_ID 0x5449
114 
120 #define TEMPHUM11_TEMP_IN_CELSIUS 0x00
121 #define TEMPHUM11_TEMP_IN_KELVIN 0x01
122 #define TEMPHUM11_TEMP_IN_FAHRENHEIT 0x02
123  // End group macro
125 // --------------------------------------------------------------- PUBLIC TYPES
134 typedef struct
135 {
136  // Modules
137 
138  i2c_master_t i2c;
139 
140  // ctx variable
141 
142  hal_i2c_address_t slave_address;
143 
144 } temphum11_t;
145 
149 typedef struct
150 {
151  // Communication gpio pins
152 
153  pin_name_t scl;
154  pin_name_t sda;
155 
156  // Static variable
157 
158  hal_i2c_speed_t i2c_speed;
159  hal_i2c_address_t i2c_address;
160 
162  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
184 
193 
201 void temphum11_default_cfg ( temphum11_t *ctx );
202 
211 void temphum11_write_config ( temphum11_t *ctx, uint16_t config );
212 
223 uint16_t temphum11_read_data ( temphum11_t *ctx, uint8_t reg );
224 
235 float temphum11_get_temperature ( temphum11_t *ctx, uint8_t temp_in );
236 
246 float temphum11_get_humidity ( temphum11_t *ctx );
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 #endif // _TEMPHUM11_H_
252  // End public_function group
255 
256 // ------------------------------------------------------------------------- END
pin_name_t scl
Definition: temphum11.h:153
void temphum11_cfg_setup(temphum11_cfg_t *cfg)
Config Object Initialization function.
TEMPHUM11_RETVAL temphum11_init(temphum11_t *ctx, temphum11_cfg_t *cfg)
Initialization function.
void temphum11_default_cfg(temphum11_t *ctx)
Click Default Configuration function.
i2c_master_t i2c
Definition: temphum11.h:138
float temphum11_get_temperature(temphum11_t *ctx, uint8_t temp_in)
Functions for reading Temperature data.
Click ctx object definition.
Definition: temphum11.h:134
pin_name_t sda
Definition: temphum11.h:154
hal_i2c_speed_t i2c_speed
Definition: temphum11.h:158
hal_i2c_address_t slave_address
Definition: temphum11.h:142
void temphum11_write_config(temphum11_t *ctx, uint16_t config)
Function for writing configuration device for measurement.
uint16_t temphum11_read_data(temphum11_t *ctx, uint8_t reg)
Functions for reading data from registers.
hal_i2c_address_t i2c_address
Definition: temphum11.h:159
float temphum11_get_humidity(temphum11_t *ctx)
Functions for reading Relative Huminidy data.
Click configuration structure definition.
Definition: temphum11.h:149
#define TEMPHUM11_RETVAL
Definition: temphum11.h:62