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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define TEMPHUM21_REG_ALARM_HIGH_ON 0x18
60 #define TEMPHUM21_REG_ALARM_HIGH_OFF 0x19
61 #define TEMPHUM21_REG_ALARM_LOW_ON 0x1A
62 #define TEMPHUM21_REG_ALARM_LOW_OFF 0x1B
63 #define TEMPHUM21_REG_CUST_CONFIG 0x1C
64 #define TEMPHUM21_REG_CUST_ID2 0x1E
65 #define TEMPHUM21_REG_CUST_ID3 0x1F
66 #define TEMPHUM21_CMD_WRITE_EEPROM 0x40
67 #define TEMPHUM21_CMD_START_NOM 0x80
68 #define TEMPHUM21_CMD_START_CM 0xA0
69  // temphum21_reg
71 
86 #define TEMPHUM21_STATUS_NORMAL_OP 0x00
87 #define TEMPHUM21_STATUS_STALE_DATA 0x40
88 #define TEMPHUM21_STATUS_COMMAND_MODE 0x80
89 #define TEMPHUM21_STATUS_BIT_MASK 0xC0
90 #define TEMPHUM21_DIAGNOSTIC_CORR_EP_ERR 0x04
91 #define TEMPHUM21_DIAGNOSTIC_UNCORR_EP_ERR 0x08
92 #define TEMPHUM21_DIAGNOSTIC_RAM_PAR_ERR 0x10
93 #define TEMPHUM21_DIAGNOSTIC_CONFIG_ERR 0x20
94 #define TEMPHUM21_DIAGNOSTIC_BIT_MASK 0x3C
95 #define TEMPHUM21_RESPONSE_BUSY 0x00
96 #define TEMPHUM21_RESPONSE_ACK 0x01
97 #define TEMPHUM21_RESPONSE_NACK 0x02
98 #define TEMPHUM21_RESPONSE_BIT_MASK 0x03
99 
104 #define TEMPHUM21_DATA_RES 0x3FFF
105 #define TEMPHUM21_TEMP_RES 165.0
106 #define TEMPHUM21_TEMP_OFFSET 40.0
107 #define TEMPHUM21_HUM_RES 100.0
108 
113 #define TEMPHUM21_ALARM_HIGH_ON_80PCT 0x3333
114 #define TEMPHUM21_ALARM_HIGH_OFF_75PCT 0x3000
115 #define TEMPHUM21_ALARM_LOW_ON_20PCT 0x0CCD
116 #define TEMPHUM21_ALARM_LOW_OFF_25PCT 0x1000
117 
123 #define TEMPHUM21_SET_DEV_ADDR 0x27
124  // temphum21_set
126 
141 #define TEMPHUM21_MAP_MIKROBUS( cfg, mikrobus ) \
142  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
143  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
144  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
145  cfg.all = MIKROBUS( mikrobus, MIKROBUS_AN ); \
146  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_INT )
147  // temphum21_map // temphum21
150 
155 typedef struct
156 {
157  // Output pins
158  digital_out_t en;
160  // Input pins
161  digital_in_t all;
162  digital_in_t alh;
164  // Modules
165  i2c_master_t i2c;
167  // I2C slave address
168  uint8_t slave_address;
170 } temphum21_t;
171 
176 typedef struct
177 {
178  pin_name_t scl;
179  pin_name_t sda;
181  pin_name_t en;
182  pin_name_t all;
183  pin_name_t alh;
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
189 
194 typedef enum
195 {
197  TEMPHUM21_ERROR = -1
198 
200 
217 
232 
246 
258 
275 err_t temphum21_read_measurement ( temphum21_t *ctx, float *temperature, float *humidity );
276 
286 
296 
306 
316 
328 
340 
354 err_t temphum21_eeprom_read ( temphum21_t *ctx, uint8_t address, uint8_t *status, uint16_t *data_out );
355 
368 err_t temphum21_eeprom_write ( temphum21_t *ctx, uint8_t address, uint16_t data_in );
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 #endif // TEMPHUM21_H
374  // temphum21
376 
377 // ------------------------------------------------------------------------ END
temphum21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum21.h:185
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:195
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:179
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:182
temphum21_cfg_t::scl
pin_name_t scl
Definition: temphum21.h:178
temphum21_cfg_t
TempHum 21 Click configuration object.
Definition: temphum21.h:177
temphum21_disable_device
void temphum21_disable_device(temphum21_t *ctx)
TempHum 21 disable device function.
TEMPHUM21_OK
@ TEMPHUM21_OK
Definition: temphum21.h:196
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:161
temphum21_cfg_t::en
pin_name_t en
Definition: temphum21.h:181
temphum21_t::i2c
i2c_master_t i2c
Definition: temphum21.h:165
temphum21_t::slave_address
uint8_t slave_address
Definition: temphum21.h:168
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:183
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:197
temphum21_t::en
digital_out_t en
Definition: temphum21.h:158
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:186
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:162
temphum21_t
TempHum 21 Click context object.
Definition: temphum21.h:156