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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_i2c_master.h"
38
59#define TEMPHUM20_REG_PDM_CLIP_HIGH 0x16
60#define TEMPHUM20_REG_PDM_CLIP_LOW 0x17
61#define TEMPHUM20_REG_ALARM_HIGH_ON 0x18
62#define TEMPHUM20_REG_ALARM_HIGH_OFF 0x19
63#define TEMPHUM20_REG_ALARM_LOW_ON 0x1A
64#define TEMPHUM20_REG_ALARM_LOW_OFF 0x1B
65#define TEMPHUM20_REG_CUST_CONFIG 0x1C
66#define TEMPHUM20_REG_RESERVED 0x1D
67#define TEMPHUM20_REG_CUST_ID2 0x1E
68#define TEMPHUM20_REG_CUST_ID3 0x1F
69#define TEMPHUM20_CMD_START_NOM 0x80
70#define TEMPHUM20_CMD_START_CM 0xA0
71 // temphum20_reg
73
88#define TEMPHUM20_DATA_RESOLUTION 0x4000
89#define TEMPHUM20_TEMP_MULTIPLIER 165.0
90#define TEMPHUM20_HUM_MULTIPLIER 100.0
91#define TEMPHUM20_TEMP_OFFSET 40.0
92
97#define TEMPHUM20_STATUS_BITS_MASK 0xC0
98#define TEMPHUM20_STATUS_VALID_DATA 0x00
99#define TEMPHUM20_STATUS_STALE_DATA 0x40
100#define TEMPHUM20_STATUS_COMMAND_MODE 0x80
101
106#define TEMPHUM20_OPMODE_COMMAND 0x00
107#define TEMPHUM20_OPMODE_NORMAL 0x01
108
113#define TEMPHUM20_DUMMY 0x0000
114
120#define TEMPHUM20_SET_DEV_ADDR 0x28
121 // temphum20_set
123
138#define TEMPHUM20_MAP_MIKROBUS( cfg, mikrobus ) \
139 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
140 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
141 cfg.alh = MIKROBUS( mikrobus, MIKROBUS_AN ); \
142 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
143 cfg.all = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
144 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
145 // temphum20_map // temphum20
148
153typedef struct
154{
155 // Output pins
156 digital_out_t en;
158 // Input pins
159 digital_in_t alh;
160 digital_in_t all;
161 digital_in_t int_pin;
163 // Modules
164 i2c_master_t i2c;
166 // I2C slave address
170
175typedef struct
176{
177 pin_name_t scl;
178 pin_name_t sda;
180 pin_name_t en;
181 pin_name_t alh;
182 pin_name_t all;
183 pin_name_t int_pin;
185 uint32_t i2c_speed;
186 uint8_t i2c_address;
189
194typedef enum
195{
197 TEMPHUM20_ERROR = -1
198
200
217
233
248
262err_t temphum20_write_data ( temphum20_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
263
277err_t temphum20_read_data ( temphum20_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
278
288void temphum20_set_en_pin ( temphum20_t *ctx, uint8_t state );
289
299
309
319
329
343err_t temphum20_write_command ( temphum20_t *ctx, uint8_t cmd_byte, uint16_t cmd_data );
344
359err_t temphum20_get_measurement ( temphum20_t *ctx, float *temp, float *hum );
360
374err_t temphum20_set_operating_mode ( temphum20_t *ctx, uint8_t op_mode );
375
376#ifdef __cplusplus
377}
378#endif
379#endif // TEMPHUM20_H
380 // temphum20
382
383// ------------------------------------------------------------------------ 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:176
pin_name_t all
Definition: temphum20.h:182
uint32_t i2c_speed
Definition: temphum20.h:185
pin_name_t alh
Definition: temphum20.h:181
pin_name_t scl
Definition: temphum20.h:177
pin_name_t en
Definition: temphum20.h:180
pin_name_t int_pin
Definition: temphum20.h:183
pin_name_t sda
Definition: temphum20.h:178
uint8_t i2c_address
Definition: temphum20.h:186
TempHum 20 Click context object.
Definition: temphum20.h:154
digital_in_t all
Definition: temphum20.h:160
digital_in_t int_pin
Definition: temphum20.h:161
i2c_master_t i2c
Definition: temphum20.h:164
digital_in_t alh
Definition: temphum20.h:159
digital_out_t en
Definition: temphum20.h:156
uint8_t slave_address
Definition: temphum20.h:167
temphum20_return_value_t
TempHum 20 Click return value data.
Definition: temphum20.h:195
@ TEMPHUM20_OK
Definition: temphum20.h:196
@ TEMPHUM20_ERROR
Definition: temphum20.h:197