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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
49 
70 #define ADC10_REG_CONFIG_0 0x00
71 #define ADC10_REG_CONFIG_1 0x01
72 #define ADC10_REG_CONFIG_2 0x02
73 #define ADC10_REG_CONFIG_3 0x03
74 #define ADC10_REG_CONFIG_4 0x04
75  // adc10_reg
77 
93 #define ADC10_SYNC_WORD 0x55
94 #define ADC10_CMD_RESET 0x06
95 #define ADC10_CMD_START 0x08
96 #define ADC10_CMD_POWERDOWN 0x03
97 #define ADC10_CMD_RDATA 0x10
98 #define ADC10_CMD_RREG 0x20
99 #define ADC10_CMD_WREG 0x40
100 
106 #define ADC10_REG0_MUX_P0_N1 0x00
107 #define ADC10_REG0_MUX_P0_N2 0x01
108 #define ADC10_REG0_MUX_P0_N3 0x02
109 #define ADC10_REG0_MUX_P1_N0 0x03
110 #define ADC10_REG0_MUX_P1_N2 0x04
111 #define ADC10_REG0_MUX_P1_N3 0x05
112 #define ADC10_REG0_MUX_P2_N3 0x06
113 #define ADC10_REG0_MUX_P3_N2 0x07
114 #define ADC10_REG0_MUX_P0_NS 0x08
115 #define ADC10_REG0_MUX_P1_NS 0x09
116 #define ADC10_REG0_MUX_P2_NS 0x0A
117 #define ADC10_REG0_MUX_P3_NS 0x0B
118 #define ADC10_REG0_MUX_VREF 0x0C
119 #define ADC10_REG0_MUX_AVOLD_4 0x0D
120 #define ADC10_REG0_MUX_AVOLAVER 0x0E
121 #define ADC10_REG0_MUX_RESERVE 0x0F
122 
128 #define ADC10_REG0_GAIN_1 0x00
129 #define ADC10_REG0_GAIN_2 0x01
130 #define ADC10_REG0_GAIN_4 0x02
131 #define ADC10_REG0_GAIN_8 0x03
132 #define ADC10_REG0_GAIN_16 0x04
133 #define ADC10_REG0_GAIN_32 0x05
134 #define ADC10_REG0_GAIN_64 0x06
135 #define ADC10_REG0_GAIN_128 0x07
136 
142 #define ADC10_REG0_PGA_ENABLED 0x00
143 #define ADC10_REG0_PGA_DISABLED 0x01
144 
150 #define ADC10_REG1_DR_NORMAL_20 0x00
151 #define ADC10_REG1_DR_NORMAL_45 0x01
152 #define ADC10_REG1_DR_NORMAL_90 0x02
153 #define ADC10_REG1_DR_NORMAL_175 0x03
154 #define ADC10_REG1_DR_NORMAL_330 0x04
155 #define ADC10_REG1_DR_NORMAL_600 0x05
156 #define ADC10_REG1_DR_NORMAL_1000 0x06
157 #define ADC10_REG1_DR_TURBO_40 0x00
158 #define ADC10_REG1_DR_TURBO_90 0x01
159 #define ADC10_REG1_DR_TURBO_180 0x02
160 #define ADC10_REG1_DR_TURBO_350 0x03
161 #define ADC10_REG1_DR_TURBO_660 0x04
162 #define ADC10_REG1_DR_TURBO_1200 0x05
163 #define ADC10_REG1_DR_TURBO_2000 0x06
164 
170 #define ADC10_REG1_MODE_NORMAL 0x00
171 #define ADC10_REG1_MODE_TURBO 0x01
172 
178 #define ADC10_REG1_CM_SINGAL_SHOT 0x00
179 #define ADC10_REG1_CM_CONTINUOUS 0x01
180 
186 #define ADC10_REG1_VREF_INTERNAL_2048 0x00
187 #define ADC10_REG1_VREF_EXTERNAL_REF 0x01
188 #define ADC10_REG1_VREF_ANALOG_1 0x02
189 #define ADC10_REG1_VREF_ANALOG_2 0x03
190 
196 #define ADC10_REG1_TS_DISABLED 0x00
197 #define ADC10_REG1_TS_ENABLED 0x01
198 
204 #define ADC10_REG2_DRDY_NOT_READY 0x00
205 #define ADC10_REG2_DRDY_READY 0x01
206 
212 #define ADC10_REG2_DCNT_DISABLED 0x00
213 #define ADC10_REG2_DCNT_ENABLED 0x01
214 
220 #define ADC10_REG2_CRC_DISABLED 0x00
221 #define ADC10_REG2_CRC_INVERTED_ENABLED 0x01
222 #define ADC10_REG2_CRC_CRC16_ENABLED 0x02
223 #define ADC10_REG2_CRC_RESERVED 0x03
224 
230 #define ADC10_REG2_BCS_CURRENT_SOURCE_OFF 0x00
231 #define ADC10_REG2_BCS_CURRENT_SOURCE_ON 0x01
232 
238 #define ADC10_REG2_IDAC_CURRENT_OFF 0x00
239 #define ADC10_REG2_IDAC_CURRENT_10_uA 0x01
240 #define ADC10_REG2_IDAC_CURRENT_50_uA 0x02
241 #define ADC10_REG2_IDAC_CURRENT_100_uA 0x03
242 #define ADC10_REG2_IDAC_CURRENT_250_uA 0x04
243 #define ADC10_REG2_IDAC_CURRENT_500_uA 0x05
244 #define ADC10_REG2_IDAC_CURRENT_1000_uA 0x06
245 #define ADC10_REG2_IDAC_CURRENT_1500_uA 0x07
246 
252 #define ADC10_REG3_L1MUX_DISABLED 0x00
253 #define ADC10_REG3_L1MUX_TO_AIN0 0x01
254 #define ADC10_REG3_L1MUX_TO_AIN1 0x02
255 #define ADC10_REG3_L1MUX_TO_AIN2 0x03
256 #define ADC10_REG3_L1MUX_TO_AIN3 0x04
257 #define ADC10_REG3_L1MUX_TO_REFP 0x05
258 #define ADC10_REG3_L1MUX_TO_REFN 0x06
259 #define ADC10_REG3_L1MUX_RESERVED 0x07
260 
266 #define ADC10_REG3_L2MUX_DISABLED 0x00
267 #define ADC10_REG3_L2MUX_TO_AIN0 0x01
268 #define ADC10_REG3_L2MUX_TO_AIN1 0x02
269 #define ADC10_REG3_L2MUX_TO_AIN2 0x03
270 #define ADC10_REG3_L2MUX_TO_AIN3 0x04
271 #define ADC10_REG3_L2MUX_TO_REFP 0x05
272 #define ADC10_REG3_L2MUX_TO_REFN 0x06
273 
279 #define ADC10_REG3_DATA_MODE_MANUAL 0x00
280 #define ADC10_REG3_DATA_MODE_AUTO 0x01
281 
287 #define ADC10_REG4_GPIO2_DIR_INPUT 0x00
288 #define ADC10_REG4_GPIO2_DIR_OUTPUT 0x01
289 #define ADC10_REG4_GPIO1_DIR_INPUT 0x00
290 #define ADC10_REG4_GPIO1_DIR_OUTPUT 0x01
291 #define ADC10_REG4_GPIO0_DIR_INPUT 0x00
292 #define ADC10_REG4_GPIO0_DIR_OUTPUT 0x01
293 
299 #define ADC10_REG4_GPIO2_SEL_DAT 0x00
300 #define ADC10_REG4_GPIO2_SEL_DRDY 0x01
301 
307 #define ADC10_REG4_GPIO_LOW 0x00
308 #define ADC10_REG4_GPIO_HIGH 0x01
309 
314 #define ADC10_ANALOG_INPUT_CH_0 0x00
315 #define ADC10_ANALOG_INPUT_CH_1 0x01
316 #define ADC10_ANALOG_INPUT_CH_2 0x02
317 #define ADC10_ANALOG_INPUT_CH_3 0x03
318 
323 #define ADC10_NEW_DATA_IS_READY 0x00
324 #define ADC10_NEW_DATA_NOT_READY 0x01
325 
330 #define ADC10_GAIN_1 1
331 #define ADC10_GAIN_2 2
332 #define ADC10_GAIN_4 4
333 #define ADC10_GAIN_8 8
334 #define ADC10_GAIN_16 16
335 #define ADC10_GAIN_32 32
336 #define ADC10_GAIN_64 64
337 #define ADC10_GAIN_128 128
338 
343 #define ADC10_REG_BITS 0x0E
344 #define ADC10_ADC_RESOLUTION 0x007FFFFF
345 #define ADC10_VREF_INTERNAL 2048.0
346 #define ADC10_VREF_EXTERNAL_3300_mA 3300.0
347 #define ADC10_VREF_EXTERNAL_5000_mA 5000.0
348 
349 
355 #define DRV_BUFFER_SIZE 200
356  // adc10_set
358 
373 #define ADC10_MAP_MIKROBUS( cfg, mikrobus ) \
374  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
375  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
376  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
377  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
378  // adc10_map // adc10
381 
386 typedef struct
387 {
388  // Output pins
389 
390  digital_out_t rst;
392  // Input pins
393 
394  digital_in_t int_pin;
396  // Modules
397 
398  uart_t uart;
400  // Buffers
401 
402  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
403  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
405 } adc10_t;
406 
411 typedef struct
412 {
413  // Communication gpio pins
414 
415  pin_name_t rx_pin;
416  pin_name_t tx_pin;
418  // Additional gpio pins
419 
420  pin_name_t rst;
421  pin_name_t int_pin;
423  // Static variable
424 
425  uint32_t baud_rate;
427  uart_data_bits_t data_bit;
428  uart_parity_t parity_bit;
429  uart_stop_bits_t stop_bit;
431 } adc10_cfg_t;
432 
433 typedef struct
434 {
435  uint8_t input_mux;
436  uint8_t gain;
437  uint8_t pga_bypass;
438  uint8_t data_rate;
439  uint8_t op_mode;
440  uint8_t conv_mode;
441  uint8_t vref;
442  uint8_t temp_sensor;
443  uint8_t conv_drdy;
444  uint8_t data_cnt;
446  uint8_t b_current_src;
447  uint8_t idac_current;
448  uint8_t idac1_routing;
449  uint8_t idac2_routing;
451  uint8_t gpio2_ctrl;
452  uint8_t gpio1_ctrl;
453  uint8_t gpio0_ctrl;
455  uint8_t gpio2_io_lvl;
456  uint8_t gpio1_io_lvl;
457  uint8_t gpio0_io_lvl;
458 }
460 
477 
492 err_t adc10_init ( adc10_t *ctx, adc10_cfg_t *cfg );
493 
506 
520 err_t adc10_generic_write ( adc10_t *ctx, char *data_buf, uint16_t len );
521 
535 err_t adc10_generic_read ( adc10_t *ctx, char *data_buf, uint16_t max_len );
536 
548 void adc10_hw_reset ( adc10_t *ctx );
549 
563 uint8_t adc10_check_drdy ( adc10_t *ctx );
564 
577 void adc10_send_command ( adc10_t *ctx, uint8_t cmd );
578 
590 void adc10_reset ( adc10_t *ctx );
591 
603 void adc10_start_sync ( adc10_t *ctx );
604 
616 void adc10_shutdown ( adc10_t *ctx );
617 
632 void adc10_write_reg ( adc10_t *ctx, uint8_t reg, uint8_t tx_data );
633 
647 uint8_t adc10_read_reg ( adc10_t *ctx, uint8_t reg );
648 
664 int32_t adc10_get_ch_output ( adc10_t *ctx, uint8_t sel_ch );
665 
680 float adc10_calc_voltage ( adc10_t *ctx, int32_t adc_data, float vref, uint8_t gain );
681 
694 void adc10_set_config ( adc10_t *ctx, adc10_settings_t cfg_data );
695 
708 void adc10_get_config ( adc10_t *ctx, adc10_settings_t *cfg_data );
709 
710 
711 
712 #ifdef __cplusplus
713 }
714 #endif
715 #endif // ADC10_H
716  // adc10
718 
719 // ------------------------------------------------------------------------ END
adc10_settings_t::gpio1_io_lvl
uint8_t gpio1_io_lvl
Definition: adc10.h:456
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_settings_t::gpio0_io_lvl
uint8_t gpio0_io_lvl
Definition: adc10.h:457
adc10_set_config
void adc10_set_config(adc10_t *ctx, adc10_settings_t cfg_data)
ADC 10 Set configuration function.
adc10_settings_t::op_mode
uint8_t op_mode
Definition: adc10.h:439
adc10_settings_t::data_integ_check
uint8_t data_integ_check
Definition: adc10.h:445
adc10_settings_t::idac2_routing
uint8_t idac2_routing
Definition: adc10.h:449
adc10_shutdown
void adc10_shutdown(adc10_t *ctx)
ADC 10 Shutdown function.
adc10_settings_t::adc_data_out_mode
uint8_t adc_data_out_mode
Definition: adc10.h:450
adc10_settings_t::gpio0_ctrl
uint8_t gpio0_ctrl
Definition: adc10.h:453
adc10_settings_t::pga_bypass
uint8_t pga_bypass
Definition: adc10.h:437
adc10_cfg_t::rx_pin
pin_name_t rx_pin
Definition: adc10.h:415
adc10_cfg_t::tx_pin
pin_name_t tx_pin
Definition: adc10.h:416
adc10_t::int_pin
digital_in_t int_pin
Definition: adc10.h:394
adc10_settings_t::idac_current
uint8_t idac_current
Definition: adc10.h:447
adc10_settings_t::gain
uint8_t gain
Definition: adc10.h:436
adc10_settings_t::gpio2_drdy_ctrl
uint8_t gpio2_drdy_ctrl
Definition: adc10.h:454
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_cfg_t::baud_rate
uint32_t baud_rate
Definition: adc10.h:425
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_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: adc10.h:427
adc10_read_reg
uint8_t adc10_read_reg(adc10_t *ctx, uint8_t reg)
ADC 10 Read register function.
adc10_settings_t::input_mux
uint8_t input_mux
Definition: adc10.h:435
adc10_default_cfg
void adc10_default_cfg(adc10_t *ctx)
ADC 10 default configuration function.
adc10_settings_t
Definition: adc10.h:434
adc10_cfg_t::uart_blocking
bool uart_blocking
Definition: adc10.h:426
adc10_t::rst
digital_out_t rst
Definition: adc10.h:390
adc10_settings_t::conv_mode
uint8_t conv_mode
Definition: adc10.h:440
adc10_settings_t::b_current_src
uint8_t b_current_src
Definition: adc10.h:446
adc10_start_sync
void adc10_start_sync(adc10_t *ctx)
ADC 10 Start the synchronization function.
adc10_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: adc10.h:429
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:412
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:387
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
ADC 10 driver buffer size.
Definition: adc10.h:355
adc10_write_reg
void adc10_write_reg(adc10_t *ctx, uint8_t reg, uint8_t tx_data)
ADC 10 Write register function.
adc10_settings_t::gpio2_io_lvl
uint8_t gpio2_io_lvl
Definition: adc10.h:455
adc10_settings_t::gpio2_ctrl
uint8_t gpio2_ctrl
Definition: adc10.h:451
adc10_settings_t::data_cnt
uint8_t data_cnt
Definition: adc10.h:444
adc10_cfg_t::int_pin
pin_name_t int_pin
Definition: adc10.h:421
adc10_settings_t::conv_drdy
uint8_t conv_drdy
Definition: adc10.h:443
adc10_generic_write
err_t adc10_generic_write(adc10_t *ctx, char *data_buf, uint16_t len)
ADC 10 data writing function.
adc10_settings_t::temp_sensor
uint8_t temp_sensor
Definition: adc10.h:442
adc10_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: adc10.h:428
adc10_t::uart
uart_t uart
Definition: adc10.h:398
adc10_cfg_t::rst
pin_name_t rst
Definition: adc10.h:420
adc10_settings_t::vref
uint8_t vref
Definition: adc10.h:441
adc10_init
err_t adc10_init(adc10_t *ctx, adc10_cfg_t *cfg)
ADC 10 initialization function.
adc10_settings_t::idac1_routing
uint8_t idac1_routing
Definition: adc10.h:448
adc10_settings_t::data_rate
uint8_t data_rate
Definition: adc10.h:438
adc10_send_command
void adc10_send_command(adc10_t *ctx, uint8_t cmd)
ADC 10 Send command function.
adc10_settings_t::gpio1_ctrl
uint8_t gpio1_ctrl
Definition: adc10.h:452