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
32 extern "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 
153 typedef 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
167  uint8_t slave_address;
169 } temphum20_t;
170 
175 typedef 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 
194 typedef enum
195 {
197  TEMPHUM20_ERROR = -1
198 
200 
217 
233 
248 
262 err_t temphum20_write_data ( temphum20_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
263 
277 err_t temphum20_read_data ( temphum20_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
278 
288 void temphum20_set_en_pin ( temphum20_t *ctx, uint8_t state );
289 
299 
309 
319 
329 
343 err_t temphum20_write_command ( temphum20_t *ctx, uint8_t cmd_byte, uint16_t cmd_data );
344 
359 err_t temphum20_get_measurement ( temphum20_t *ctx, float *temp, float *hum );
360 
374 err_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
temphum20_t::i2c
i2c_master_t i2c
Definition: temphum20.h:164
temphum20_t::slave_address
uint8_t slave_address
Definition: temphum20.h:167
temphum20_set_operating_mode
err_t temphum20_set_operating_mode(temphum20_t *ctx, uint8_t op_mode)
TempHum 20 set operating mode function.
temphum20_write_command
err_t temphum20_write_command(temphum20_t *ctx, uint8_t cmd_byte, uint16_t cmd_data)
TempHum 20 write command function.
temphum20_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum20.h:185
temphum20_t::int_pin
digital_in_t int_pin
Definition: temphum20.h:161
temphum20_cfg_t::scl
pin_name_t scl
Definition: temphum20.h:177
temphum20_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum20.h:183
temphum20_cfg_t
TempHum 20 Click configuration object.
Definition: temphum20.h:176
TEMPHUM20_ERROR
@ TEMPHUM20_ERROR
Definition: temphum20.h:197
temphum20_cfg_t::en
pin_name_t en
Definition: temphum20.h:180
temphum20_cfg_t::all
pin_name_t all
Definition: temphum20.h:182
temphum20_t::en
digital_out_t en
Definition: temphum20.h:156
temphum20_set_en_pin
void temphum20_set_en_pin(temphum20_t *ctx, uint8_t state)
TempHum 20 set EN pin function.
temphum20_t::alh
digital_in_t alh
Definition: temphum20.h:159
temphum20_default_cfg
err_t temphum20_default_cfg(temphum20_t *ctx)
TempHum 20 default configuration function.
temphum20_cfg_t::sda
pin_name_t sda
Definition: temphum20.h:178
temphum20_read_data
err_t temphum20_read_data(temphum20_t *ctx, uint8_t *rx_buf, uint8_t rx_len)
TempHum 20 I2C reading function.
temphum20_init
err_t temphum20_init(temphum20_t *ctx, temphum20_cfg_t *cfg)
TempHum 20 initialization function.
temphum20_reset_device
void temphum20_reset_device(temphum20_t *ctx)
TempHum 20 reset device function.
temphum20_write_data
err_t temphum20_write_data(temphum20_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
TempHum 20 I2C writing function.
temphum20_get_alarm_high_pin
uint8_t temphum20_get_alarm_high_pin(temphum20_t *ctx)
TempHum 20 get alarm high pin function.
temphum20_get_int_pin
uint8_t temphum20_get_int_pin(temphum20_t *ctx)
TempHum 20 get INT pin function.
temphum20_get_alarm_low_pin
uint8_t temphum20_get_alarm_low_pin(temphum20_t *ctx)
TempHum 20 get alarm low pin function.
TEMPHUM20_OK
@ TEMPHUM20_OK
Definition: temphum20.h:196
temphum20_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum20.h:186
temphum20_get_measurement
err_t temphum20_get_measurement(temphum20_t *ctx, float *temp, float *hum)
TempHum 20 get measurement function.
temphum20_t::all
digital_in_t all
Definition: temphum20.h:160
temphum20_t
TempHum 20 Click context object.
Definition: temphum20.h:154
temphum20_return_value_t
temphum20_return_value_t
TempHum 20 Click return value data.
Definition: temphum20.h:195
temphum20_cfg_setup
void temphum20_cfg_setup(temphum20_cfg_t *cfg)
TempHum 20 configuration object setup function.
temphum20_cfg_t::alh
pin_name_t alh
Definition: temphum20.h:181