temphum16 2.0.0.0
temphum16.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 TEMPHUM16_H
29#define TEMPHUM16_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_i2c_master.h"
38#include "drv_spi_master.h"
39
60#define TEMPHUM16_REG_DEVICE_ID 0x0F
61#define TEMPHUM16_REG_AVERAGE 0x10
62#define TEMPHUM16_REG_CTRL_1 0x20
63#define TEMPHUM16_REG_CTRL_2 0x21
64#define TEMPHUM16_REG_CTRL_3 0x22
65#define TEMPHUM16_REG_STATUS 0x27
66#define TEMPHUM16_REG_H_OUT_L 0x28
67#define TEMPHUM16_REG_H_OUT_H 0x29
68#define TEMPHUM16_REG_T_OUT_L 0x2A
69#define TEMPHUM16_REG_T_OUT_H 0x2B
70#define TEMPHUM16_REG_H0_RH_X2 0x30
71#define TEMPHUM16_REG_H1_RH_X2 0x31
72#define TEMPHUM16_REG_T0_DEGC_X8 0x32
73#define TEMPHUM16_REG_T1_DEGC_X8 0x33
74#define TEMPHUM16_REG_T0_T1_DEGC_H2 0x35
75#define TEMPHUM16_REG_H0_T0_OUT_L 0x36
76#define TEMPHUM16_REG_H0_T0_OUT_H 0x37
77#define TEMPHUM16_REG_H1_T0_OUT_L 0x3A
78#define TEMPHUM16_REG_H1_T0_OUT_H 0x3B
79#define TEMPHUM16_REG_T0_OUT_L 0x3C
80#define TEMPHUM16_REG_T0_OUT_H 0x3D
81#define TEMPHUM16_REG_T1_OUT_L 0x3E
82#define TEMPHUM16_REG_T1_OUT_H 0x3F
83 // temphum16_reg
85
100#define TEMPHUM16_PWR_MODE_POWER_DOWN 0x00
101#define TEMPHUM16_PWR_MODE_CONTINUOUS 0x01
102
103#define TEMPHUM16_BDU_CONTINUOUS_UPDATE 0x00
104#define TEMPHUM16_BDU_NOT_UPDAT_UNTIL_READ 0x01
105
106#define TEMPHUM16_ODR_ONE_SHOT_MODE 0x00
107#define TEMPHUM16_ODR_1_Hz 0x01
108#define TEMPHUM16_ODR_7_Hz 0x02
109#define TEMPHUM16_ODR_12_5_Hz 0x03
110
111#define TEMPHUM16_HEATER_DISABLE 0x00
112#define TEMPHUM16_HEATER_ENABLE 0x01
113
118#define TEMPHUM16_DEVICE_ID 0xBC
119
124#define TEMPHUM16_DRDY 0x01
125
131#define TEMPHUM16_SET_DEV_ADDR 0x5F
132 // temphum16_set
134
149#define TEMPHUM16_MAP_MIKROBUS( cfg, mikrobus ) \
150 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
151 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
152 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
153 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
154 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
155 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
156 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
157 // temphum16_map // temphum16
160
165typedef enum
166{
171
176typedef err_t ( *temphum16_master_io_t )( struct temphum16_s*, uint8_t, uint8_t*, uint8_t );
182typedef struct temphum16_s
183{
184 digital_in_t rdy;
186 i2c_master_t i2c;
187 spi_master_t spi;
190 pin_name_t chip_select;
197
202typedef struct
203{
204 pin_name_t scl;
205 pin_name_t sda;
206 pin_name_t miso;
207 pin_name_t mosi;
208 pin_name_t sck;
209 pin_name_t cs;
210 pin_name_t rdy;
212 uint32_t i2c_speed;
213 uint8_t i2c_address;
215 uint32_t spi_speed;
216 spi_master_mode_t spi_mode;
217 spi_master_chip_select_polarity_t cs_polarity;
222
227typedef enum
228{
230 TEMPHUM16_ERROR = -1
231
233
250
266
282
297
313err_t temphum16_generic_write ( temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
314
330err_t temphum16_generic_read ( temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
331
346err_t temphum16_get_device_id ( temphum16_t *ctx, uint8_t *device_id );
347
364err_t temphum16_power_mode ( temphum16_t *ctx, uint8_t pwr_mode );
365
382err_t temphum16_bdu_mode ( temphum16_t *ctx, uint8_t bdu_mode );
383
402err_t temphum16_set_odr ( temphum16_t *ctx, uint8_t odr );
403
420err_t temphum16_heater ( temphum16_t *ctx, uint8_t heater_mode );
421
436
451err_t temphum16_get_status ( temphum16_t *ctx, uint8_t *status );
452
467
484err_t temphum16_get_humidity ( temphum16_t *ctx, float *humidity );
485
502err_t temphum16_get_temperature ( temphum16_t *ctx, float *temperature );
503
504#ifdef __cplusplus
505}
506#endif
507#endif // TEMPHUM16_H
508 // temphum16
510
511// ------------------------------------------------------------------------ END
err_t temphum16_generic_write(temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Temp&Hum 16 data writing function.
err_t temphum16_bdu_mode(temphum16_t *ctx, uint8_t bdu_mode)
Temp&Hum 16 set block data update mode function.
err_t temphum16_default_cfg(temphum16_t *ctx)
Temp&Hum 16 default configuration function.
err_t temphum16_heater(temphum16_t *ctx, uint8_t heater_mode)
Temp&Hum 16 heater function.
err_t temphum16_get_status(temphum16_t *ctx, uint8_t *status)
Temp&Hum 16 get status function.
err_t temphum16_get_device_id(temphum16_t *ctx, uint8_t *device_id)
Temp&Hum 16 get device ID function.
void temphum16_drv_interface_selection(temphum16_cfg_t *cfg, temphum16_drv_t drv_sel)
Temp&Hum 16 driver interface setup function.
uint8_t temphum16_check_ready(temphum16_t *ctx)
Temp&Hum 16 check ready function.
err_t temphum16_get_humidity(temphum16_t *ctx, float *humidity)
Temp&Hum 16 get humidity function.
err_t temphum16_get_temperature(temphum16_t *ctx, float *temperature)
Temp&Hum 16 get temperature function.
err_t temphum16_power_mode(temphum16_t *ctx, uint8_t pwr_mode)
Temp&Hum 16 set power mode function.
void temphum16_cfg_setup(temphum16_cfg_t *cfg)
Temp&Hum 16 configuration object setup function.
err_t temphum16_enable_data_ready_interrupt(temphum16_t *ctx)
Temp&Hum 16 enable data ready interrupt function.
err_t temphum16_init(temphum16_t *ctx, temphum16_cfg_t *cfg)
Temp&Hum 16 initialization function.
err_t temphum16_generic_read(temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Temp&Hum 16 data reading function.
err_t temphum16_set_odr(temphum16_t *ctx, uint8_t odr)
Temp&Hum 16 set output data rate function.
Temp&Hum 16 Click configuration object.
Definition: temphum16.h:203
temphum16_drv_t drv_sel
Definition: temphum16.h:219
uint32_t i2c_speed
Definition: temphum16.h:212
spi_master_chip_select_polarity_t cs_polarity
Definition: temphum16.h:217
pin_name_t sck
Definition: temphum16.h:208
spi_master_mode_t spi_mode
Definition: temphum16.h:216
pin_name_t mosi
Definition: temphum16.h:207
uint32_t spi_speed
Definition: temphum16.h:215
pin_name_t scl
Definition: temphum16.h:204
pin_name_t rdy
Definition: temphum16.h:210
pin_name_t miso
Definition: temphum16.h:206
pin_name_t sda
Definition: temphum16.h:205
pin_name_t cs
Definition: temphum16.h:209
uint8_t i2c_address
Definition: temphum16.h:213
Temp&Hum 16 Click context object.
Definition: temphum16.h:183
spi_master_t spi
Definition: temphum16.h:187
temphum16_drv_t drv_sel
Definition: temphum16.h:191
temphum16_master_io_t read_f
Definition: temphum16.h:194
temphum16_master_io_t write_f
Definition: temphum16.h:193
i2c_master_t i2c
Definition: temphum16.h:186
uint8_t slave_address
Definition: temphum16.h:189
pin_name_t chip_select
Definition: temphum16.h:190
digital_in_t rdy
Definition: temphum16.h:184
err_t(* temphum16_master_io_t)(struct temphum16_s *, uint8_t, uint8_t *, uint8_t)
Temp&Hum 16 Click driver interface.
Definition: temphum16.h:176
temphum16_return_value_t
Temp&Hum 16 Click return value data.
Definition: temphum16.h:228
@ TEMPHUM16_ERROR
Definition: temphum16.h:230
@ TEMPHUM16_OK
Definition: temphum16.h:229
struct temphum16_s temphum16_t
Temp&Hum 16 Click context object.
temphum16_drv_t
Temp&Hum 16 Click driver selector.
Definition: temphum16.h:166
@ TEMPHUM16_DRV_SEL_SPI
Definition: temphum16.h:167
@ TEMPHUM16_DRV_SEL_I2C
Definition: temphum16.h:168