temphum15  2.0.0.0
temphum15.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 TEMPHUM15_H
29 #define TEMPHUM15_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 
60 #define TEMPHUM15_CMD_MEASURE_HIGH_PRECISION 0xFD
61 #define TEMPHUM15_CMD_MEASURE_MEDIUM_PRECISION 0xF6
62 #define TEMPHUM15_CMD_MEASURE_LOW_PRECISION 0xE0
63 #define TEMPHUM15_CMD_READ_SERIAL 0x89
64 #define TEMPHUM15_CMD_SOFT_RESET 0x94
65 #define TEMPHUM15_CMD_HEATER_HIGHEST_POW_HIGH_DUR 0x39
66 #define TEMPHUM15_CMD_HEATER_HIGHEST_POW_LOW_DUR 0x32
67 #define TEMPHUM15_CMD_HEATER_MEDIUM_POW_HIGH_DUR 0x2F
68 #define TEMPHUM15_CMD_HEATER_MEDIUM_POW_LOW_DUR 0x24
69 #define TEMPHUM15_CMD_HEATER_LOWEST_POW_HIGH_DUR 0x1E
70 #define TEMPHUM15_CMD_HEATER_LOWEST_POW_LOW_DUR 0x15
71  // temphum15_cmd
73 
89 #define TEMPHUM15_SET_DEV_ADDR 0x44
90  // temphum15_set
92 
104 #define TEMPHUM15_MODE_HIGH_PRECISION 0x00
105 #define TEMPHUM15_MODE_MEDIUM_PRECISION 0x01
106 #define TEMPHUM15_MODE_LOW_PRECISION 0x02
107  // precision_mode
109 
121 #define TEMPHUM15_SUCCESS 0
122 #define TEMPHUM15_ERROR -1
123  // status
125 
140 #define TEMPHUM15_MAP_MIKROBUS( cfg, mikrobus ) \
141  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
142  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
143  // temphum15_map // temphum15
146 
151 typedef struct
152 {
153  // Modules
154 
155  i2c_master_t i2c;
157  // I2C slave address
158 
159  uint8_t slave_address;
161 } temphum15_t;
162 
167 typedef struct
168 {
169  pin_name_t scl;
170  pin_name_t sda;
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
176 
195 
213 
230 
248 err_t temphum15_generic_write ( temphum15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
249 
267 err_t temphum15_generic_read ( temphum15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
268 
286 err_t temphum15_get_temp_and_hum ( temphum15_t *ctx, uint8_t precision_mode, float *temp_val, float *hum_val );
287 
302 
317 err_t temphum15_read_serial ( temphum15_t *ctx, uint32_t *serial_number );
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 #endif // TEMPHUM15_H
323  // temphum15
325 
326 // ------------------------------------------------------------------------ END
temphum15_generic_write
err_t temphum15_generic_write(temphum15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Temp&Hum 15 I2C writing function.
temphum15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum15.h:172
temphum15_cfg_t
Temp&Hum 15 Click configuration object.
Definition: temphum15.h:168
temphum15_t::i2c
i2c_master_t i2c
Definition: temphum15.h:155
temphum15_init
err_t temphum15_init(temphum15_t *ctx, temphum15_cfg_t *cfg)
Temp&Hum 15 initialization function.
temphum15_default_cfg
err_t temphum15_default_cfg(temphum15_t *ctx)
Temp&Hum 15 default configuration function.
temphum15_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum15.h:173
temphum15_generic_read
err_t temphum15_generic_read(temphum15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Temp&Hum 15 I2C reading function.
temphum15_t
Temp&Hum 15 Click context object.
Definition: temphum15.h:152
temphum15_cfg_setup
void temphum15_cfg_setup(temphum15_cfg_t *cfg)
Temp&Hum 15 configuration object setup function.
temphum15_read_serial
err_t temphum15_read_serial(temphum15_t *ctx, uint32_t *serial_number)
Temp&Hum 15 read serial number function.
temphum15_cfg_t::sda
pin_name_t sda
Definition: temphum15.h:170
temphum15_t::slave_address
uint8_t slave_address
Definition: temphum15.h:159
temphum15_cfg_t::scl
pin_name_t scl
Definition: temphum15.h:169
temphum15_get_temp_and_hum
err_t temphum15_get_temp_and_hum(temphum15_t *ctx, uint8_t precision_mode, float *temp_val, float *hum_val)
Temp&Hum 15 get temperature and humidity function.
temphum15_soft_reset
err_t temphum15_soft_reset(temphum15_t *ctx)
Temp&Hum 15 soft reset function.