tds 2.2.0
Loading...
Searching...
No Matches
tds.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
27
28#ifndef TDS_H
29#define TDS_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
53
59
64
69
74#define TDS_COEF_POW3 133.42
75#define TDS_COEF_POW2 255.86
76#define TDS_COEF_POW1 875.39
77#define TDS_COEF_FINAL 0.5
78
83#define TDS_NUM_CONVERSIONS 200
84
89#define TDS_ADC_RESOLUTION 0x0FFF
90#define TDS_VREF_3V3 3.3
91#define TDS_VREF_5V 5.0
92
97#define TDS_TIMEOUT_MS 2000
98
104#define TDS_SET_DEV_ADDR 0x4D
105 // tds_set
107
112
117
122#define TDS_MAP_MIKROBUS( cfg, mikrobus ) \
123 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
124 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
125 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
126 // tds_map // tds
129
140
145typedef struct
146{
147 analog_in_t adc;
148 i2c_master_t i2c;
149
151 float vref;
153
154} tds_t;
155
160typedef struct
161{
162 pin_name_t an;
163 pin_name_t scl;
164 pin_name_t sda;
165
166 analog_in_resolution_t resolution;
167 float vref;
168
169 uint32_t i2c_speed;
170 uint8_t i2c_address;
171
173
174} tds_cfg_t;
175
180typedef enum
181{
184
186
192
203
219
233err_t tds_init ( tds_t *ctx, tds_cfg_t *cfg );
234
246err_t tds_read_raw_adc ( tds_t *ctx, uint16_t *raw_adc );
247
259err_t tds_read_voltage ( tds_t *ctx, float *voltage );
260
273err_t tds_read_voltage_avg ( tds_t *ctx, uint16_t num_conv, float *voltage_avg );
274
286err_t tds_set_vref ( tds_t *ctx, float vref );
287
298err_t tds_read_ppm ( tds_t *ctx, float *data_out );
299
300#ifdef __cplusplus
301}
302#endif
303#endif // TDS_H
304 // tds
306
307// ------------------------------------------------------------------------ END
err_t tds_set_vref(tds_t *ctx, float vref)
TDS set vref function.
err_t tds_init(tds_t *ctx, tds_cfg_t *cfg)
TDS initialization function.
err_t tds_read_voltage_avg(tds_t *ctx, uint16_t num_conv, float *voltage_avg)
TDS read average voltage level function.
void tds_drv_interface_sel(tds_cfg_t *cfg, tds_drv_t drv_sel)
TDS driver interface setup function.
void tds_cfg_setup(tds_cfg_t *cfg)
TDS configuration object setup function.
err_t tds_read_raw_adc(tds_t *ctx, uint16_t *raw_adc)
TDS read raw ADC value function.
err_t tds_read_ppm(tds_t *ctx, float *data_out)
TDS read ppm function.
err_t tds_read_voltage(tds_t *ctx, float *voltage)
TDS read voltage level function.
TDS Click configuration object.
Definition tds.h:161
analog_in_resolution_t resolution
Definition tds.h:166
float vref
Definition tds.h:167
tds_drv_t drv_sel
Definition tds.h:172
uint32_t i2c_speed
Definition tds.h:169
pin_name_t scl
Definition tds.h:163
pin_name_t sda
Definition tds.h:164
pin_name_t an
Definition tds.h:162
uint8_t i2c_address
Definition tds.h:170
TDS Click context object.
Definition tds.h:146
float vref
Definition tds.h:151
tds_drv_t drv_sel
Definition tds.h:152
i2c_master_t i2c
Definition tds.h:148
uint8_t slave_address
Definition tds.h:150
analog_in_t adc
Definition tds.h:147
tds_drv_t
TDS Click driver selector.
Definition tds.h:135
@ TDS_DRV_SEL_I2C
Definition tds.h:137
@ TDS_DRV_SEL_ADC
Definition tds.h:136
tds_return_value_t
TDS Click return value data.
Definition tds.h:181
@ TDS_ERROR
Definition tds.h:183
@ TDS_OK
Definition tds.h:182