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
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 #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  // 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  // 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  // temphum16_map // temphum16
174 
179 typedef enum
180 {
185 
190 typedef err_t ( *temphum16_master_io_t )( struct temphum16_s*, uint8_t, uint8_t*, uint8_t );
196 typedef struct temphum16_s
197 {
198  digital_in_t rdy;
200  i2c_master_t i2c;
201  spi_master_t spi;
203  uint8_t slave_address;
204  pin_name_t chip_select;
211 
216 typedef 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 
241 typedef enum
242 {
244  TEMPHUM16_ERROR = -1
245 
247 
264 
280 
296 
311 
327 err_t temphum16_generic_write ( temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
328 
344 err_t temphum16_generic_read ( temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
345 
360 err_t temphum16_get_device_id ( temphum16_t *ctx, uint8_t *device_id );
361 
378 err_t temphum16_power_mode ( temphum16_t *ctx, uint8_t pwr_mode );
379 
396 err_t temphum16_bdu_mode ( temphum16_t *ctx, uint8_t bdu_mode );
397 
416 err_t temphum16_set_odr ( temphum16_t *ctx, uint8_t odr );
417 
434 err_t temphum16_heater ( temphum16_t *ctx, uint8_t heater_mode );
435 
450 
465 err_t temphum16_get_status ( temphum16_t *ctx, uint8_t *status );
466 
481 
498 err_t temphum16_get_humidity ( temphum16_t *ctx, float *humidity );
499 
516 err_t temphum16_get_temperature ( temphum16_t *ctx, float *temperature );
517 
518 #ifdef __cplusplus
519 }
520 #endif
521 #endif // TEMPHUM16_H
522  // temphum16
524 
525 // ------------------------------------------------------------------------ END
temphum16_s::i2c
i2c_master_t i2c
Definition: temphum16.h:200
temphum16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: temphum16.h:230
temphum16_s::write_f
temphum16_master_io_t write_f
Definition: temphum16.h:207
temphum16_s::slave_address
uint8_t slave_address
Definition: temphum16.h:203
temphum16_default_cfg
err_t temphum16_default_cfg(temphum16_t *ctx)
Temp&Hum 16 default configuration function.
temphum16_cfg_t
Temp&Hum 16 Click configuration object.
Definition: temphum16.h:217
temphum16_cfg_t::rdy
pin_name_t rdy
Definition: temphum16.h:224
temphum16_cfg_t::sda
pin_name_t sda
Definition: temphum16.h:219
temphum16_get_status
err_t temphum16_get_status(temphum16_t *ctx, uint8_t *status)
Temp&Hum 16 get status function.
temphum16_generic_read
err_t temphum16_generic_read(temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Temp&Hum 16 data reading function.
temphum16_s::drv_sel
temphum16_drv_t drv_sel
Definition: temphum16.h:205
temphum16_power_mode
err_t temphum16_power_mode(temphum16_t *ctx, uint8_t pwr_mode)
Temp&Hum 16 set power mode function.
temphum16_drv_t
temphum16_drv_t
Temp&Hum 16 Click driver selector.
Definition: temphum16.h:180
temphum16_get_humidity
err_t temphum16_get_humidity(temphum16_t *ctx, float *humidity)
Temp&Hum 16 get humidity function.
temphum16_get_device_id
err_t temphum16_get_device_id(temphum16_t *ctx, uint8_t *device_id)
Temp&Hum 16 get device ID function.
temphum16_cfg_t::cs
pin_name_t cs
Definition: temphum16.h:223
temphum16_cfg_t::drv_sel
temphum16_drv_t drv_sel
Definition: temphum16.h:233
temphum16_check_ready
uint8_t temphum16_check_ready(temphum16_t *ctx)
Temp&Hum 16 check ready function.
temphum16_drv_interface_selection
void temphum16_drv_interface_selection(temphum16_cfg_t *cfg, temphum16_drv_t drv_sel)
Temp&Hum 16 driver interface setup function.
temphum16_master_io_t
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_s::spi
spi_master_t spi
Definition: temphum16.h:201
temphum16_s
Temp&Hum 16 Click context object.
Definition: temphum16.h:197
temphum16_cfg_setup
void temphum16_cfg_setup(temphum16_cfg_t *cfg)
Temp&Hum 16 configuration object setup function.
TEMPHUM16_ERROR
@ TEMPHUM16_ERROR
Definition: temphum16.h:244
temphum16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: temphum16.h:231
temphum16_cfg_t::miso
pin_name_t miso
Definition: temphum16.h:220
TEMPHUM16_OK
@ TEMPHUM16_OK
Definition: temphum16.h:243
temphum16_t
struct temphum16_s temphum16_t
Temp&Hum 16 Click context object.
temphum16_cfg_t::mosi
pin_name_t mosi
Definition: temphum16.h:221
temphum16_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum16.h:227
temphum16_bdu_mode
err_t temphum16_bdu_mode(temphum16_t *ctx, uint8_t bdu_mode)
Temp&Hum 16 set block data update mode function.
TEMPHUM16_DRV_SEL_I2C
@ TEMPHUM16_DRV_SEL_I2C
Definition: temphum16.h:182
temphum16_s::chip_select
pin_name_t chip_select
Definition: temphum16.h:204
temphum16_enable_data_ready_interrupt
err_t temphum16_enable_data_ready_interrupt(temphum16_t *ctx)
Temp&Hum 16 enable data ready interrupt function.
temphum16_cfg_t::scl
pin_name_t scl
Definition: temphum16.h:218
temphum16_s::rdy
digital_in_t rdy
Definition: temphum16.h:198
temphum16_heater
err_t temphum16_heater(temphum16_t *ctx, uint8_t heater_mode)
Temp&Hum 16 heater function.
temphum16_return_value_t
temphum16_return_value_t
Temp&Hum 16 Click return value data.
Definition: temphum16.h:242
temphum16_set_odr
err_t temphum16_set_odr(temphum16_t *ctx, uint8_t odr)
Temp&Hum 16 set output data rate function.
temphum16_cfg_t::spi_speed
uint32_t spi_speed
Definition: temphum16.h:229
TEMPHUM16_DRV_SEL_SPI
@ TEMPHUM16_DRV_SEL_SPI
Definition: temphum16.h:181
temphum16_generic_write
err_t temphum16_generic_write(temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Temp&Hum 16 data writing function.
temphum16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum16.h:226
temphum16_s::read_f
temphum16_master_io_t read_f
Definition: temphum16.h:208
temphum16_init
err_t temphum16_init(temphum16_t *ctx, temphum16_cfg_t *cfg)
Temp&Hum 16 initialization function.
temphum16_cfg_t::sck
pin_name_t sck
Definition: temphum16.h:222
temphum16_get_temperature
err_t temphum16_get_temperature(temphum16_t *ctx, float *temperature)
Temp&Hum 16 get temperature function.