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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
74 #define TEMPHUM15_CMD_MEASURE_HIGH_PRECISION 0xFD
75 #define TEMPHUM15_CMD_MEASURE_MEDIUM_PRECISION 0xF6
76 #define TEMPHUM15_CMD_MEASURE_LOW_PRECISION 0xE0
77 #define TEMPHUM15_CMD_READ_SERIAL 0x89
78 #define TEMPHUM15_CMD_SOFT_RESET 0x94
79 #define TEMPHUM15_CMD_HEATER_HIGHEST_POW_HIGH_DUR 0x39
80 #define TEMPHUM15_CMD_HEATER_HIGHEST_POW_LOW_DUR 0x32
81 #define TEMPHUM15_CMD_HEATER_MEDIUM_POW_HIGH_DUR 0x2F
82 #define TEMPHUM15_CMD_HEATER_MEDIUM_POW_LOW_DUR 0x24
83 #define TEMPHUM15_CMD_HEATER_LOWEST_POW_HIGH_DUR 0x1E
84 #define TEMPHUM15_CMD_HEATER_LOWEST_POW_LOW_DUR 0x15
85  // temphum15_cmd
87 
103 #define TEMPHUM15_SET_DEV_ADDR 0x44
104  // temphum15_set
106 
118 #define TEMPHUM15_MODE_HIGH_PRECISION 0x00
119 #define TEMPHUM15_MODE_MEDIUM_PRECISION 0x01
120 #define TEMPHUM15_MODE_LOW_PRECISION 0x02
121  // precision_mode
123 
135 #define TEMPHUM15_SUCCESS 0
136 #define TEMPHUM15_ERROR -1
137  // status
139 
154 #define TEMPHUM15_MAP_MIKROBUS( cfg, mikrobus ) \
155  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
156  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
157  // temphum15_map // temphum15
160 
165 typedef struct
166 {
167  // Modules
168 
169  i2c_master_t i2c;
171  // I2C slave address
172 
173  uint8_t slave_address;
175 } temphum15_t;
176 
181 typedef struct
182 {
183  pin_name_t scl;
184  pin_name_t sda;
186  uint32_t i2c_speed;
187  uint8_t i2c_address;
190 
209 
227 
244 
262 err_t temphum15_generic_write ( temphum15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
263 
281 err_t temphum15_generic_read ( temphum15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
282 
300 err_t temphum15_get_temp_and_hum ( temphum15_t *ctx, uint8_t precision_mode, float *temp_val, float *hum_val );
301 
316 
331 err_t temphum15_read_serial ( temphum15_t *ctx, uint32_t *serial_number );
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 #endif // TEMPHUM15_H
337  // temphum15
339 
340 // ------------------------------------------------------------------------ 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:186
temphum15_cfg_t
Temp&Hum 15 Click configuration object.
Definition: temphum15.h:182
temphum15_t::i2c
i2c_master_t i2c
Definition: temphum15.h:169
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:187
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:166
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:184
temphum15_t::slave_address
uint8_t slave_address
Definition: temphum15.h:173
temphum15_cfg_t::scl
pin_name_t scl
Definition: temphum15.h:183
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.