temphum18  2.0.0.0
temphum18.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 TEMPHUM18_H
29 #define TEMPHUM18_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 TEMPHUM18_REG_HUMIDITY_SENSOR_RESOLUTION_READ 0x06
70 #define TEMPHUM18_REG_HUMIDITY_SENSOR_RESOLUTION_WRITE 0x46
71 #define TEMPHUM18_REG_TEMPERATURE_SENSOR_RESOLUTION_READ 0x11
72 #define TEMPHUM18_REG_TEMPERATURE_SENSOR_RESOLUTION_WRITE 0x51
73 #define TEMPHUM18_REG_SENSOR_ID_UPPER_READ 0x1E
74 #define TEMPHUM18_REG_SENSOR_ID_LOWER_READ 0x1F
75  // temphum18_reg
77 
92 #define TEMPHUM18_CMD_ENTER_PROGRAMMING_MODE 0xA0
93 #define TEMPHUM18_CMD_DUMMY 0x00
94 #define TEMPHUM18_CMD_ENTER_MEASUREMENTS_MODE 0x80
95  // temphum18_cmd
96 
111 #define TEMPHUM18_STATUS_VALID_DATA 0x00
112 #define TEMPHUM18_STATUS_STALE_DATA 0x01
113  // temphum18_status
114 
129 #define TEMPHUM18_RESOLUTION_8_BITS 0x00
130 #define TEMPHUM18_RESOLUTION_10_BITS 0x01
131 #define TEMPHUM18_RESOLUTION_12_BITS 0x02
132 #define TEMPHUM18_RESOLUTION_14_BITS 0x03
133 
139 #define TEMPHUM18_SET_DEV_ADDR 0x44
140  // temphum18_set
142 
157 #define TEMPHUM18_MAP_MIKROBUS( cfg, mikrobus ) \
158  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
159  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
160  // temphum18_map // temphum18
163 
168 typedef struct
169 {
170  // Modules
171  i2c_master_t i2c;
173  // I2C slave address
174  uint8_t slave_address;
176 } temphum18_t;
177 
182 typedef struct
183 {
184  pin_name_t scl;
185  pin_name_t sda;
187  uint32_t i2c_speed;
188  uint8_t i2c_address;
191 
196 typedef enum
197 {
199  TEMPHUM18_ERROR = -1
200 
202 
219 
235 
250 
266 err_t temphum18_generic_write ( temphum18_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
267 
283 err_t temphum18_generic_read ( temphum18_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
284 
299 
329 err_t temphum18_get_raw_data ( temphum18_t *ctx, uint8_t resolution, int16_t *temp, uint16_t *hum, uint8_t *status );
330 
358 err_t temphum18_get_temp_hum ( temphum18_t *ctx, uint8_t resolution, float *temperature, float *humidity );
359 
374 
389 
407 err_t temphum18_set_relative_humidity_resolution ( temphum18_t *ctx, uint8_t resolution );
408 
426 err_t temphum18_set_temperature_resolution ( temphum18_t *ctx, uint8_t resolution );
427 
428 #ifdef __cplusplus
429 }
430 #endif
431 #endif // TEMPHUM18_H
432  // temphum18
434 
435 // ------------------------------------------------------------------------ END
temphum18_cfg_t::sda
pin_name_t sda
Definition: temphum18.h:185
temphum18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum18.h:187
temphum18_default_cfg
err_t temphum18_default_cfg(temphum18_t *ctx)
Temp&Hum 18 default configuration function.
temphum18_set_temperature_resolution
err_t temphum18_set_temperature_resolution(temphum18_t *ctx, uint8_t resolution)
Temp&Hum 18 set relative temperature resolution function.
temphum18_generic_read
err_t temphum18_generic_read(temphum18_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Temp&Hum 18 I2C reading function.
temphum18_cfg_t
Temp&Hum 18 Click configuration object.
Definition: temphum18.h:183
temphum18_get_raw_data
err_t temphum18_get_raw_data(temphum18_t *ctx, uint8_t resolution, int16_t *temp, uint16_t *hum, uint8_t *status)
Temp&Hum 18 get raw data function.
temphum18_wake_up
err_t temphum18_wake_up(temphum18_t *ctx)
Temp&Hum 18 wake up function.
temphum18_get_temp_hum
err_t temphum18_get_temp_hum(temphum18_t *ctx, uint8_t resolution, float *temperature, float *humidity)
Temp&Hum 18 get temperature and humidity function.
TEMPHUM18_ERROR
@ TEMPHUM18_ERROR
Definition: temphum18.h:199
temphum18_cfg_setup
void temphum18_cfg_setup(temphum18_cfg_t *cfg)
Temp&Hum 18 configuration object setup function.
temphum18_t::i2c
i2c_master_t i2c
Definition: temphum18.h:171
temphum18_return_value_t
temphum18_return_value_t
Temp&Hum 18 Click return value data.
Definition: temphum18.h:197
TEMPHUM18_OK
@ TEMPHUM18_OK
Definition: temphum18.h:198
temphum18_t::slave_address
uint8_t slave_address
Definition: temphum18.h:174
temphum18_cfg_t::scl
pin_name_t scl
Definition: temphum18.h:184
temphum18_enter_measurements_mode
err_t temphum18_enter_measurements_mode(temphum18_t *ctx)
Temp&Hum 18 enter measurements mode function.
temphum18_t
Temp&Hum 18 Click context object.
Definition: temphum18.h:169
temphum18_enter_programming_mode
err_t temphum18_enter_programming_mode(temphum18_t *ctx)
Temp&Hum 18 enter programming mode function.
temphum18_generic_write
err_t temphum18_generic_write(temphum18_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Temp&Hum 18 I2C writing function.
temphum18_init
err_t temphum18_init(temphum18_t *ctx, temphum18_cfg_t *cfg)
Temp&Hum 18 initialization function.
temphum18_set_relative_humidity_resolution
err_t temphum18_set_relative_humidity_resolution(temphum18_t *ctx, uint8_t resolution)
Temp&Hum 18 set relative humidity resolution function.
temphum18_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum18.h:188