ph2 2.1.0.0
ph2.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 PH2_H
29#define PH2_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_analog_in.h"
38#include "drv_i2c_master.h"
39
65#define PH2_PH_CALCULATION_COEF 0.18
66
71#define PH2_ADC_RESOLUTION 0x0FFF
72#define PH2_VREF_3V3 3.3
73#define PH2_VREF_5V 5.0
74
80#define PH2_SET_DEV_ADDR 0x4D
81 // ph2_set
83
98#define PH2_MAP_MIKROBUS( cfg, mikrobus ) \
99 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
100 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
101 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
102 cfg.st1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
103 cfg.st2 = MIKROBUS( mikrobus, MIKROBUS_INT )
104 // ph2_map // ph2
107
112typedef enum
113{
118
123typedef struct
124{
125 digital_out_t st1;
126 digital_out_t st2;
128 analog_in_t adc;
129 i2c_master_t i2c;
131 float pH_val;
132 float pH_vol;
133
135 float vref;
138} ph2_t;
139
144typedef struct
145{
146 pin_name_t an;
147 pin_name_t scl;
148 pin_name_t sda;
149 pin_name_t st1;
150 pin_name_t st2;
152 analog_in_resolution_t resolution;
153 float vref;
155 uint32_t i2c_speed;
156 uint8_t i2c_address;
160} ph2_cfg_t;
161
166typedef enum
167{
169 PH2_ERROR = -1
170
172
189
205
219err_t ph2_init ( ph2_t *ctx, ph2_cfg_t *cfg );
220
232err_t ph2_read_raw_adc ( ph2_t *ctx, uint16_t *raw_adc );
233
245err_t ph2_read_voltage ( ph2_t *ctx, float *voltage );
246
258err_t ph2_set_vref ( ph2_t *ctx, float vref );
259
272err_t ph2_calibrate ( ph2_t *ctx, float pH_value );
273
285err_t ph2_calculate_ph ( ph2_t *ctx, float *pH_value );
286
300
309void ph2_enable_st1 ( ph2_t *ctx );
310
319void ph2_disable_st1 ( ph2_t *ctx );
320
329void ph2_enable_st2 ( ph2_t *ctx );
330
339void ph2_disable_st2 ( ph2_t *ctx );
340
341#ifdef __cplusplus
342}
343#endif
344#endif // PH2_H
345 // ph2
347
348// ------------------------------------------------------------------------ END
void ph2_enable_st1(ph2_t *ctx)
Ph 2 enable LED STAT1 function.
void ph2_calibrate_offset(ph2_t *ctx)
Ph 2 calibrate offset function.
void ph2_disable_st2(ph2_t *ctx)
Ph 2 disable LED STAT2 function.
void ph2_drv_interface_selection(ph2_cfg_t *cfg, ph2_drv_t drv_sel)
pH 2 driver interface setup function.
err_t ph2_calculate_ph(ph2_t *ctx, float *pH_value)
Ph 2 calculate pH value function.
void ph2_enable_st2(ph2_t *ctx)
Ph 2 enable LED STAT2 function.
err_t ph2_read_raw_adc(ph2_t *ctx, uint16_t *raw_adc)
pH 2 read raw ADC value function.
err_t ph2_read_voltage(ph2_t *ctx, float *voltage)
pH 2 read voltage level function.
void ph2_disable_st1(ph2_t *ctx)
Ph 2 disable LED STAT1 function.
err_t ph2_init(ph2_t *ctx, ph2_cfg_t *cfg)
pH 2 initialization function.
err_t ph2_set_vref(ph2_t *ctx, float vref)
pH 2 set vref function.
err_t ph2_calibrate(ph2_t *ctx, float pH_value)
Ph 2 calibrate function.
void ph2_cfg_setup(ph2_cfg_t *cfg)
pH 2 configuration object setup function.
ph2_drv_t
pH 2 Click driver selector.
Definition: ph2.h:113
@ PH2_DRV_SEL_I2C
Definition: ph2.h:115
@ PH2_DRV_SEL_ADC
Definition: ph2.h:114
ph2_return_value_t
pH 2 Click return value data.
Definition: ph2.h:167
@ PH2_OK
Definition: ph2.h:168
@ PH2_ERROR
Definition: ph2.h:169
pH 2 Click configuration object.
Definition: ph2.h:145
analog_in_resolution_t resolution
Definition: ph2.h:152
float vref
Definition: ph2.h:153
uint32_t i2c_speed
Definition: ph2.h:155
pin_name_t st1
Definition: ph2.h:149
ph2_drv_t drv_sel
Definition: ph2.h:158
pin_name_t st2
Definition: ph2.h:150
pin_name_t scl
Definition: ph2.h:147
pin_name_t sda
Definition: ph2.h:148
pin_name_t an
Definition: ph2.h:146
uint8_t i2c_address
Definition: ph2.h:156
pH 2 Click context object.
Definition: ph2.h:124
digital_out_t st2
Definition: ph2.h:126
float vref
Definition: ph2.h:135
ph2_drv_t drv_sel
Definition: ph2.h:136
float pH_val
Definition: ph2.h:131
digital_out_t st1
Definition: ph2.h:125
i2c_master_t i2c
Definition: ph2.h:129
float pH_vol
Definition: ph2.h:132
uint8_t slave_address
Definition: ph2.h:134
analog_in_t adc
Definition: ph2.h:128