39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
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#include "drv_one_wire.h"
75#define PH2_CMD_CONVERT_TEMPERATURE 0x44
76#define PH2_CMD_WRITE_SCRATCHPAD 0x4E
77#define PH2_CMD_READ_SCRATCHPAD 0xBE
78#define PH2_CMD_COPY_SCRATCHPAD 0x48
79#define PH2_CMD_RECALL_SCRATCHPAD 0xB8
80#define PH2_CMD_READ_POWER_SUPPLY 0xB4
98#define PH2_PH_CALCULATION_COEF 0.18
100#define PH2_CONFIG_ADDRESS 0x10
105#define PH2_ADC_RESOLUTION 0x0FFF
106#define PH2_VREF_3V3 3.3
107#define PH2_VREF_5V 5.0
114#define PH2_SET_DEV_ADDR 0x4D
120#define PH2_FAMILY_CODE 0x28
127#define PH2_CONFIG_RESOLUTION_9BIT 0x00
128#define PH2_CONFIG_RESOLUTION_10BIT 0x20
129#define PH2_CONFIG_RESOLUTION_11BIT 0x40
130#define PH2_CONFIG_RESOLUTION_12BIT 0x60
131#define PH2_CONFIG_RESOLUTION_BIT_MASK 0x60
132#define PH2_CONFIG_RESERVED_BITS 0x10
138#define PH2_DATA_RESOLUTION 0.0625
144#define PH2_DEFAULT_ADDRESS PH2_CONFIG_ADDRESS
145#define PH2_DEFAULT_RESOLUTION PH2_CONFIG_RESOLUTION_12BIT
146#define PH2_DEFAULT_TEMP_HIGH_ALARM 0xFF
147#define PH2_DEFAULT_TEMP_LOW_ALARM 0x00
165#define PH2_MAP_MIKROBUS( cfg, mikrobus ) \
166 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
167 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
168 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
169 cfg.dq = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
170 cfg.st1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
171 cfg.st2 = MIKROBUS( mikrobus, MIKROBUS_INT )
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.
err_t ph2_ds18b20_start_measurement(ph2_t *ctx)
pH 2 DS18B20 start measurement function.
void ph2_enable_st2(ph2_t *ctx)
Ph 2 enable LED STAT2 function.
err_t ph2_ds18b20_select_device(ph2_t *ctx)
pH 2 DS18B20 select device function.
err_t ph2_ds18b20_write_scratchpad(ph2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config)
pH 2 DS18B20 write scratchpad function.
err_t ph2_ds18b20_init(ph2_t *ctx, ph2_cfg_t *cfg)
pH 2 DS18B20 initialization 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.
err_t ph2_ds18b20_default_cfg(ph2_t *ctx)
pH 2 DS18B20 default configuration function.
void ph2_disable_st1(ph2_t *ctx)
Ph 2 disable LED STAT1 function.
err_t ph2_ds18b20_check_communication(ph2_t *ctx)
pH 2 DS18B20 check communication function.
err_t ph2_init(ph2_t *ctx, ph2_cfg_t *cfg)
pH 2 initialization function.
err_t ph2_ds18b20_read_temperature(ph2_t *ctx, float *temperature)
pH 2 DS18B20 read temperature function.
err_t ph2_set_vref(ph2_t *ctx, float vref)
pH 2 set vref function.
err_t ph2_ds18b20_read_scratchpad(ph2_t *ctx, uint8_t *scratchpad)
pH 2 DS18B20 read scratchpad 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:181
@ PH2_DRV_SEL_I2C
Definition ph2.h:183
@ PH2_DRV_SEL_ADC
Definition ph2.h:182
ph2_return_value_t
pH 2 Click return value data.
Definition ph2.h:239
@ PH2_OK
Definition ph2.h:240
@ PH2_ERROR
Definition ph2.h:241
pH 2 Click configuration object.
Definition ph2.h:216
analog_in_resolution_t resolution
Definition ph2.h:224
float vref
Definition ph2.h:225
uint32_t i2c_speed
Definition ph2.h:227
pin_name_t st1
Definition ph2.h:221
ph2_drv_t drv_sel
Definition ph2.h:230
pin_name_t st2
Definition ph2.h:222
pin_name_t scl
Definition ph2.h:218
pin_name_t sda
Definition ph2.h:219
pin_name_t dq
Definition ph2.h:220
pin_name_t an
Definition ph2.h:217
uint8_t i2c_address
Definition ph2.h:228
pH 2 Click context object.
Definition ph2.h:192
one_wire_rom_address_t rom_addr
Definition ph2.h:203
digital_out_t st2
Definition ph2.h:194
float vref
Definition ph2.h:206
uint8_t config
Definition ph2.h:204
ph2_drv_t drv_sel
Definition ph2.h:207
float pH_val
Definition ph2.h:200
digital_out_t st1
Definition ph2.h:193
i2c_master_t i2c
Definition ph2.h:197
float pH_vol
Definition ph2.h:201
uint8_t slave_address
Definition ph2.h:205
analog_in_t adc
Definition ph2.h:196
one_wire_t ow
Definition ph2.h:198