pht  2.0.0.0
pht.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 PHT_H
29 #define PHT_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 PHT_RH_CMD_RESET 0xFE
70 #define PHT_RH_CMD_WRITE_USER_REG 0xE6
71 #define PHT_RH_CMD_READ_USER_REG 0xE7
72 #define PHT_RH_MEASURE_RH_HOLD 0xE5
73 #define PHT_RH_MEASURE_RH_NO_HOLD 0xF5
74 
79 #define PHT_PT_CMD_RESET 0x1E
80 #define PHT_PT_CMD_ADC_READ 0x00
81 #define PHT_PT_CMD_PROM_READ_P_T_START 0xA0
82 #define PHT_PT_CMD_PROM_READ_P_T_END 0xAE
83 
84 #define PHT_PT_CMD_RATIO_256 0x00
85 #define PHT_PT_CMD_RATIO_512 0x01
86 #define PHT_PT_CMD_RATIO_1024 0x02
87 #define PHT_PT_CMD_RATIO_2048 0x03
88 #define PHT_PT_CMD_RATIO_4096 0x04
89 #define PHT_PT_CMD_RATIO_8192 0x05
90 
95 #define PHT_PT_MANUFACTURER_RESERVED 0x00
96 #define PHT_PT_C1_SENS 0x01
97 #define PHT_PT_C2_OFF 0x02
98 #define PHT_PT_C3_TCS 0x03
99 #define PHT_PT_C4_TCO 0x04
100 #define PHT_PT_C5_TREF 0x05
101 #define PHT_PT_C6_TEMPSENS 0x06
102 #define PHT_PT_CRC 0x07
103 
108 #define PHT_SENSOR_TYPE_RH 0x00
109 #define PHT_SENSOR_TYPE_PT 0x01
110 
116 #define PHT_I2C_SLAVE_ADDR_RH 0x40
117 #define PHT_I2C_SLAVE_ADDR_P_AND_T 0x76
118 
119  // pht_set
121 
136 #define PHT_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
138  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
139  // pht_map // pht
142 
147 typedef struct
148 {
149  // Modules
150  i2c_master_t i2c;
152  // I2C slave address
153  uint8_t slave_address;
155 } pht_t;
156 
161 typedef struct
162 {
163  pin_name_t scl;
164  pin_name_t sda;
166  uint32_t i2c_speed;
167  uint8_t i2c_address;
169 } pht_cfg_t;
170 
175 typedef enum
176 {
177  PHT_OK = 0,
178  PHT_ERROR = -1
179 
181 
197 void pht_cfg_setup ( pht_cfg_t *cfg );
198 
212 err_t pht_init ( pht_t *ctx, pht_cfg_t *cfg );
213 
228 err_t pht_generic_write ( pht_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
229 
244 err_t pht_generic_read ( pht_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
245 
246 
258 void pht_set_command ( pht_t *ctx, uint8_t sensor_type, uint8_t cmd );
259 
270 void pht_soft_reset ( pht_t *ctx, uint8_t sensor_type );
271 
286 uint8_t pht_get_prom ( pht_t *ctx, uint8_t sel_data, uint32_t *tx_data );
287 
303 uint8_t pht_set_ratio ( pht_t *ctx, uint8_t temp_ratio, uint8_t press_ratio );
304 
316 void pht_reset ( pht_t *ctx );
317 
328 void pht_write_user_register ( pht_t *ctx, uint8_t tx_data );
329 
339 uint8_t pht_read_user_register ( pht_t *ctx );
340 
351 uint8_t pht_measure_rh ( pht_t *ctx, uint16_t *rh_data );
352 
368 
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 #endif // PHT_H
387  // pht
389 
390 // ------------------------------------------------------------------------ END
pht_get_temperature_pressure
void pht_get_temperature_pressure(pht_t *ctx, float *temperature, float *pressure)
Get temperature and pressure function.
pht_t::slave_address
uint8_t slave_address
Definition: pht.h:153
pht_cfg_t::scl
pin_name_t scl
Definition: pht.h:163
pht_set_ratio
uint8_t pht_set_ratio(pht_t *ctx, uint8_t temp_ratio, uint8_t press_ratio)
Set Ratio function.
pressure
float pressure
Definition: main.c:32
pht_generic_write
err_t pht_generic_write(pht_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
PHT I2C writing function.
pht_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pht.h:166
pht_generic_read
err_t pht_generic_read(pht_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
PHT I2C reading function.
humidity
float humidity
Definition: main.c:33
pht_measure_rh
uint8_t pht_measure_rh(pht_t *ctx, uint16_t *rh_data)
Measure RH function.
pht_return_value_t
pht_return_value_t
PHT Click return value data.
Definition: pht.h:176
temperature
float temperature
Definition: main.c:34
pht_cfg_t
PHT Click configuration object.
Definition: pht.h:162
pht_set_command
void pht_set_command(pht_t *ctx, uint8_t sensor_type, uint8_t cmd)
Set Command function.
pht_soft_reset
void pht_soft_reset(pht_t *ctx, uint8_t sensor_type)
Soft Reset function.
pht_cfg_setup
void pht_cfg_setup(pht_cfg_t *cfg)
PHT configuration object setup function.
pht_cfg_t::sda
pin_name_t sda
Definition: pht.h:164
pht_t::i2c
i2c_master_t i2c
Definition: pht.h:150
pht_read_user_register
uint8_t pht_read_user_register(pht_t *ctx)
Raed User Register function.
PHT_OK
@ PHT_OK
Definition: pht.h:177
pht_t
PHT Click context object.
Definition: pht.h:148
pht_get_relative_humidity
void pht_get_relative_humidity(pht_t *ctx, float *humidity)
Get humidity function.
pht_init
err_t pht_init(pht_t *ctx, pht_cfg_t *cfg)
PHT initialization function.
pht_get_prom
uint8_t pht_get_prom(pht_t *ctx, uint8_t sel_data, uint32_t *tx_data)
Calibration Data Read function.
pht_write_user_register
void pht_write_user_register(pht_t *ctx, uint8_t tx_data)
Write User Register function.
pht_reset
void pht_reset(pht_t *ctx)
Reset function.
pht_cfg_t::i2c_address
uint8_t i2c_address
Definition: pht.h:167
PHT_ERROR
@ PHT_ERROR
Definition: pht.h:178