adac4 2.2.0
Loading...
Searching...
No Matches
adac4.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 ADAC4_H
29#define ADAC4_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_i2c_master.h"
52
58
63
68
73#define ADAC4_REG_ADC_SEQ 0x02
74#define ADAC4_REG_ADC_DAC_CFG 0x03
75#define ADAC4_REG_ADC_SEL 0x04
76#define ADAC4_REG_DAC_SEL 0x05
77#define ADAC4_REG_PULL_DOWN_SEL 0x06
78#define ADAC4_REG_LDAC_CTRL 0x07
79#define ADAC4_REG_GPIO_WRITE_SEL 0x08
80#define ADAC4_REG_GPIO_WRITE_DATA 0x09
81#define ADAC4_REG_GPIO_READ_SEL 0x0A
82#define ADAC4_REG_POWER_DOWN_CTRL 0x0B
83#define ADAC4_REG_OPEN_DRAIN_CFG 0x0C
84#define ADAC4_REG_THREE_STATE_SEL 0x0D
85#define ADAC4_REG_SW_RESET 0x0F
86#define ADAC4_REG_DAC_WRITE 0x10
87#define ADAC4_REG_ADC_READ 0x40
88#define ADAC4_REG_DAC_READ 0x50
89#define ADAC4_REG_GPIO_READ 0x60
90#define ADAC4_REG_CHIP_ID 0x7E
91 // adac4_reg
93
98
103
108#define ADAC4_ADC_SEQ_REP_EN 0x0200
109#define ADAC4_ADC_SEQ_TEMP_EN 0x0100
110#define ADAC4_ADC_SEQ_ADC7_SEL 0x0080
111#define ADAC4_ADC_SEQ_ADC6_SEL 0x0040
112#define ADAC4_ADC_SEQ_ADC5_SEL 0x0020
113#define ADAC4_ADC_SEQ_ADC4_SEL 0x0010
114#define ADAC4_ADC_SEQ_ADC3_SEL 0x0008
115#define ADAC4_ADC_SEQ_ADC2_SEL 0x0004
116#define ADAC4_ADC_SEQ_ADC1_SEL 0x0002
117#define ADAC4_ADC_SEQ_ADC0_SEL 0x0001
118
123#define ADAC4_ADC_DAC_CFG_PRE_CHARGE_EN 0x0200
124#define ADAC4_ADC_DAC_CFG_ADC_BUFFER_EN 0x0100
125#define ADAC4_ADC_DAC_CFG_GPIO_LOCK 0x0080
126#define ADAC4_ADC_DAC_CFG_DAC_WRITE_ALL 0x0040
127#define ADAC4_ADC_DAC_CFG_ADC_RANGE_2X 0x0020
128#define ADAC4_ADC_DAC_CFG_DAC_RANGE_2X 0x0010
129
134#define ADAC4_DAC_SEL_CHANNEL_7 0x0080
135#define ADAC4_DAC_SEL_CHANNEL_6 0x0040
136#define ADAC4_DAC_SEL_CHANNEL_5 0x0020
137#define ADAC4_DAC_SEL_CHANNEL_4 0x0010
138#define ADAC4_DAC_SEL_CHANNEL_3 0x0008
139#define ADAC4_DAC_SEL_CHANNEL_2 0x0004
140#define ADAC4_DAC_SEL_CHANNEL_1 0x0002
141#define ADAC4_DAC_SEL_CHANNEL_0 0x0001
142#define ADAC4_DAC_SEL_ALL_CHANNELS 0x00FF
143
148#define ADAC4_DAC_DATA_MSB 0x8000
149#define ADAC4_DAC_DATA_ADDR_MASK 0x7000
150#define ADAC4_DAC_DATA_DATA_MASK 0x0FFF
151#define ADAC4_DAC_DATA_MIN 0
152#define ADAC4_DAC_DATA_MAX 4095
153
158#define ADAC4_ADC_DATA_MSB 0x8000
159#define ADAC4_ADC_DATA_ADDR_MASK 0x7000
160#define ADAC4_ADC_DATA_DATA_MASK 0x0FFF
161
166#define ADAC4_POWER_DOWN_CTRL_PD_ALL 0x0400
167#define ADAC4_POWER_DOWN_CTRL_EN_REF 0x0200
168#define ADAC4_POWER_DOWN_CTRL_PD7 0x0080
169#define ADAC4_POWER_DOWN_CTRL_PD6 0x0040
170#define ADAC4_POWER_DOWN_CTRL_PD5 0x0020
171#define ADAC4_POWER_DOWN_CTRL_PD4 0x0010
172#define ADAC4_POWER_DOWN_CTRL_PD3 0x0008
173#define ADAC4_POWER_DOWN_CTRL_PD2 0x0004
174#define ADAC4_POWER_DOWN_CTRL_PD1 0x0002
175#define ADAC4_POWER_DOWN_CTRL_PD0 0x0001
176
181#define ADAC4_CHIP_ID 0x0808
182
187#define ADAC4_TEMP_OFFSET 1024.0
188#define ADAC4_TEMP_RES 16.0
189
194#define ADAC4_VREF_INT 2.5
195
200#define ADAC4_CHANNEL_0 0
201#define ADAC4_CHANNEL_1 1
202#define ADAC4_CHANNEL_2 2
203#define ADAC4_CHANNEL_3 3
204#define ADAC4_CHANNEL_4 4
205#define ADAC4_CHANNEL_5 5
206#define ADAC4_CHANNEL_6 6
207#define ADAC4_CHANNEL_7 7
208
214#define ADAC4_DEVICE_ADDRESS_0 0x10
215#define ADAC4_DEVICE_ADDRESS_1 0x11
216 // adac4_set
218
223
228
233#define ADAC4_MAP_MIKROBUS( cfg, mikrobus ) \
234 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
235 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
236 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
237 // adac4_map // adac4
240
245typedef struct
246{
247 // Output pins
248 digital_out_t rst;
249
250 // Modules
251 i2c_master_t i2c;
252
253 // I2C slave address
255
256 float vref;
257
258} adac4_t;
259
264typedef struct
265{
266 pin_name_t scl;
267 pin_name_t sda;
268
269 pin_name_t rst;
270
271 uint32_t i2c_speed;
272 uint8_t i2c_address;
273
275
280typedef enum
281{
284
286
292
303
317err_t adac4_init ( adac4_t *ctx, adac4_cfg_t *cfg );
318
332
344err_t adac4_write_reg ( adac4_t *ctx, uint8_t reg, uint16_t data_in );
345
357err_t adac4_read_reg ( adac4_t *ctx, uint8_t reg, uint16_t *data_out );
358
368void adac4_set_rst_pin ( adac4_t *ctx, uint8_t state );
369
379
390
402err_t adac4_write_dac ( adac4_t *ctx, uint8_t channel, uint16_t dac_data );
403
415err_t adac4_read_raw_adc ( adac4_t *ctx, uint8_t channel, uint16_t *raw_adc );
416
428err_t adac4_read_adc_voltage ( adac4_t *ctx, uint8_t channel, float *voltage );
429
440err_t adac4_read_die_temp ( adac4_t *ctx, float *die_temp );
441
442#ifdef __cplusplus
443}
444#endif
445#endif // ADAC4_H
446 // adac4
448
449// ------------------------------------------------------------------------ END
adac4_return_value_t
ADAC 4 Click return value data.
Definition adac4.h:281
@ ADAC4_ERROR
Definition adac4.h:283
@ ADAC4_OK
Definition adac4.h:282
err_t adac4_write_dac(adac4_t *ctx, uint8_t channel, uint16_t dac_data)
ADAC 4 write DAC channel function.
void adac4_cfg_setup(adac4_cfg_t *cfg)
ADAC 4 configuration object setup function.
err_t adac4_default_cfg(adac4_t *ctx)
ADAC 4 default configuration function.
void adac4_set_rst_pin(adac4_t *ctx, uint8_t state)
ADAC 4 set RST pin state function.
err_t adac4_read_adc_voltage(adac4_t *ctx, uint8_t channel, float *voltage)
ADAC 4 read ADC voltage function.
err_t adac4_init(adac4_t *ctx, adac4_cfg_t *cfg)
ADAC 4 initialization function.
err_t adac4_write_reg(adac4_t *ctx, uint8_t reg, uint16_t data_in)
ADAC 4 write register function.
void adac4_reset_device(adac4_t *ctx)
ADAC 4 hardware reset function.
err_t adac4_read_die_temp(adac4_t *ctx, float *die_temp)
ADAC 4 read die temperature function.
err_t adac4_read_reg(adac4_t *ctx, uint8_t reg, uint16_t *data_out)
ADAC 4 read register function.
err_t adac4_check_communication(adac4_t *ctx)
ADAC 4 check communication function.
err_t adac4_read_raw_adc(adac4_t *ctx, uint8_t channel, uint16_t *raw_adc)
ADAC 4 read raw ADC value function.
ADAC 4 Click configuration object.
Definition adac4.h:265
uint32_t i2c_speed
Definition adac4.h:271
pin_name_t scl
Definition adac4.h:266
pin_name_t sda
Definition adac4.h:267
pin_name_t rst
Definition adac4.h:269
uint8_t i2c_address
Definition adac4.h:272
ADAC 4 Click context object.
Definition adac4.h:246
float vref
Definition adac4.h:256
i2c_master_t i2c
Definition adac4.h:251
digital_out_t rst
Definition adac4.h:248
uint8_t slave_address
Definition adac4.h:254