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
32extern "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
86 // temphum15_cmd
87
103#define TEMPHUM15_SET_DEV_ADDR 0x44
104
105 // 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
122 // precision_mode
123
135#define TEMPHUM15_SUCCESS 0
136#define TEMPHUM15_ERROR -1
137
138 // status
139
154#define TEMPHUM15_MAP_MIKROBUS( cfg, mikrobus ) \
155 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
156 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
157
158 // temphum15_map
159 // temphum15
160
165typedef struct
166{
167 // Modules
168
169 i2c_master_t i2c;
171 // I2C slave address
172
176
181typedef 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
262err_t temphum15_generic_write ( temphum15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
263
281err_t temphum15_generic_read ( temphum15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
282
300err_t temphum15_get_temp_and_hum ( temphum15_t *ctx, uint8_t precision_mode, float *temp_val, float *hum_val );
301
316
331err_t temphum15_read_serial ( temphum15_t *ctx, uint32_t *serial_number );
332
333#ifdef __cplusplus
334}
335#endif
336#endif // TEMPHUM15_H
337
338 // temphum15
339
340// ------------------------------------------------------------------------ END
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.
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.
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.
err_t temphum15_soft_reset(temphum15_t *ctx)
Temp&Hum 15 soft reset function.
err_t temphum15_read_serial(temphum15_t *ctx, uint32_t *serial_number)
Temp&Hum 15 read serial number function.
void temphum15_cfg_setup(temphum15_cfg_t *cfg)
Temp&Hum 15 configuration object setup function.
err_t temphum15_init(temphum15_t *ctx, temphum15_cfg_t *cfg)
Temp&Hum 15 initialization function.
err_t temphum15_default_cfg(temphum15_t *ctx)
Temp&Hum 15 default configuration function.
Temp&Hum 15 Click configuration object.
Definition temphum15.h:182
uint32_t i2c_speed
Definition temphum15.h:186
pin_name_t scl
Definition temphum15.h:183
pin_name_t sda
Definition temphum15.h:184
uint8_t i2c_address
Definition temphum15.h:187
Temp&Hum 15 Click context object.
Definition temphum15.h:166
i2c_master_t i2c
Definition temphum15.h:169
uint8_t slave_address
Definition temphum15.h:173