temphum27 2.2.0
Loading...
Searching...
No Matches
temphum27.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
27
28#ifndef TEMPHUM27_H
29#define TEMPHUM27_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
58
63
68
73#define TEMPHUM27_CMD_HOLD_TEMP_MEAS 0xE3
74#define TEMPHUM27_CMD_NO_HOLD_TEMP_MEAS 0xF3
75#define TEMPHUM27_CMD_HOLD_TEMP_HUM_MEAS 0xE5
76#define TEMPHUM27_CMD_NO_HOLD_TEMP_HUM_MEAS 0xF5
77#define TEMPHUM27_CMD_READ_REG 0xA7
78#define TEMPHUM27_CMD_WRITE_REG 0xA6
79#define TEMPHUM27_CMD_STOP_PERIODIC_MEAS 0x30
80#define TEMPHUM27_CMD_READ_SENSOR_ID 0xD7
81
86#define TEMPHUM27_REG_MEAS_RESOLUTION 0x00
87#define TEMPHUM27_REG_PERIODIC_CONFIG 0x02
88#define TEMPHUM27_REG_ALERT_ENABLE 0x03
89#define TEMPHUM27_REG_RST_THOLD_TEMP_H_LSB 0x05
90#define TEMPHUM27_REG_RST_THOLD_TEMP_H_MSB 0x06
91#define TEMPHUM27_REG_TRG_THOLD_TEMP_H_LSB 0x07
92#define TEMPHUM27_REG_TRG_THOLD_TEMP_H_MSB 0x08
93#define TEMPHUM27_REG_TRG_THOLD_TEMP_L_LSB 0x09
94#define TEMPHUM27_REG_TRG_THOLD_TEMP_L_MSB 0x0A
95#define TEMPHUM27_REG_RST_THOLD_TEMP_L_LSB 0x0B
96#define TEMPHUM27_REG_RST_THOLD_TEMP_L_MSB 0x0C
97#define TEMPHUM27_REG_RST_THOLD_HUM_H_LSB 0x0D
98#define TEMPHUM27_REG_RST_THOLD_HUM_H_MSB 0x0E
99#define TEMPHUM27_REG_TRG_THOLD_HUM_H_LSB 0x0F
100#define TEMPHUM27_REG_TRG_THOLD_HUM_H_MSB 0x10
101#define TEMPHUM27_REG_TRG_THOLD_HUM_L_LSB 0x11
102#define TEMPHUM27_REG_TRG_THOLD_HUM_L_MSB 0x12
103#define TEMPHUM27_REG_RST_THOLD_HUM_L_LSB 0x13
104#define TEMPHUM27_REG_RST_THOLD_HUM_L_MSB 0x14
105 // temphum27_reg
107
112
117
122#define TEMPHUM27_PERIODIC_CONFIG_ACTIVATE 0x80
123#define TEMPHUM27_PERIODIC_CONFIG_FREQ_0_5S 0x00
124#define TEMPHUM27_PERIODIC_CONFIG_FREQ_1S 0x10
125#define TEMPHUM27_PERIODIC_CONFIG_FREQ_2_5S 0x20
126#define TEMPHUM27_PERIODIC_CONFIG_FREQ_MASK 0x30
127#define TEMPHUM27_PERIODIC_CONFIG_ALR_POL_LOW 0x00
128#define TEMPHUM27_PERIODIC_CONFIG_ALR_POL_HIGH 0x01
129#define TEMPHUM27_PERIODIC_CONFIG_ALR_POL_MASK 0x01
130
135#define TEMPHUM27_PERIODIC_FREQ_0_5S 0
136#define TEMPHUM27_PERIODIC_FREQ_1S 1
137#define TEMPHUM27_PERIODIC_FREQ_2_5S 2
138
143#define TEMPHUM27_DATA_RESOLUTION 0x3FFF
144#define TEMPHUM27_TEMP_DATA_RES 165
145#define TEMPHUM27_TEMP_DATA_OFFSET 40
146#define TEMPHUM27_HUM_DATA_RES 100
147
153#define TEMPHUM27_DEVICE_ADDRESS 0x54
154 // temphum27_set
156
161
166
171#define TEMPHUM27_MAP_MIKROBUS( cfg, mikrobus ) \
172 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
174 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
175 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
176 // temphum27_map // temphum27
179
184typedef struct
185{
186 // Output pins
187 digital_out_t en;
188
189 // Input pins
190 digital_in_t alr;
191
192 // Modules
193 i2c_master_t i2c;
194
195 // I2C slave address
197
199
204typedef struct
205{
206 pin_name_t scl;
207 pin_name_t sda;
208
209 pin_name_t en;
210 pin_name_t alr;
211
212 uint32_t i2c_speed;
213 uint8_t i2c_address;
214
216
227
233
244
259
271err_t temphum27_write_reg ( temphum27_t *ctx, uint8_t reg, uint8_t data_in );
272
284err_t temphum27_read_reg ( temphum27_t *ctx, uint8_t reg, uint8_t *data_out );
285
297err_t temphum27_read_data_hold ( temphum27_t *ctx, float *temp, float *hum );
298
310err_t temphum27_read_data_no_hold ( temphum27_t *ctx, float *temp, float *hum );
311
325err_t temphum27_start_periodic_meas ( temphum27_t *ctx, uint8_t freq );
326
337
349err_t temphum27_read_data_periodic ( temphum27_t *ctx, float *temp, float *hum );
350
363err_t temphum27_read_data_periodic_al ( temphum27_t *ctx, float *temp, float *hum, uint8_t *alert );
364
375err_t temphum27_read_sensor_id ( temphum27_t *ctx, uint32_t *sensor_id );
376
386
396
406
416
417#ifdef __cplusplus
418}
419#endif
420#endif // TEMPHUM27_H
421 // temphum27
423
424// ------------------------------------------------------------------------ END
err_t temphum27_read_reg(temphum27_t *ctx, uint8_t reg, uint8_t *data_out)
TempHum 27 read register function.
err_t temphum27_read_data_no_hold(temphum27_t *ctx, float *temp, float *hum)
TempHum 27 read data (no hold mode) function.
err_t temphum27_read_data_hold(temphum27_t *ctx, float *temp, float *hum)
TempHum 27 read data (hold mode) function.
err_t temphum27_stop_periodic_meas(temphum27_t *ctx)
TempHum 27 stop periodic measurement function.
err_t temphum27_read_sensor_id(temphum27_t *ctx, uint32_t *sensor_id)
TempHum 27 read sensor ID function.
uint8_t temphum27_get_alert_pin(temphum27_t *ctx)
TempHum 27 get alert pin function.
err_t temphum27_write_reg(temphum27_t *ctx, uint8_t reg, uint8_t data_in)
TempHum 27 write register function.
void temphum27_cfg_setup(temphum27_cfg_t *cfg)
TempHum 27 configuration object setup function.
err_t temphum27_read_data_periodic_al(temphum27_t *ctx, float *temp, float *hum, uint8_t *alert)
TempHum 27 read data and alert in periodic mode function.
err_t temphum27_read_data_periodic(temphum27_t *ctx, float *temp, float *hum)
TempHum 27 read data in periodic mode function.
void temphum27_disable_device(temphum27_t *ctx)
TempHum 27 disable device function.
void temphum27_enable_device(temphum27_t *ctx)
TempHum 27 enable device function.
err_t temphum27_init(temphum27_t *ctx, temphum27_cfg_t *cfg)
TempHum 27 initialization function.
err_t temphum27_start_periodic_meas(temphum27_t *ctx, uint8_t freq)
TempHum 27 start periodic measurement function.
void temphum27_reset_device(temphum27_t *ctx)
TempHum 27 reset device function.
TempHum 27 Click configuration object.
Definition temphum27.h:205
pin_name_t alr
Definition temphum27.h:210
uint32_t i2c_speed
Definition temphum27.h:212
pin_name_t scl
Definition temphum27.h:206
pin_name_t en
Definition temphum27.h:209
pin_name_t sda
Definition temphum27.h:207
uint8_t i2c_address
Definition temphum27.h:213
TempHum 27 Click context object.
Definition temphum27.h:185
digital_in_t alr
Definition temphum27.h:190
i2c_master_t i2c
Definition temphum27.h:193
digital_out_t en
Definition temphum27.h:187
uint8_t slave_address
Definition temphum27.h:196
temphum27_return_value_t
TempHum 27 Click return value data.
Definition temphum27.h:222
@ TEMPHUM27_OK
Definition temphum27.h:223
@ TEMPHUM27_ERROR
Definition temphum27.h:224