adc16  2.0.0.0
adc16.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 ADC16_H
29 #define ADC16_H
30 
31 #ifdef __cplusplus
32 extern "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 ADC16_OPCODE_SINGLE_READ 0x10
60 #define ADC16_OPCODE_SINGLE_WRITE 0x08
61 #define ADC16_OPCODE_SET_BIT 0x18
62 #define ADC16_OPCODE_CLEAR_BIT 0x20
63 #define ADC16_OPCODE_CONTINUOUS_READ 0x30
64 #define ADC16_OPCODE_CONTINUOUS_WRITE 0x28
65 
70 #define ADC16_REG_OPMODE_I2CMODE_STATUS 0x00
71 #define ADC16_REG_DATA_BUFFER_STATUS 0x01
72 #define ADC16_REG_ACCUMULATOR_STATUS 0x02
73 #define ADC16_REG_ALERT_TRIG_CHID 0x03
74 #define ADC16_REG_SEQUENCE_STATUS 0x04
75 #define ADC16_REG_ACC_CH0_LSB 0x08
76 #define ADC16_REG_ACC_CH0_MSB 0x09
77 #define ADC16_REG_ACC_CH1_LSB 0x0A
78 #define ADC16_REG_ACC_CH1_MSB 0x0B
79 #define ADC16_REG_ALERT_LOW_FLAGS 0x0C
80 #define ADC16_REG_ALERT_HIGH_FLAGS 0x0E
81 #define ADC16_REG_DEVICE_RESET 0x14
82 #define ADC16_REG_OFFSET_CAL 0x15
83 #define ADC16_REG_WKEY 0x17
84 #define ADC16_REG_OSC_SEL 0x18
85 #define ADC16_REG_NCLK_SEL 0x19
86 #define ADC16_REG_OPMODE_SEL 0x1C
87 #define ADC16_REG_START_SEQUENCE 0x1E
88 #define ADC16_REG_ABORT_SEQUENCE 0x1F
89 #define ADC16_REG_AUTO_SEQ_CHEN 0x20
90 #define ADC16_REG_CH_INPUT_CFG 0x24
91 #define ADC16_REG_DOUT_FORMAT_CFG 0x28
92 #define ADC16_REG_DATA_BUFFER_OPMODE 0x2C
93 #define ADC16_REG_ACC_EN 0x30
94 #define ADC16_REG_ALERT_CHEN 0x34
95 #define ADC16_REG_PRE_ALT_MAX_EVENT_COUNT 0x36
96 #define ADC16_REG_ALERT_DWC_EN 0x37
97 #define ADC16_REG_DWC_HTH_CH0_LSB 0x38
98 #define ADC16_REG_DWC_HTH_CH0_MSB 0x39
99 #define ADC16_REG_DWC_LTH_CH0_LSB 0x3A
100 #define ADC16_REG_DWC_LTH_CH0_MSB 0x3B
101 #define ADC16_REG_DWC_HTH_CH1_LSB 0x3C
102 #define ADC16_REG_DWC_HTH_CH1_MSB 0x3D
103 #define ADC16_REG_DWC_LTH_CH1_LSB 0x3E
104 #define ADC16_REG_DWC_LTH_CH1_MSB 0x3F
105 #define ADC16_REG_DWC_HYS_CH0 0x40
106 #define ADC16_REG_DWC_HYS_CH1 0x41
107  // adc16_reg
109 
124 #define ADC16_WKEY_UNLOCK 0x0A
125 #define ADC16_WKEY_LOCK 0x00
126 
131 #define ADC16_DEVICE_RESET 0x01
132 
137 #define ADC16_START_CALIBRATION 0x01
138 
143 #define ADC16_CH_CFG_TWO_CH_SINGLE_END 0x00
144 #define ADC16_CH_CFG_SIN_CH_SINGLE_END_RMT_GND 0x01
145 #define ADC16_CH_CFG_SIN_CH_SINGLE_END_PSEUDO_DIFF 0x02
146 
151 #define ADC16_OPMODE_SEL_MAN_WITH_CH0 0x00
152 #define ADC16_OPMODE_SEL_MAN_WITH_AUTO_SEQ 0x04
153 #define ADC16_OPMODE_SEL_AUTO_WITH_AUTO_SEQ 0x06
154 #define ADC16_OPMODE_SEL_HIGH_PREC_WITH_AUTO_SEQ 0x07
155 
160 #define ADC16_AUTOSEQ_EN_CH0 0x01
161 #define ADC16_AUTOSEQ_EN_CH1 0x02
162 #define ADC16_AUTOSEQ_EN_BOTH_CH 0x03
163 
168 #define ADC16_START_SEQUENCE 0x01
169 #define ADC16_ABORT_SEQUENCE 0x01
170 
175 #define ADC16_RESOLUTION 0x0FFF
176 #define ADC16_VREF 3.3
177 
183 #define ADC16_DEV_ADDR_R1_0_R2_DNP 0x1F
184 #define ADC16_DEV_ADDR_R1_11K_R2_DNP 0x1E
185 #define ADC16_DEV_ADDR_R1_33K_R2_DNP 0x1D
186 #define ADC16_DEV_ADDR_R1_100K_R2_DNP 0x1C
187 #define ADC16_DEV_ADDR_R1_DNP_R2_DNP 0x18
188 #define ADC16_DEV_ADDR_R1_DNP_R2_11K 0x19
189 #define ADC16_DEV_ADDR_R1_DNP_R2_33K 0x1A
190 #define ADC16_DEV_ADDR_R1_DNP_R2_100K 0x1B
191  // adc16_set
193 
208 #define ADC16_MAP_MIKROBUS( cfg, mikrobus ) \
209  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
210  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
211  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_AN ); \
212  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
213  // adc16_map // adc16
216 
221 typedef struct
222 {
223  // Input pins
224  digital_in_t rdy;
225  digital_in_t alr;
227  // Modules
228  i2c_master_t i2c;
230  // I2C slave address
231  uint8_t slave_address;
233 } adc16_t;
234 
239 typedef struct
240 {
241  pin_name_t scl;
242  pin_name_t sda;
244  pin_name_t rdy;
245  pin_name_t alr;
247  uint32_t i2c_speed;
248  uint8_t i2c_address;
250 } adc16_cfg_t;
251 
256 typedef enum
257 {
258  ADC16_OK = 0,
259  ADC16_ERROR = -1
260 
262 
279 
293 err_t adc16_init ( adc16_t *ctx, adc16_cfg_t *cfg );
294 
307 err_t adc16_default_cfg ( adc16_t *ctx );
308 
321 err_t adc16_single_register_write ( adc16_t *ctx, uint8_t reg, uint8_t data_in );
322 
335 err_t adc16_single_register_read ( adc16_t *ctx, uint8_t reg, uint8_t *data_out );
336 
350 err_t adc16_set_register_bits ( adc16_t *ctx, uint8_t reg, uint8_t bit_mask );
351 
365 err_t adc16_clear_register_bits ( adc16_t *ctx, uint8_t reg, uint8_t bit_mask );
366 
381 err_t adc16_continuous_register_write ( adc16_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
382 
397 err_t adc16_continuous_register_read ( adc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
398 
407 uint8_t adc16_get_rdy_pin ( adc16_t *ctx );
408 
417 uint8_t adc16_get_alr_pin ( adc16_t *ctx );
418 
431 err_t adc16_get_voltage ( adc16_t *ctx, float *ain0_voltage, float *ain1_voltage );
432 
433 #ifdef __cplusplus
434 }
435 #endif
436 #endif // ADC16_H
437  // adc16
439 
440 // ------------------------------------------------------------------------ END
adc16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adc16.h:247
adc16_single_register_read
err_t adc16_single_register_read(adc16_t *ctx, uint8_t reg, uint8_t *data_out)
ADC 16 single register read function.
adc16_init
err_t adc16_init(adc16_t *ctx, adc16_cfg_t *cfg)
ADC 16 initialization function.
adc16_set_register_bits
err_t adc16_set_register_bits(adc16_t *ctx, uint8_t reg, uint8_t bit_mask)
ADC 16 set register bits function.
adc16_return_value_t
adc16_return_value_t
ADC 16 Click return value data.
Definition: adc16.h:257
adc16_cfg_t::alr
pin_name_t alr
Definition: adc16.h:245
ADC16_OK
@ ADC16_OK
Definition: adc16.h:258
adc16_get_alr_pin
uint8_t adc16_get_alr_pin(adc16_t *ctx)
ADC 16 get alr pin function.
adc16_continuous_register_read
err_t adc16_continuous_register_read(adc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
ADC 16 continuous register read function.
adc16_get_voltage
err_t adc16_get_voltage(adc16_t *ctx, float *ain0_voltage, float *ain1_voltage)
ADC 16 get voltage function.
adc16_get_rdy_pin
uint8_t adc16_get_rdy_pin(adc16_t *ctx)
ADC 16 get rdy pin function.
adc16_t::i2c
i2c_master_t i2c
Definition: adc16.h:228
adc16_default_cfg
err_t adc16_default_cfg(adc16_t *ctx)
ADC 16 default configuration function.
adc16_continuous_register_write
err_t adc16_continuous_register_write(adc16_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
ADC 16 continuous register write function.
adc16_cfg_t
ADC 16 Click configuration object.
Definition: adc16.h:240
adc16_t::slave_address
uint8_t slave_address
Definition: adc16.h:231
adc16_t
ADC 16 Click context object.
Definition: adc16.h:222
adc16_cfg_t::i2c_address
uint8_t i2c_address
Definition: adc16.h:248
adc16_clear_register_bits
err_t adc16_clear_register_bits(adc16_t *ctx, uint8_t reg, uint8_t bit_mask)
ADC 16 clear register bits function.
adc16_cfg_t::scl
pin_name_t scl
Definition: adc16.h:241
adc16_t::alr
digital_in_t alr
Definition: adc16.h:225
adc16_cfg_t::rdy
pin_name_t rdy
Definition: adc16.h:244
adc16_t::rdy
digital_in_t rdy
Definition: adc16.h:224
adc16_cfg_setup
void adc16_cfg_setup(adc16_cfg_t *cfg)
ADC 16 configuration object setup function.
ADC16_ERROR
@ ADC16_ERROR
Definition: adc16.h:259
adc16_cfg_t::sda
pin_name_t sda
Definition: adc16.h:242
adc16_single_register_write
err_t adc16_single_register_write(adc16_t *ctx, uint8_t reg, uint8_t data_in)
ADC 16 single register write function.