temphum20 2.0.0.0
temphum20.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 TEMPHUM20_H
29#define TEMPHUM20_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
73#define TEMPHUM20_REG_PDM_CLIP_HIGH 0x16
74#define TEMPHUM20_REG_PDM_CLIP_LOW 0x17
75#define TEMPHUM20_REG_ALARM_HIGH_ON 0x18
76#define TEMPHUM20_REG_ALARM_HIGH_OFF 0x19
77#define TEMPHUM20_REG_ALARM_LOW_ON 0x1A
78#define TEMPHUM20_REG_ALARM_LOW_OFF 0x1B
79#define TEMPHUM20_REG_CUST_CONFIG 0x1C
80#define TEMPHUM20_REG_RESERVED 0x1D
81#define TEMPHUM20_REG_CUST_ID2 0x1E
82#define TEMPHUM20_REG_CUST_ID3 0x1F
83#define TEMPHUM20_CMD_START_NOM 0x80
84#define TEMPHUM20_CMD_START_CM 0xA0
85
86 // temphum20_reg
87
102#define TEMPHUM20_DATA_RESOLUTION 0x4000
103#define TEMPHUM20_TEMP_MULTIPLIER 165.0
104#define TEMPHUM20_HUM_MULTIPLIER 100.0
105#define TEMPHUM20_TEMP_OFFSET 40.0
106
111#define TEMPHUM20_STATUS_BITS_MASK 0xC0
112#define TEMPHUM20_STATUS_VALID_DATA 0x00
113#define TEMPHUM20_STATUS_STALE_DATA 0x40
114#define TEMPHUM20_STATUS_COMMAND_MODE 0x80
115
120#define TEMPHUM20_OPMODE_COMMAND 0x00
121#define TEMPHUM20_OPMODE_NORMAL 0x01
122
127#define TEMPHUM20_DUMMY 0x0000
128
134#define TEMPHUM20_SET_DEV_ADDR 0x28
135
136 // temphum20_set
137
152#define TEMPHUM20_MAP_MIKROBUS( cfg, mikrobus ) \
153 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
154 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
155 cfg.alh = MIKROBUS( mikrobus, MIKROBUS_AN ); \
156 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
157 cfg.all = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
158 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
159
160 // temphum20_map
161 // temphum20
162
167typedef struct
168{
169 // Output pins
170 digital_out_t en;
172 // Input pins
173 digital_in_t alh;
174 digital_in_t all;
175 digital_in_t int_pin;
177 // Modules
178 i2c_master_t i2c;
180 // I2C slave address
184
189typedef struct
190{
191 pin_name_t scl;
192 pin_name_t sda;
194 pin_name_t en;
195 pin_name_t alh;
196 pin_name_t all;
197 pin_name_t int_pin;
199 uint32_t i2c_speed;
200 uint8_t i2c_address;
203
214
231
247
262
276err_t temphum20_write_data ( temphum20_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
277
291err_t temphum20_read_data ( temphum20_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
292
302void temphum20_set_en_pin ( temphum20_t *ctx, uint8_t state );
303
313
323
333
343
357err_t temphum20_write_command ( temphum20_t *ctx, uint8_t cmd_byte, uint16_t cmd_data );
358
373err_t temphum20_get_measurement ( temphum20_t *ctx, float *temp, float *hum );
374
388err_t temphum20_set_operating_mode ( temphum20_t *ctx, uint8_t op_mode );
389
390#ifdef __cplusplus
391}
392#endif
393#endif // TEMPHUM20_H
394
395 // temphum20
396
397// ------------------------------------------------------------------------ END
err_t temphum20_write_command(temphum20_t *ctx, uint8_t cmd_byte, uint16_t cmd_data)
TempHum 20 write command function.
uint8_t temphum20_get_alarm_high_pin(temphum20_t *ctx)
TempHum 20 get alarm high pin function.
err_t temphum20_init(temphum20_t *ctx, temphum20_cfg_t *cfg)
TempHum 20 initialization function.
err_t temphum20_default_cfg(temphum20_t *ctx)
TempHum 20 default configuration function.
err_t temphum20_set_operating_mode(temphum20_t *ctx, uint8_t op_mode)
TempHum 20 set operating mode function.
void temphum20_reset_device(temphum20_t *ctx)
TempHum 20 reset device function.
err_t temphum20_write_data(temphum20_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
TempHum 20 I2C writing function.
err_t temphum20_get_measurement(temphum20_t *ctx, float *temp, float *hum)
TempHum 20 get measurement function.
err_t temphum20_read_data(temphum20_t *ctx, uint8_t *rx_buf, uint8_t rx_len)
TempHum 20 I2C reading function.
uint8_t temphum20_get_alarm_low_pin(temphum20_t *ctx)
TempHum 20 get alarm low pin function.
uint8_t temphum20_get_int_pin(temphum20_t *ctx)
TempHum 20 get INT pin function.
void temphum20_cfg_setup(temphum20_cfg_t *cfg)
TempHum 20 configuration object setup function.
void temphum20_set_en_pin(temphum20_t *ctx, uint8_t state)
TempHum 20 set EN pin function.
TempHum 20 Click configuration object.
Definition temphum20.h:190
pin_name_t all
Definition temphum20.h:196
uint32_t i2c_speed
Definition temphum20.h:199
pin_name_t alh
Definition temphum20.h:195
pin_name_t scl
Definition temphum20.h:191
pin_name_t en
Definition temphum20.h:194
pin_name_t int_pin
Definition temphum20.h:197
pin_name_t sda
Definition temphum20.h:192
uint8_t i2c_address
Definition temphum20.h:200
TempHum 20 Click context object.
Definition temphum20.h:168
digital_in_t all
Definition temphum20.h:174
digital_in_t int_pin
Definition temphum20.h:175
i2c_master_t i2c
Definition temphum20.h:178
digital_in_t alh
Definition temphum20.h:173
digital_out_t en
Definition temphum20.h:170
uint8_t slave_address
Definition temphum20.h:181
temphum20_return_value_t
TempHum 20 Click return value data.
Definition temphum20.h:209
@ TEMPHUM20_OK
Definition temphum20.h:210
@ TEMPHUM20_ERROR
Definition temphum20.h:211