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
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#include "drv_spi_master.h"
53
74#define TEMPHUM16_REG_DEVICE_ID 0x0F
75#define TEMPHUM16_REG_AVERAGE 0x10
76#define TEMPHUM16_REG_CTRL_1 0x20
77#define TEMPHUM16_REG_CTRL_2 0x21
78#define TEMPHUM16_REG_CTRL_3 0x22
79#define TEMPHUM16_REG_STATUS 0x27
80#define TEMPHUM16_REG_H_OUT_L 0x28
81#define TEMPHUM16_REG_H_OUT_H 0x29
82#define TEMPHUM16_REG_T_OUT_L 0x2A
83#define TEMPHUM16_REG_T_OUT_H 0x2B
84#define TEMPHUM16_REG_H0_RH_X2 0x30
85#define TEMPHUM16_REG_H1_RH_X2 0x31
86#define TEMPHUM16_REG_T0_DEGC_X8 0x32
87#define TEMPHUM16_REG_T1_DEGC_X8 0x33
88#define TEMPHUM16_REG_T0_T1_DEGC_H2 0x35
89#define TEMPHUM16_REG_H0_T0_OUT_L 0x36
90#define TEMPHUM16_REG_H0_T0_OUT_H 0x37
91#define TEMPHUM16_REG_H1_T0_OUT_L 0x3A
92#define TEMPHUM16_REG_H1_T0_OUT_H 0x3B
93#define TEMPHUM16_REG_T0_OUT_L 0x3C
94#define TEMPHUM16_REG_T0_OUT_H 0x3D
95#define TEMPHUM16_REG_T1_OUT_L 0x3E
96#define TEMPHUM16_REG_T1_OUT_H 0x3F
97
98 // temphum16_reg
99
114#define TEMPHUM16_PWR_MODE_POWER_DOWN 0x00
115#define TEMPHUM16_PWR_MODE_CONTINUOUS 0x01
116
117#define TEMPHUM16_BDU_CONTINUOUS_UPDATE 0x00
118#define TEMPHUM16_BDU_NOT_UPDAT_UNTIL_READ 0x01
119
120#define TEMPHUM16_ODR_ONE_SHOT_MODE 0x00
121#define TEMPHUM16_ODR_1_Hz 0x01
122#define TEMPHUM16_ODR_7_Hz 0x02
123#define TEMPHUM16_ODR_12_5_Hz 0x03
124
125#define TEMPHUM16_HEATER_DISABLE 0x00
126#define TEMPHUM16_HEATER_ENABLE 0x01
127
132#define TEMPHUM16_DEVICE_ID 0xBC
133
138#define TEMPHUM16_DRDY 0x01
139
145#define TEMPHUM16_SET_DEV_ADDR 0x5F
146
147 // temphum16_set
148
163#define TEMPHUM16_MAP_MIKROBUS( cfg, mikrobus ) \
164 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
165 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
166 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
167 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
168 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
169 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
170 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
171
172 // temphum16_map
173 // temphum16
174
185
190typedef err_t ( *temphum16_master_io_t )( struct temphum16_s*, uint8_t, uint8_t*, uint8_t );
211
216typedef struct
217{
218 pin_name_t scl;
219 pin_name_t sda;
220 pin_name_t miso;
221 pin_name_t mosi;
222 pin_name_t sck;
223 pin_name_t cs;
224 pin_name_t rdy;
226 uint32_t i2c_speed;
227 uint8_t i2c_address;
229 uint32_t spi_speed;
230 spi_master_mode_t spi_mode;
231 spi_master_chip_select_polarity_t cs_polarity;
236
247
264
280
296
311
327err_t temphum16_generic_write ( temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
328
344err_t temphum16_generic_read ( temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
345
360err_t temphum16_get_device_id ( temphum16_t *ctx, uint8_t *device_id );
361
378err_t temphum16_power_mode ( temphum16_t *ctx, uint8_t pwr_mode );
379
396err_t temphum16_bdu_mode ( temphum16_t *ctx, uint8_t bdu_mode );
397
416err_t temphum16_set_odr ( temphum16_t *ctx, uint8_t odr );
417
434err_t temphum16_heater ( temphum16_t *ctx, uint8_t heater_mode );
435
450
465err_t temphum16_get_status ( temphum16_t *ctx, uint8_t *status );
466
481
498err_t temphum16_get_humidity ( temphum16_t *ctx, float *humidity );
499
516err_t temphum16_get_temperature ( temphum16_t *ctx, float *temperature );
517
518#ifdef __cplusplus
519}
520#endif
521#endif // TEMPHUM16_H
522
523 // temphum16
524
525// ------------------------------------------------------------------------ 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:217
temphum16_drv_t drv_sel
Definition temphum16.h:233
uint32_t i2c_speed
Definition temphum16.h:226
spi_master_chip_select_polarity_t cs_polarity
Definition temphum16.h:231
pin_name_t sck
Definition temphum16.h:222
spi_master_mode_t spi_mode
Definition temphum16.h:230
pin_name_t mosi
Definition temphum16.h:221
uint32_t spi_speed
Definition temphum16.h:229
pin_name_t scl
Definition temphum16.h:218
pin_name_t rdy
Definition temphum16.h:224
pin_name_t miso
Definition temphum16.h:220
pin_name_t sda
Definition temphum16.h:219
pin_name_t cs
Definition temphum16.h:223
uint8_t i2c_address
Definition temphum16.h:227
Temp&Hum 16 Click context object.
Definition temphum16.h:197
spi_master_t spi
Definition temphum16.h:201
temphum16_drv_t drv_sel
Definition temphum16.h:205
temphum16_master_io_t read_f
Definition temphum16.h:208
temphum16_master_io_t write_f
Definition temphum16.h:207
i2c_master_t i2c
Definition temphum16.h:200
uint8_t slave_address
Definition temphum16.h:203
pin_name_t chip_select
Definition temphum16.h:204
digital_in_t rdy
Definition temphum16.h:198
err_t(* temphum16_master_io_t)(struct temphum16_s *, uint8_t, uint8_t *, uint8_t)
Temp&Hum 16 Click driver interface.
Definition temphum16.h:190
temphum16_return_value_t
Temp&Hum 16 Click return value data.
Definition temphum16.h:242
@ TEMPHUM16_ERROR
Definition temphum16.h:244
@ TEMPHUM16_OK
Definition temphum16.h:243
struct temphum16_s temphum16_t
Temp&Hum 16 Click context object.
temphum16_drv_t
Temp&Hum 16 Click driver selector.
Definition temphum16.h:180
@ TEMPHUM16_DRV_SEL_SPI
Definition temphum16.h:181
@ TEMPHUM16_DRV_SEL_I2C
Definition temphum16.h:182