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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define TEMPHUM20_REG_PDM_CLIP_HIGH 0x16
70 #define TEMPHUM20_REG_PDM_CLIP_LOW 0x17
71 #define TEMPHUM20_REG_ALARM_HIGH_ON 0x18
72 #define TEMPHUM20_REG_ALARM_HIGH_OFF 0x19
73 #define TEMPHUM20_REG_ALARM_LOW_ON 0x1A
74 #define TEMPHUM20_REG_ALARM_LOW_OFF 0x1B
75 #define TEMPHUM20_REG_CUST_CONFIG 0x1C
76 #define TEMPHUM20_REG_RESERVED 0x1D
77 #define TEMPHUM20_REG_CUST_ID2 0x1E
78 #define TEMPHUM20_REG_CUST_ID3 0x1F
79 #define TEMPHUM20_CMD_START_NOM 0x80
80 #define TEMPHUM20_CMD_START_CM 0xA0
81  // temphum20_reg
83 
98 #define TEMPHUM20_DATA_RESOLUTION 0x4000
99 #define TEMPHUM20_TEMP_MULTIPLIER 165.0
100 #define TEMPHUM20_HUM_MULTIPLIER 100.0
101 #define TEMPHUM20_TEMP_OFFSET 40.0
102 
107 #define TEMPHUM20_STATUS_BITS_MASK 0xC0
108 #define TEMPHUM20_STATUS_VALID_DATA 0x00
109 #define TEMPHUM20_STATUS_STALE_DATA 0x40
110 #define TEMPHUM20_STATUS_COMMAND_MODE 0x80
111 
116 #define TEMPHUM20_OPMODE_COMMAND 0x00
117 #define TEMPHUM20_OPMODE_NORMAL 0x01
118 
123 #define TEMPHUM20_DUMMY 0x0000
124 
130 #define TEMPHUM20_SET_DEV_ADDR 0x28
131  // temphum20_set
133 
148 #define TEMPHUM20_MAP_MIKROBUS( cfg, mikrobus ) \
149  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
150  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
151  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_AN ); \
152  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
153  cfg.all = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
154  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
155  // temphum20_map // temphum20
158 
163 typedef struct
164 {
165  // Output pins
166  digital_out_t en;
168  // Input pins
169  digital_in_t alh;
170  digital_in_t all;
171  digital_in_t int_pin;
173  // Modules
174  i2c_master_t i2c;
176  // I2C slave address
177  uint8_t slave_address;
179 } temphum20_t;
180 
185 typedef struct
186 {
187  pin_name_t scl;
188  pin_name_t sda;
190  pin_name_t en;
191  pin_name_t alh;
192  pin_name_t all;
193  pin_name_t int_pin;
195  uint32_t i2c_speed;
196  uint8_t i2c_address;
199 
204 typedef enum
205 {
207  TEMPHUM20_ERROR = -1
208 
210 
227 
243 
258 
272 err_t temphum20_write_data ( temphum20_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
273 
287 err_t temphum20_read_data ( temphum20_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
288 
298 void temphum20_set_en_pin ( temphum20_t *ctx, uint8_t state );
299 
309 
319 
329 
339 
353 err_t temphum20_write_command ( temphum20_t *ctx, uint8_t cmd_byte, uint16_t cmd_data );
354 
369 err_t temphum20_get_measurement ( temphum20_t *ctx, float *temp, float *hum );
370 
384 err_t temphum20_set_operating_mode ( temphum20_t *ctx, uint8_t op_mode );
385 
386 #ifdef __cplusplus
387 }
388 #endif
389 #endif // TEMPHUM20_H
390  // temphum20
392 
393 // ------------------------------------------------------------------------ END
temphum20_t::i2c
i2c_master_t i2c
Definition: temphum20.h:174
temphum20_t::slave_address
uint8_t slave_address
Definition: temphum20.h:177
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:195
temphum20_t::int_pin
digital_in_t int_pin
Definition: temphum20.h:171
temphum20_cfg_t::scl
pin_name_t scl
Definition: temphum20.h:187
temphum20_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum20.h:193
temphum20_cfg_t
TempHum 20 Click configuration object.
Definition: temphum20.h:186
TEMPHUM20_ERROR
@ TEMPHUM20_ERROR
Definition: temphum20.h:207
temphum20_cfg_t::en
pin_name_t en
Definition: temphum20.h:190
temphum20_cfg_t::all
pin_name_t all
Definition: temphum20.h:192
temphum20_t::en
digital_out_t en
Definition: temphum20.h:166
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:169
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:188
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:206
temphum20_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum20.h:196
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:170
temphum20_t
TempHum 20 Click context object.
Definition: temphum20.h:164
temphum20_return_value_t
temphum20_return_value_t
TempHum 20 Click return value data.
Definition: temphum20.h:205
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:191