temphum9  2.0.0.0
temphum9.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 TEMPHUM9_H
36 #define TEMPHUM9_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 TEMPHUM9_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 
57 
63 #define TEMPHUM9_RETVAL uint8_t
64 
65 #define TEMPHUM9_OK 0x00
66 #define TEMPHUM9_INIT_ERROR 0xFF
67 
73 #define TEMPHUM9_DEVICE_ADDRESS 0x70
74 
81 #define TEMPHUM9_NORMAL_MODE 0x00
82 #define TEMPHUM9_LOW_POWER_MODE 0x01
83 
90 #define TEMPHUM9_SINGLE_DATA 0x03
91 #define TEMPHUM9_DUAL_DATA 0x06
92 
99 #define TEMPHUM9_SLEEP 0xB098
100 #define TEMPHUM9_WAKEUP 0x3517
101 #define TEMPHUM9_SOFT_RESET 0x805D
102 #define TEMPHUM9_GENERAL_CALL_RESET 0x0006
103 #define TEMPHUM9_READ_ID 0xEFC8
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Modules
119 
120  i2c_master_t i2c;
121 
122  // ctx variable
123 
124  hal_i2c_address_t slave_address;
125 
126 } temphum9_t;
127 
131 typedef struct
132 {
133  // Communication gpio pins
134 
135  pin_name_t scl;
136  pin_name_t sda;
137 
138  // static variable
139 
140  hal_i2c_speed_t i2c_speed;
141  hal_i2c_address_t i2c_address;
142 
144  // End types group
146 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
165 void temphum9_cfg_setup ( temphum9_cfg_t *cfg );
166 
175 
183 void temphum9_default_cfg ( temphum9_t *ctx );
184 
195 void temphum9_generic_write ( temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
196 
208 void temphum9_generic_read ( temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
209 
221 void temphum9_read_register ( temphum9_t *ctx, uint16_t register_address, uint8_t n_data_, uint16_t *register_buffer );
222 
232 void temphum9_send_command ( temphum9_t *ctx, uint16_t command );
233 
243 float temphum9_get_temperature ( temphum9_t *ctx, uint8_t data_mode );
244 
254 float temphum9_get_relative_humidity ( temphum9_t *ctx, uint8_t data_mode );
255 
265 void temhum9_get_temperature_and_humidity ( temphum9_t *ctx, uint8_t data_mode , float *measurement_data );
266 
267 
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif // _TEMPHUM9_H_
273  // End public_function group
276 
277 // ------------------------------------------------------------------------- END
hal_i2c_speed_t i2c_speed
Definition: temphum9.h:140
void temhum9_get_temperature_and_humidity(temphum9_t *ctx, uint8_t data_mode, float *measurement_data)
Calculating temperature and relative humidity.
uint8_t measurement_data[2]
Definition: main.c:32
void temphum9_read_register(temphum9_t *ctx, uint16_t register_address, uint8_t n_data_, uint16_t *register_buffer)
Readinig register content.
float temphum9_get_relative_humidity(temphum9_t *ctx, uint8_t data_mode)
Calculating relative humidity.
hal_i2c_address_t i2c_address
Definition: temphum9.h:141
#define TEMPHUM9_RETVAL
Definition: temphum9.h:63
void temphum9_cfg_setup(temphum9_cfg_t *cfg)
Config Object Initialization function.
float temphum9_get_temperature(temphum9_t *ctx, uint8_t data_mode)
Calculating temperature.
Click ctx object definition.
Definition: temphum9.h:116
void temphum9_generic_read(temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2c_master_t i2c
Definition: temphum9.h:120
void temphum9_default_cfg(temphum9_t *ctx)
Click Default Configuration function.
pin_name_t scl
Definition: temphum9.h:135
Click configuration structure definition.
Definition: temphum9.h:131
void temphum9_send_command(temphum9_t *ctx, uint16_t command)
Issuing a command.
hal_i2c_address_t slave_address
Definition: temphum9.h:124
TEMPHUM9_RETVAL temphum9_init(temphum9_t *ctx, temphum9_cfg_t *cfg)
Initialization function.
pin_name_t sda
Definition: temphum9.h:136
void temphum9_generic_write(temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.