temphum21  2.0.0.0
temphum21.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 TEMPHUM21_H
29 #define TEMPHUM21_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 TEMPHUM21_REG_ALARM_HIGH_ON 0x18
70 #define TEMPHUM21_REG_ALARM_HIGH_OFF 0x19
71 #define TEMPHUM21_REG_ALARM_LOW_ON 0x1A
72 #define TEMPHUM21_REG_ALARM_LOW_OFF 0x1B
73 #define TEMPHUM21_REG_CUST_CONFIG 0x1C
74 #define TEMPHUM21_REG_CUST_ID2 0x1E
75 #define TEMPHUM21_REG_CUST_ID3 0x1F
76 #define TEMPHUM21_CMD_WRITE_EEPROM 0x40
77 #define TEMPHUM21_CMD_START_NOM 0x80
78 #define TEMPHUM21_CMD_START_CM 0xA0
79  // temphum21_reg
81 
96 #define TEMPHUM21_STATUS_NORMAL_OP 0x00
97 #define TEMPHUM21_STATUS_STALE_DATA 0x40
98 #define TEMPHUM21_STATUS_COMMAND_MODE 0x80
99 #define TEMPHUM21_STATUS_BIT_MASK 0xC0
100 #define TEMPHUM21_DIAGNOSTIC_CORR_EP_ERR 0x04
101 #define TEMPHUM21_DIAGNOSTIC_UNCORR_EP_ERR 0x08
102 #define TEMPHUM21_DIAGNOSTIC_RAM_PAR_ERR 0x10
103 #define TEMPHUM21_DIAGNOSTIC_CONFIG_ERR 0x20
104 #define TEMPHUM21_DIAGNOSTIC_BIT_MASK 0x3C
105 #define TEMPHUM21_RESPONSE_BUSY 0x00
106 #define TEMPHUM21_RESPONSE_ACK 0x01
107 #define TEMPHUM21_RESPONSE_NACK 0x02
108 #define TEMPHUM21_RESPONSE_BIT_MASK 0x03
109 
114 #define TEMPHUM21_DATA_RES 0x3FFF
115 #define TEMPHUM21_TEMP_RES 165.0
116 #define TEMPHUM21_TEMP_OFFSET 40.0
117 #define TEMPHUM21_HUM_RES 100.0
118 
123 #define TEMPHUM21_ALARM_HIGH_ON_80PCT 0x3333
124 #define TEMPHUM21_ALARM_HIGH_OFF_75PCT 0x3000
125 #define TEMPHUM21_ALARM_LOW_ON_20PCT 0x0CCD
126 #define TEMPHUM21_ALARM_LOW_OFF_25PCT 0x1000
127 
133 #define TEMPHUM21_SET_DEV_ADDR 0x27
134  // temphum21_set
136 
151 #define TEMPHUM21_MAP_MIKROBUS( cfg, mikrobus ) \
152  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
154  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
155  cfg.all = MIKROBUS( mikrobus, MIKROBUS_AN ); \
156  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_INT )
157  // temphum21_map // temphum21
160 
165 typedef struct
166 {
167  // Output pins
168  digital_out_t en;
170  // Input pins
171  digital_in_t all;
172  digital_in_t alh;
174  // Modules
175  i2c_master_t i2c;
177  // I2C slave address
178  uint8_t slave_address;
180 } temphum21_t;
181 
186 typedef struct
187 {
188  pin_name_t scl;
189  pin_name_t sda;
191  pin_name_t en;
192  pin_name_t all;
193  pin_name_t alh;
195  uint32_t i2c_speed;
196  uint8_t i2c_address;
199 
204 typedef enum
205 {
207  TEMPHUM21_ERROR = -1
208 
210 
227 
242 
256 
268 
285 err_t temphum21_read_measurement ( temphum21_t *ctx, float *temperature, float *humidity );
286 
296 
306 
316 
326 
338 
350 
364 err_t temphum21_eeprom_read ( temphum21_t *ctx, uint8_t address, uint8_t *status, uint16_t *data_out );
365 
378 err_t temphum21_eeprom_write ( temphum21_t *ctx, uint8_t address, uint16_t data_in );
379 
380 #ifdef __cplusplus
381 }
382 #endif
383 #endif // TEMPHUM21_H
384  // temphum21
386 
387 // ------------------------------------------------------------------------ END
temphum21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum21.h:195
temphum21_cfg_setup
void temphum21_cfg_setup(temphum21_cfg_t *cfg)
TempHum 21 configuration object setup function.
temphum21_return_value_t
temphum21_return_value_t
TempHum 21 Click return value data.
Definition: temphum21.h:205
temphum21_enable_device
void temphum21_enable_device(temphum21_t *ctx)
TempHum 21 enable device function.
temphum21_read_measurement
err_t temphum21_read_measurement(temphum21_t *ctx, float *temperature, float *humidity)
TempHum 21 read measurement function.
temphum21_cfg_t::sda
pin_name_t sda
Definition: temphum21.h:189
temphum21_exit_command_mode
err_t temphum21_exit_command_mode(temphum21_t *ctx)
TempHum 21 exit command mode function.
temphum21_cfg_t::all
pin_name_t all
Definition: temphum21.h:192
temphum21_cfg_t::scl
pin_name_t scl
Definition: temphum21.h:188
temphum21_cfg_t
TempHum 21 Click configuration object.
Definition: temphum21.h:187
temphum21_disable_device
void temphum21_disable_device(temphum21_t *ctx)
TempHum 21 disable device function.
TEMPHUM21_OK
@ TEMPHUM21_OK
Definition: temphum21.h:206
temphum21_get_alh_pin
uint8_t temphum21_get_alh_pin(temphum21_t *ctx)
TempHum 21 get alh pin function.
temphum21_t::all
digital_in_t all
Definition: temphum21.h:171
temphum21_cfg_t::en
pin_name_t en
Definition: temphum21.h:191
temphum21_t::i2c
i2c_master_t i2c
Definition: temphum21.h:175
temphum21_t::slave_address
uint8_t slave_address
Definition: temphum21.h:178
temphum21_eeprom_read
err_t temphum21_eeprom_read(temphum21_t *ctx, uint8_t address, uint8_t *status, uint16_t *data_out)
TempHum 21 eeprom read function.
temphum21_get_all_pin
uint8_t temphum21_get_all_pin(temphum21_t *ctx)
TempHum 21 get all pin function.
temphum21_cfg_t::alh
pin_name_t alh
Definition: temphum21.h:193
temphum21_init
err_t temphum21_init(temphum21_t *ctx, temphum21_cfg_t *cfg)
TempHum 21 initialization function.
temphum21_enter_command_mode
err_t temphum21_enter_command_mode(temphum21_t *ctx)
TempHum 21 enter command mode function.
TEMPHUM21_ERROR
@ TEMPHUM21_ERROR
Definition: temphum21.h:207
temphum21_t::en
digital_out_t en
Definition: temphum21.h:168
temphum21_request_measurement
err_t temphum21_request_measurement(temphum21_t *ctx)
TempHum 21 request measurement function.
temphum21_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum21.h:196
temphum21_eeprom_write
err_t temphum21_eeprom_write(temphum21_t *ctx, uint8_t address, uint16_t data_in)
TempHum 21 eeprom write function.
temphum21_default_cfg
err_t temphum21_default_cfg(temphum21_t *ctx)
TempHum 21 default configuration function.
temphum21_t::alh
digital_in_t alh
Definition: temphum21.h:172
temphum21_t
TempHum 21 Click context object.
Definition: temphum21.h:166