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
32extern "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 PHT_RH_CMD_RESET 0xFE
60#define PHT_RH_CMD_WRITE_USER_REG 0xE6
61#define PHT_RH_CMD_READ_USER_REG 0xE7
62#define PHT_RH_MEASURE_RH_HOLD 0xE5
63#define PHT_RH_MEASURE_RH_NO_HOLD 0xF5
64
69#define PHT_PT_CMD_RESET 0x1E
70#define PHT_PT_CMD_ADC_READ 0x00
71#define PHT_PT_CMD_PROM_READ_P_T_START 0xA0
72#define PHT_PT_CMD_PROM_READ_P_T_END 0xAE
73
74#define PHT_PT_CMD_RATIO_256 0x00
75#define PHT_PT_CMD_RATIO_512 0x01
76#define PHT_PT_CMD_RATIO_1024 0x02
77#define PHT_PT_CMD_RATIO_2048 0x03
78#define PHT_PT_CMD_RATIO_4096 0x04
79#define PHT_PT_CMD_RATIO_8192 0x05
80
85#define PHT_PT_MANUFACTURER_RESERVED 0x00
86#define PHT_PT_C1_SENS 0x01
87#define PHT_PT_C2_OFF 0x02
88#define PHT_PT_C3_TCS 0x03
89#define PHT_PT_C4_TCO 0x04
90#define PHT_PT_C5_TREF 0x05
91#define PHT_PT_C6_TEMPSENS 0x06
92#define PHT_PT_CRC 0x07
93
98#define PHT_SENSOR_TYPE_RH 0x00
99#define PHT_SENSOR_TYPE_PT 0x01
100
106#define PHT_I2C_SLAVE_ADDR_RH 0x40
107#define PHT_I2C_SLAVE_ADDR_P_AND_T 0x76
108
109 // pht_set
111
126#define PHT_MAP_MIKROBUS( cfg, mikrobus ) \
127 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
128 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
129 // pht_map // pht
132
137typedef struct
138{
139 // Modules
140 i2c_master_t i2c;
142 // I2C slave address
145} pht_t;
146
151typedef struct
152{
153 pin_name_t scl;
154 pin_name_t sda;
156 uint32_t i2c_speed;
157 uint8_t i2c_address;
159} pht_cfg_t;
160
165typedef enum
166{
168 PHT_ERROR = -1
169
171
188
202err_t pht_init ( pht_t *ctx, pht_cfg_t *cfg );
203
218err_t pht_generic_write ( pht_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
219
234err_t pht_generic_read ( pht_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
235
236
248void pht_set_command ( pht_t *ctx, uint8_t sensor_type, uint8_t cmd );
249
260void pht_soft_reset ( pht_t *ctx, uint8_t sensor_type );
261
276uint8_t pht_get_prom ( pht_t *ctx, uint8_t sel_data, uint32_t *tx_data );
277
293uint8_t pht_set_ratio ( pht_t *ctx, uint8_t temp_ratio, uint8_t press_ratio );
294
306void pht_reset ( pht_t *ctx );
307
318void pht_write_user_register ( pht_t *ctx, uint8_t tx_data );
319
330
341uint8_t pht_measure_rh ( pht_t *ctx, uint16_t *rh_data );
342
358
372
373#ifdef __cplusplus
374}
375#endif
376#endif // PHT_H
377 // pht
379
380// ------------------------------------------------------------------------ END
void pht_get_temperature_pressure(pht_t *ctx, float *temperature, float *pressure)
Get temperature and pressure function.
uint8_t pht_read_user_register(pht_t *ctx)
Raed User Register function.
void pht_soft_reset(pht_t *ctx, uint8_t sensor_type)
Soft Reset function.
uint8_t pht_get_prom(pht_t *ctx, uint8_t sel_data, uint32_t *tx_data)
Calibration Data Read function.
void pht_get_relative_humidity(pht_t *ctx, float *humidity)
Get humidity function.
err_t pht_generic_read(pht_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
PHT I2C reading function.
uint8_t pht_set_ratio(pht_t *ctx, uint8_t temp_ratio, uint8_t press_ratio)
Set Ratio function.
err_t pht_init(pht_t *ctx, pht_cfg_t *cfg)
PHT initialization function.
void pht_set_command(pht_t *ctx, uint8_t sensor_type, uint8_t cmd)
Set Command function.
err_t pht_generic_write(pht_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
PHT I2C writing function.
void pht_reset(pht_t *ctx)
Reset function.
uint8_t pht_measure_rh(pht_t *ctx, uint16_t *rh_data)
Measure RH function.
void pht_write_user_register(pht_t *ctx, uint8_t tx_data)
Write User Register function.
void pht_cfg_setup(pht_cfg_t *cfg)
PHT configuration object setup function.
float humidity
Definition: main.c:33
float pressure
Definition: main.c:32
float temperature
Definition: main.c:34
pht_return_value_t
PHT Click return value data.
Definition: pht.h:166
@ PHT_ERROR
Definition: pht.h:168
@ PHT_OK
Definition: pht.h:167
PHT Click configuration object.
Definition: pht.h:152
uint32_t i2c_speed
Definition: pht.h:156
pin_name_t scl
Definition: pht.h:153
pin_name_t sda
Definition: pht.h:154
uint8_t i2c_address
Definition: pht.h:157
PHT Click context object.
Definition: pht.h:138
i2c_master_t i2c
Definition: pht.h:140
uint8_t slave_address
Definition: pht.h:143