temphum19  2.0.0.0
temphum19.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 TEMPHUM19_H
29 #define TEMPHUM19_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define TEMPHUM19_REG_RESET 0x00
70 #define TEMPHUM19_REG_MODE 0x01
71 #define TEMPHUM19_REG_ERROR 0x03
72 #define TEMPHUM19_REG_HUMIDITY_LSB 0x04
73 #define TEMPHUM19_REG_HUMIDITY_MSB 0x05
74 #define TEMPHUM19_REG_TEMPERATURE_LSB 0x06
75 #define TEMPHUM19_REG_TEMPERATURE_MSB 0x07
76 #define TEMPHUM19_REG_CAPACITY_LSB 0x0A
77 #define TEMPHUM19_REG_CAPACITY_MSB 0x0B
78 #define TEMPHUM19_REG_CAPACITY_CTRL 0x2C
79  // temphum19_reg
81 
96 #define TEMPHUM19_10BIT_RESOLUTION 0x400
97 #define TEMPHUM19_TEMP_DATA 0x7FF
98 #define TEMPHUM19_HUM_DATA 0x3FF
99 #define TEMPHUM19_TEMP_RESOLUTION 0.1
100 #define TEMPHUM19_HUM_RESOLUTION 100
101 #define TEMPHUM19_TEMP_NOMINAL 25
102 
107 #define TEMPHUM19_NORMAL_OPERATION_MODE 0x00
108 #define TEMPHUM19_HUM_NO_AVG 0x00
109 #define TEMPHUM19_HUM_AVG_2 0x08
110 #define TEMPHUM19_HUM_AVG_4 0x10
111 #define TEMPHUM19_HUM_AVG_8 0x20
112 #define TEMPHUM19_TEMP_AVG_8 0x00
113 #define TEMPHUM19_TEMP_AVG_16 0x04
114 #define TEMPHUM19_START_DETECTION 0x01
115 #define TEMPHUM19_STOP_DETECTION 0x00
116 
122 #define TEMPHUM19_SET_DEV_ADDR 0x7F
123  // temphum19_set
125 
140 #define TEMPHUM19_MAP_MIKROBUS( cfg, mikrobus ) \
141  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
142  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
143  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM );
144  // temphum19_map // temphum19
147 
152 typedef struct
153 {
154  // Output pins
155  digital_out_t en;
157  // Modules
158  i2c_master_t i2c;
159  pin_name_t scl;
160  pin_name_t sda;
162  // I2C slave address
163  uint8_t slave_address;
165  uint8_t detection_mode;
167 } temphum19_t;
168 
173 typedef struct
174 {
175  pin_name_t scl;
176  pin_name_t sda;
178  pin_name_t en;
180  uint32_t i2c_speed;
181  uint8_t i2c_address;
184 
189 typedef enum
190 {
192  TEMPHUM19_ERROR = -1
193 
195 
212 
228 
243 
259 err_t temphum19_generic_write ( temphum19_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
260 
276 err_t temphum19_generic_read ( temphum19_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
277 
287 
297 
307 
321 err_t temphum19_set_mode_reg ( temphum19_t *ctx, uint8_t mode );
322 
337 err_t temphum19_read_data ( temphum19_t *ctx, float *temperature, float *humidity );
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 #endif // TEMPHUM19_H
343  // temphum19
345 
346 // ------------------------------------------------------------------------ END
temphum19_read_data
err_t temphum19_read_data(temphum19_t *ctx, float *temperature, float *humidity)
TempHum 19 read data function.
temphum19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum19.h:180
temphum19_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum19.h:181
temphum19_default_cfg
err_t temphum19_default_cfg(temphum19_t *ctx)
TempHum 19 default configuration function.
temphum19_cfg_t
TempHum 19 Click configuration object.
Definition: temphum19.h:174
temphum19_t::scl
pin_name_t scl
Definition: temphum19.h:159
temphum19_generic_read
err_t temphum19_generic_read(temphum19_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
TempHum 19 I2C reading function.
temphum19_restart_chip
void temphum19_restart_chip(temphum19_t *ctx)
TempHum 19 restart chip function.
temphum19_disable_chip
void temphum19_disable_chip(temphum19_t *ctx)
TempHum 19 disable chip function.
TEMPHUM19_ERROR
@ TEMPHUM19_ERROR
Definition: temphum19.h:192
temphum19_t::en
digital_out_t en
Definition: temphum19.h:155
TEMPHUM19_OK
@ TEMPHUM19_OK
Definition: temphum19.h:191
temphum19_enable_chip
void temphum19_enable_chip(temphum19_t *ctx)
TempHum 19 enable chip function.
temphum19_set_mode_reg
err_t temphum19_set_mode_reg(temphum19_t *ctx, uint8_t mode)
TempHum 19 set mode function.
temphum19_cfg_setup
void temphum19_cfg_setup(temphum19_cfg_t *cfg)
TempHum 19 configuration object setup function.
temphum19_cfg_t::sda
pin_name_t sda
Definition: temphum19.h:176
temphum19_return_value_t
temphum19_return_value_t
TempHum 19 Click return value data.
Definition: temphum19.h:190
temphum19_init
err_t temphum19_init(temphum19_t *ctx, temphum19_cfg_t *cfg)
TempHum 19 initialization function.
temphum19_cfg_t::scl
pin_name_t scl
Definition: temphum19.h:175
temphum19_t::i2c
i2c_master_t i2c
Definition: temphum19.h:158
temphum19_t::detection_mode
uint8_t detection_mode
Definition: temphum19.h:165
temphum19_t
TempHum 19 Click context object.
Definition: temphum19.h:153
temphum19_generic_write
err_t temphum19_generic_write(temphum19_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
TempHum 19 I2C writing function.
temphum19_cfg_t::en
pin_name_t en
Definition: temphum19.h:178
temphum19_t::sda
pin_name_t sda
Definition: temphum19.h:160
temphum19_t::slave_address
uint8_t slave_address
Definition: temphum19.h:163