adc10  2.0.0.0
adc10.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 ADC10_H
29 #define ADC10_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_uart.h"
38 
39 
60 #define ADC10_REG_CONFIG_0 0x00
61 #define ADC10_REG_CONFIG_1 0x01
62 #define ADC10_REG_CONFIG_2 0x02
63 #define ADC10_REG_CONFIG_3 0x03
64 #define ADC10_REG_CONFIG_4 0x04
65  // adc10_reg
67 
83 #define ADC10_SYNC_WORD 0x55
84 #define ADC10_CMD_RESET 0x06
85 #define ADC10_CMD_START 0x08
86 #define ADC10_CMD_POWERDOWN 0x03
87 #define ADC10_CMD_RDATA 0x10
88 #define ADC10_CMD_RREG 0x20
89 #define ADC10_CMD_WREG 0x40
90 
96 #define ADC10_REG0_MUX_P0_N1 0x00
97 #define ADC10_REG0_MUX_P0_N2 0x01
98 #define ADC10_REG0_MUX_P0_N3 0x02
99 #define ADC10_REG0_MUX_P1_N0 0x03
100 #define ADC10_REG0_MUX_P1_N2 0x04
101 #define ADC10_REG0_MUX_P1_N3 0x05
102 #define ADC10_REG0_MUX_P2_N3 0x06
103 #define ADC10_REG0_MUX_P3_N2 0x07
104 #define ADC10_REG0_MUX_P0_NS 0x08
105 #define ADC10_REG0_MUX_P1_NS 0x09
106 #define ADC10_REG0_MUX_P2_NS 0x0A
107 #define ADC10_REG0_MUX_P3_NS 0x0B
108 #define ADC10_REG0_MUX_VREF 0x0C
109 #define ADC10_REG0_MUX_AVOLD_4 0x0D
110 #define ADC10_REG0_MUX_AVOLAVER 0x0E
111 #define ADC10_REG0_MUX_RESERVE 0x0F
112 
118 #define ADC10_REG0_GAIN_1 0x00
119 #define ADC10_REG0_GAIN_2 0x01
120 #define ADC10_REG0_GAIN_4 0x02
121 #define ADC10_REG0_GAIN_8 0x03
122 #define ADC10_REG0_GAIN_16 0x04
123 #define ADC10_REG0_GAIN_32 0x05
124 #define ADC10_REG0_GAIN_64 0x06
125 #define ADC10_REG0_GAIN_128 0x07
126 
132 #define ADC10_REG0_PGA_ENABLED 0x00
133 #define ADC10_REG0_PGA_DISABLED 0x01
134 
140 #define ADC10_REG1_DR_NORMAL_20 0x00
141 #define ADC10_REG1_DR_NORMAL_45 0x01
142 #define ADC10_REG1_DR_NORMAL_90 0x02
143 #define ADC10_REG1_DR_NORMAL_175 0x03
144 #define ADC10_REG1_DR_NORMAL_330 0x04
145 #define ADC10_REG1_DR_NORMAL_600 0x05
146 #define ADC10_REG1_DR_NORMAL_1000 0x06
147 #define ADC10_REG1_DR_TURBO_40 0x00
148 #define ADC10_REG1_DR_TURBO_90 0x01
149 #define ADC10_REG1_DR_TURBO_180 0x02
150 #define ADC10_REG1_DR_TURBO_350 0x03
151 #define ADC10_REG1_DR_TURBO_660 0x04
152 #define ADC10_REG1_DR_TURBO_1200 0x05
153 #define ADC10_REG1_DR_TURBO_2000 0x06
154 
160 #define ADC10_REG1_MODE_NORMAL 0x00
161 #define ADC10_REG1_MODE_TURBO 0x01
162 
168 #define ADC10_REG1_CM_SINGAL_SHOT 0x00
169 #define ADC10_REG1_CM_CONTINUOUS 0x01
170 
176 #define ADC10_REG1_VREF_INTERNAL_2048 0x00
177 #define ADC10_REG1_VREF_EXTERNAL_REF 0x01
178 #define ADC10_REG1_VREF_ANALOG_1 0x02
179 #define ADC10_REG1_VREF_ANALOG_2 0x03
180 
186 #define ADC10_REG1_TS_DISABLED 0x00
187 #define ADC10_REG1_TS_ENABLED 0x01
188 
194 #define ADC10_REG2_DRDY_NOT_READY 0x00
195 #define ADC10_REG2_DRDY_READY 0x01
196 
202 #define ADC10_REG2_DCNT_DISABLED 0x00
203 #define ADC10_REG2_DCNT_ENABLED 0x01
204 
210 #define ADC10_REG2_CRC_DISABLED 0x00
211 #define ADC10_REG2_CRC_INVERTED_ENABLED 0x01
212 #define ADC10_REG2_CRC_CRC16_ENABLED 0x02
213 #define ADC10_REG2_CRC_RESERVED 0x03
214 
220 #define ADC10_REG2_BCS_CURRENT_SOURCE_OFF 0x00
221 #define ADC10_REG2_BCS_CURRENT_SOURCE_ON 0x01
222 
228 #define ADC10_REG2_IDAC_CURRENT_OFF 0x00
229 #define ADC10_REG2_IDAC_CURRENT_10_uA 0x01
230 #define ADC10_REG2_IDAC_CURRENT_50_uA 0x02
231 #define ADC10_REG2_IDAC_CURRENT_100_uA 0x03
232 #define ADC10_REG2_IDAC_CURRENT_250_uA 0x04
233 #define ADC10_REG2_IDAC_CURRENT_500_uA 0x05
234 #define ADC10_REG2_IDAC_CURRENT_1000_uA 0x06
235 #define ADC10_REG2_IDAC_CURRENT_1500_uA 0x07
236 
242 #define ADC10_REG3_L1MUX_DISABLED 0x00
243 #define ADC10_REG3_L1MUX_TO_AIN0 0x01
244 #define ADC10_REG3_L1MUX_TO_AIN1 0x02
245 #define ADC10_REG3_L1MUX_TO_AIN2 0x03
246 #define ADC10_REG3_L1MUX_TO_AIN3 0x04
247 #define ADC10_REG3_L1MUX_TO_REFP 0x05
248 #define ADC10_REG3_L1MUX_TO_REFN 0x06
249 #define ADC10_REG3_L1MUX_RESERVED 0x07
250 
256 #define ADC10_REG3_L2MUX_DISABLED 0x00
257 #define ADC10_REG3_L2MUX_TO_AIN0 0x01
258 #define ADC10_REG3_L2MUX_TO_AIN1 0x02
259 #define ADC10_REG3_L2MUX_TO_AIN2 0x03
260 #define ADC10_REG3_L2MUX_TO_AIN3 0x04
261 #define ADC10_REG3_L2MUX_TO_REFP 0x05
262 #define ADC10_REG3_L2MUX_TO_REFN 0x06
263 
269 #define ADC10_REG3_DATA_MODE_MANUAL 0x00
270 #define ADC10_REG3_DATA_MODE_AUTO 0x01
271 
277 #define ADC10_REG4_GPIO2_DIR_INPUT 0x00
278 #define ADC10_REG4_GPIO2_DIR_OUTPUT 0x01
279 #define ADC10_REG4_GPIO1_DIR_INPUT 0x00
280 #define ADC10_REG4_GPIO1_DIR_OUTPUT 0x01
281 #define ADC10_REG4_GPIO0_DIR_INPUT 0x00
282 #define ADC10_REG4_GPIO0_DIR_OUTPUT 0x01
283 
289 #define ADC10_REG4_GPIO2_SEL_DAT 0x00
290 #define ADC10_REG4_GPIO2_SEL_DRDY 0x01
291 
297 #define ADC10_REG4_GPIO_LOW 0x00
298 #define ADC10_REG4_GPIO_HIGH 0x01
299 
304 #define ADC10_ANALOG_INPUT_CH_0 0x00
305 #define ADC10_ANALOG_INPUT_CH_1 0x01
306 #define ADC10_ANALOG_INPUT_CH_2 0x02
307 #define ADC10_ANALOG_INPUT_CH_3 0x03
308 
313 #define ADC10_NEW_DATA_IS_READY 0x00
314 #define ADC10_NEW_DATA_NOT_READY 0x01
315 
320 #define ADC10_GAIN_1 1
321 #define ADC10_GAIN_2 2
322 #define ADC10_GAIN_4 4
323 #define ADC10_GAIN_8 8
324 #define ADC10_GAIN_16 16
325 #define ADC10_GAIN_32 32
326 #define ADC10_GAIN_64 64
327 #define ADC10_GAIN_128 128
328 
333 #define ADC10_REG_BITS 0x0E
334 #define ADC10_ADC_RESOLUTION 0x007FFFFF
335 #define ADC10_VREF_INTERNAL 2048.0
336 #define ADC10_VREF_EXTERNAL_3300_mA 3300.0
337 #define ADC10_VREF_EXTERNAL_5000_mA 5000.0
338 
339 
345 #define DRV_BUFFER_SIZE 200
346  // adc10_set
348 
363 #define ADC10_MAP_MIKROBUS( cfg, mikrobus ) \
364  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
365  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
366  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
367  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
368  // adc10_map // adc10
371 
376 typedef struct
377 {
378  // Output pins
379 
380  digital_out_t rst;
382  // Input pins
383 
384  digital_in_t int_pin;
386  // Modules
387 
388  uart_t uart;
390  // Buffers
391 
392  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
393  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
395 } adc10_t;
396 
401 typedef struct
402 {
403  // Communication gpio pins
404 
405  pin_name_t rx_pin;
406  pin_name_t tx_pin;
408  // Additional gpio pins
409 
410  pin_name_t rst;
411  pin_name_t int_pin;
413  // Static variable
414 
415  uint32_t baud_rate;
416  bool uart_blocking;
417  uart_data_bits_t data_bit;
418  uart_parity_t parity_bit;
419  uart_stop_bits_t stop_bit;
421 } adc10_cfg_t;
422 
423 typedef struct
424 {
425  uint8_t input_mux;
426  uint8_t gain;
427  uint8_t pga_bypass;
428  uint8_t data_rate;
429  uint8_t op_mode;
430  uint8_t conv_mode;
431  uint8_t vref;
432  uint8_t temp_sensor;
433  uint8_t conv_drdy;
434  uint8_t data_cnt;
435  uint8_t data_integ_check;
436  uint8_t b_current_src;
437  uint8_t idac_current;
438  uint8_t idac1_routing;
439  uint8_t idac2_routing;
440  uint8_t adc_data_out_mode;
441  uint8_t gpio2_ctrl;
442  uint8_t gpio1_ctrl;
443  uint8_t gpio0_ctrl;
444  uint8_t gpio2_drdy_ctrl;
445  uint8_t gpio2_io_lvl;
446  uint8_t gpio1_io_lvl;
447  uint8_t gpio0_io_lvl;
448 }
450 
466 void adc10_cfg_setup ( adc10_cfg_t *cfg );
467 
482 err_t adc10_init ( adc10_t *ctx, adc10_cfg_t *cfg );
483 
495 void adc10_default_cfg ( adc10_t *ctx );
496 
510 err_t adc10_generic_write ( adc10_t *ctx, char *data_buf, uint16_t len );
511 
525 err_t adc10_generic_read ( adc10_t *ctx, char *data_buf, uint16_t max_len );
526 
538 void adc10_hw_reset ( adc10_t *ctx );
539 
553 uint8_t adc10_check_drdy ( adc10_t *ctx );
554 
567 void adc10_send_command ( adc10_t *ctx, uint8_t cmd );
568 
580 void adc10_reset ( adc10_t *ctx );
581 
593 void adc10_start_sync ( adc10_t *ctx );
594 
606 void adc10_shutdown ( adc10_t *ctx );
607 
622 void adc10_write_reg ( adc10_t *ctx, uint8_t reg, uint8_t tx_data );
623 
637 uint8_t adc10_read_reg ( adc10_t *ctx, uint8_t reg );
638 
654 int32_t adc10_get_ch_output ( adc10_t *ctx, uint8_t sel_ch );
655 
670 float adc10_calc_voltage ( adc10_t *ctx, int32_t adc_data, float vref, uint8_t gain );
671 
684 void adc10_set_config ( adc10_t *ctx, adc10_settings_t cfg_data );
685 
698 void adc10_get_config ( adc10_t *ctx, adc10_settings_t *cfg_data );
699 
700 
701 
702 #ifdef __cplusplus
703 }
704 #endif
705 #endif // ADC10_H
706  // adc10
708 
709 // ------------------------------------------------------------------------ END
adc10_calc_voltage
float adc10_calc_voltage(adc10_t *ctx, int32_t adc_data, float vref, uint8_t gain)
ADC 10 Calculate the voltage function.
adc10_set_config
void adc10_set_config(adc10_t *ctx, adc10_settings_t cfg_data)
ADC 10 Set configuration function.
adc10_shutdown
void adc10_shutdown(adc10_t *ctx)
ADC 10 Shutdown function.
adc10_get_ch_output
int32_t adc10_get_ch_output(adc10_t *ctx, uint8_t sel_ch)
ADC 10 Get the channel output function.
adc10_reset
void adc10_reset(adc10_t *ctx)
ADC 10 Software reset function.
adc10_cfg_setup
void adc10_cfg_setup(adc10_cfg_t *cfg)
ADC 10 configuration object setup function.
adc10_hw_reset
void adc10_hw_reset(adc10_t *ctx)
ADC 10 Hardware reset function.
adc10_read_reg
uint8_t adc10_read_reg(adc10_t *ctx, uint8_t reg)
ADC 10 Read register function.
adc10_default_cfg
void adc10_default_cfg(adc10_t *ctx)
ADC 10 default configuration function.
adc10_settings_t
Definition: adc10.h:422
adc10_start_sync
void adc10_start_sync(adc10_t *ctx)
ADC 10 Start the synchronization function.
adc10_generic_read
err_t adc10_generic_read(adc10_t *ctx, char *data_buf, uint16_t max_len)
ADC 10 data reading function.
adc10_cfg_t
ADC 10 Click configuration object.
Definition: adc10.h:400
adc10_check_drdy
uint8_t adc10_check_drdy(adc10_t *ctx)
ADC 10 Check DRDY function.
adc10_get_config
void adc10_get_config(adc10_t *ctx, adc10_settings_t *cfg_data)
ADC 10 Get configuration function.
adc10_t
ADC 10 Click context object.
Definition: adc10.h:375
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
ADC 10 driver buffer size.
Definition: adc10.h:344
adc10_write_reg
void adc10_write_reg(adc10_t *ctx, uint8_t reg, uint8_t tx_data)
ADC 10 Write register function.
adc10_generic_write
err_t adc10_generic_write(adc10_t *ctx, char *data_buf, uint16_t len)
ADC 10 data writing function.
adc10_init
err_t adc10_init(adc10_t *ctx, adc10_cfg_t *cfg)
ADC 10 initialization function.
adc10_send_command
void adc10_send_command(adc10_t *ctx, uint8_t cmd)
ADC 10 Send command function.