dac14 2.1.0.0
dac14.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 DAC14_H
29#define DAC14_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#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define DAC14_REG_NOP 0x00
76#define DAC14_REG_DAC1_MARGIN_HIGH 0x01
77#define DAC14_REG_DAC1_MARGIN_LOW 0x02
78#define DAC14_REG_DAC1_VOUT_CMP_CONFIG 0x03
79#define DAC14_REG_DAC1_IOUT_MISC_CONFIG 0x04
80#define DAC14_REG_DAC1_CMP_MODE_CONFIG 0x05
81#define DAC14_REG_DAC1_FUNC_CONFIG 0x06
82#define DAC14_REG_DAC0_MARGIN_HIGH 0x13
83#define DAC14_REG_DAC0_MARGIN_LOW 0x14
84#define DAC14_REG_DAC0_VOUT_CMP_CONFIG 0x15
85#define DAC14_REG_DAC0_IOUT_MISC_CONFIG 0x16
86#define DAC14_REG_DAC0_CMP_MODE_CONFIG 0x17
87#define DAC14_REG_DAC0_FUNC_CONFIG 0x18
88#define DAC14_REG_DAC1_DATA 0x19
89#define DAC14_REG_DAC0_DATA 0x1C
90#define DAC14_REG_COMMON_CONFIG 0x1F
91#define DAC14_REG_COMMON_TRIGGER 0x20
92#define DAC14_REG_COMMON_DAC_TRIG 0x21
93#define DAC14_REG_GENERAL_STATUS 0x22
94#define DAC14_REG_CMP_STATUS 0x23
95#define DAC14_REG_GPIO_CONFIG 0x24
96#define DAC14_REG_DEVICE_MODE_CONFIG 0x25
97#define DAC14_REG_INTERFACE_CONFIG 0x26
98#define DAC14_REG_SRAM_CONFIG 0x2B
99#define DAC14_REG_SRAM_DATA 0x2C
100#define DAC14_REG_BRDCAST_DATA 0x50
101
102 // dac14_reg
103
118#define DAC14_CC_WIN_LATCH_EN 0x8000
119#define DAC14_CC_DEV_LOCK 0x4000
120#define DAC14_CC_EE_READ_ADDR 0x2000
121#define DAC14_CC_EN_INT_REF 0x1000
122#define DAC14_CC_VOUT_PDN_0_POWER_UP 0x0000
123#define DAC14_CC_VOUT_PDN_0_POWER_DOWN_10K 0x0400
124#define DAC14_CC_VOUT_PDN_0_POWER_DOWN_100K 0x0800
125#define DAC14_CC_VOUT_PDN_0_POWER_DOWN_Z 0x0C00
126#define DAC14_CC_VOUT_PDN_0_MASK 0x0C00
127#define DAC14_CC_IOUT_PDN_0_POWER_UP 0x0000
128#define DAC14_CC_IOUT_PDN_0_POWER_DOWN 0x0200
129#define DAC14_CC_IOUT_PDN_0_MASK 0x0200
130#define DAC14_CC_RESERVED 0x0088
131#define DAC14_CC_VOUT_PDN_1_POWER_UP 0x0000
132#define DAC14_CC_VOUT_PDN_1_POWER_DOWN_10K 0x0002
133#define DAC14_CC_VOUT_PDN_1_POWER_DOWN_100K 0x0004
134#define DAC14_CC_VOUT_PDN_1_POWER_DOWN_Z 0x0006
135#define DAC14_CC_VOUT_PDN_1_MASK 0x0006
136#define DAC14_CC_IOUT_PDN_1_POWER_UP 0x0000
137#define DAC14_CC_IOUT_PDN_1_POWER_DOWN 0x0001
138#define DAC14_CC_IOUT_PDN_1_MASK 0x0001
139
144#define DAC14_CDT_RESET_CMP_FLAG_1 0x8000
145#define DAC14_CDT_TRIG_MAR_LO_1 0x4000
146#define DAC14_CDT_TRIG_MAR_HI_1 0x2000
147#define DAC14_CDT_STOP_FUNC_1 0x0000
148#define DAC14_CDT_START_FUNC_1 0x1000
149#define DAC14_CDT_RESET_CMP_FLAG_0 0x0008
150#define DAC14_CDT_TRIG_MAR_LO_0 0x0004
151#define DAC14_CDT_TRIG_MAR_HI_0 0x0002
152#define DAC14_CDT_START_FUNC_0 0x0001
153#define DAC14_CDT_STOP_FUNC_0 0x0000
154
159#define DAC14_DXFC_CLR_SEL_X 0x8000
160#define DAC14_DXFC_SYNC_CONFIG_X 0x4000
161#define DAC14_DXFC_BRD_CONFIG_X 0x2000
162#define DAC14_DXFC_PHASE_SEL_X_0_DEG 0x0000
163#define DAC14_DXFC_PHASE_SEL_X_120_DEG 0x0800
164#define DAC14_DXFC_PHASE_SEL_X_240_DEG 0x1000
165#define DAC14_DXFC_PHASE_SEL_X_90_DEG 0x1800
166#define DAC14_DXFC_PHASE_SEL_X_MASK 0x1800
167#define DAC14_DXFC_FUNC_CONFIG_X_TRIANGULAR 0x0000
168#define DAC14_DXFC_FUNC_CONFIG_X_SAWTH 0x0100
169#define DAC14_DXFC_FUNC_CONFIG_X_INV_SAWTH 0x0200
170#define DAC14_DXFC_FUNC_CONFIG_X_SINE 0x0400
171#define DAC14_DXFC_FUNC_CONFIG_X_DIS_FC 0x0700
172#define DAC14_DXFC_FUNC_CONFIG_X_MASK 0x0700
173#define DAC14_DXFC_LOG_SLEW_EN_X 0x0080
174#define DAC14_DXFC_CODE_STEP_X_1 0x0000
175#define DAC14_DXFC_CODE_STEP_X_2 0x0010
176#define DAC14_DXFC_CODE_STEP_X_3 0x0020
177#define DAC14_DXFC_CODE_STEP_X_4 0x0030
178#define DAC14_DXFC_CODE_STEP_X_6 0x0040
179#define DAC14_DXFC_CODE_STEP_X_8 0x0050
180#define DAC14_DXFC_CODE_STEP_X_16 0x0060
181#define DAC14_DXFC_CODE_STEP_X_32 0x0070
182#define DAC14_DXFC_CODE_STEP_X_MASK 0x0070
183#define DAC14_DXFC_SLEW_RATE_X_NO_SR 0x0000
184#define DAC14_DXFC_SLEW_RATE_X_4_US 0x0001
185#define DAC14_DXFC_SLEW_RATE_X_8_US 0x0002
186#define DAC14_DXFC_SLEW_RATE_X_12_US 0x0003
187#define DAC14_DXFC_SLEW_RATE_X_18_US 0x0004
188#define DAC14_DXFC_SLEW_RATE_X_27_04_US 0x0005
189#define DAC14_DXFC_SLEW_RATE_X_40_48_US 0x0006
190#define DAC14_DXFC_SLEW_RATE_X_60_72_US 0x0007
191#define DAC14_DXFC_SLEW_RATE_X_91_12_US 0x0008
192#define DAC14_DXFC_SLEW_RATE_X_136_72_US 0x0009
193#define DAC14_DXFC_SLEW_RATE_X_239_2_US 0x000A
194#define DAC14_DXFC_SLEW_RATE_X_418_64_US 0x000B
195#define DAC14_DXFC_SLEW_RATE_X_732_56_US 0x000C
196#define DAC14_DXFC_SLEW_RATE_X_1282_US 0x000D
197#define DAC14_DXFC_SLEW_RATE_X_2563_96_US 0x000E
198#define DAC14_DXFC_SLEW_RATE_X_5127_92_US 0x000F
199#define DAC14_DXFC_SLEW_RATE_X_MASK 0x000F
200
205#define DAC14_VCC_VOUT_GAIN_X_EXT_VREF 0x0000
206#define DAC14_VCC_VOUT_GAIN_X_VDD 0x0400
207#define DAC14_VCC_VOUT_GAIN_X_INT_1_5X 0x0800
208#define DAC14_VCC_VOUT_GAIN_X_INT_2X 0x0C00
209#define DAC14_VCC_VOUT_GAIN_X_INT_3X 0x1000
210#define DAC14_VCC_VOUT_GAIN_X_INT_4X 0x1400
211#define DAC14_VCC_VOUT_GAIN_X_MASK 0x1C00
212#define DAC14_VCC_CMP_X_OD_EN 0x0010
213#define DAC14_VCC_CMP_X_OUT_EN 0x0008
214#define DAC14_VCC_CMP_X_HIZ_IN_EN 0x0004
215#define DAC14_VCC_CMP_X_INV_EN 0x0002
216#define DAC14_VCC_CMP_X_EN 0x0001
217
222#define DAC14_IC_TIMEOUT_EN 0x1000
223#define DAC14_IC_EN_PMBUS 0x0100
224#define DAC14_IC_FSDO_EN 0x0004
225#define DAC14_IC_SDO_EN 0x0001
226#define DAC14_IC_SDO_DIS 0x0000
227
232#define DAC14_DAC_DATA_MAX 1023
233#define DAC14_DAC_DATA_MIN 0
234
239#define DAC14_DEVICE_ID_MASK 0xFC
240#define DAC14_DEVICE_ID 0x1C
241
246#define DAC14_SEL_DAC_0 0
247#define DAC14_SEL_DAC_1 1
248
253#define DAC14_EN_VOUT_POWER_UP 0
254#define DAC14_EN_VOUT_POWER_DOWN_10K_AGND 1
255#define DAC14_EN_VOUT_POWER_DOWN_100K_AGND 2
256#define DAC14_EN_VOUT_POWER_DOWN_HI_Z_AGND 3
257
262#define DAC14_WAVEFORM_TRIANGULAR 0
263#define DAC14_WAVEFORM_SAWTOOTH 1
264#define DAC14_WAVEFORM_INV_SAWTOOTH 2
265#define DAC14_WAVEFORM_SINE 4
266#define DAC14_WAVEFORM_DISABLE 7
267
272#define DAC14_CODE_STEP_1_LSB 0
273#define DAC14_CODE_STEP_2_LSB 1
274#define DAC14_CODE_STEP_3_LSB 2
275#define DAC14_CODE_STEP_4_LSB 3
276#define DAC14_CODE_STEP_6_LSB 4
277#define DAC14_CODE_STEP_8_LSB 5
278#define DAC14_CODE_STEP_16_LSB 6
279#define DAC14_CODE_STEP_32_LSB 7
280
285#define DAC14_SLEW_RATE_NO_SLEW 0
286#define DAC14_SLEW_RATE_4_US 1
287#define DAC14_SLEW_RATE_8_US 2
288#define DAC14_SLEW_RATE_12_US 3
289#define DAC14_SLEW_RATE_18_US 4
290#define DAC14_SLEW_RATE_27_04_US 5
291#define DAC14_SLEW_RATE_40_48_US 6
292#define DAC14_SLEW_RATE_60_72_US 7
293#define DAC14_SLEW_RATE_91_12_US 8
294#define DAC14_SLEW_RATE_136_72_US 9
295#define DAC14_SLEW_RATE_239_2_US 10
296#define DAC14_SLEW_RATE_418_64_US 11
297#define DAC14_SLEW_RATE_732_56_US 12
298#define DAC14_SLEW_RATE_1282_US 13
299#define DAC14_SLEW_RATE_2563_96_US 14
300#define DAC14_SLEW_RATE_5127_92_US 15
301
306#define DAC14_VREF_EXT 0
307#define DAC14_VREF_VDD 1
308#define DAC14_VREF_INT_1_5X 2
309#define DAC14_VREF_INT_2X 3
310#define DAC14_VREF_INT_3X 4
311#define DAC14_VREF_INT_4X 5
312
317#define DAC14_VDD_3V3 3.3f
318#define DAC14_VDD_5V 5.0f
319
325#define DAC14_DEVICE_ADDRESS_GND 0x48
326#define DAC14_DEVICE_ADDRESS_VCC 0x49
327#define DAC14_DEVICE_ADDRESS_SDA 0x4A
328#define DAC14_DEVICE_ADDRESS_SCL 0x4B
329
338#define DAC14_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
339#define DAC14_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
340
341 // dac14_set
342
357#define DAC14_MAP_MIKROBUS( cfg, mikrobus ) \
358 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
359 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
360 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
361 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
362 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
363 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
364 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
365
366 // dac14_map
367 // dac14
368
379
384typedef err_t ( *dac14_master_io_t )( struct dac14_s*, uint8_t, uint16_t* );
405
410typedef struct
411{
412 pin_name_t scl;
413 pin_name_t sda;
414 pin_name_t miso;
415 pin_name_t mosi;
416 pin_name_t sck;
417 pin_name_t cs;
418 pin_name_t int_pin;
420 uint32_t i2c_speed;
421 uint8_t i2c_address;
423 uint32_t spi_speed;
424 spi_master_mode_t spi_mode;
425 spi_master_chip_select_polarity_t cs_polarity;
430
435typedef enum
436{
438 DAC14_ERROR = -1
439
441
458
474
488err_t dac14_init ( dac14_t *ctx, dac14_cfg_t *cfg );
489
503
516err_t dac14_write_register ( dac14_t *ctx, uint8_t reg, uint16_t data_in );
517
530err_t dac14_read_register ( dac14_t *ctx, uint8_t reg, uint16_t *data_out );
531
540uint8_t dac14_get_int_pin ( dac14_t *ctx );
541
553
570err_t dac14_set_dac_vout_enable ( dac14_t *ctx, uint8_t dac, uint8_t vout_pdn );
571
590err_t dac14_set_dac_vref ( dac14_t *ctx, uint8_t dac, uint8_t vref );
591
606err_t dac14_set_dac_margins ( dac14_t *ctx, uint8_t dac, uint16_t margin_l, uint16_t margin_h );
607
621err_t dac14_set_dac_data ( dac14_t *ctx, uint8_t dac, uint16_t dac_data );
622
635err_t dac14_start_function_gen ( dac14_t *ctx, uint8_t dac );
636
649err_t dac14_stop_function_gen ( dac14_t *ctx, uint8_t dac );
650
675err_t dac14_config_function_gen ( dac14_t *ctx, uint8_t dac, uint8_t waveform,
676 uint8_t code_step, uint8_t slew_rate );
677
678#ifdef __cplusplus
679}
680#endif
681#endif // DAC14_H
682
683 // dac14
684
685// ------------------------------------------------------------------------ END
dac14_return_value_t
DAC 14 Click return value data.
Definition dac14.h:436
@ DAC14_OK
Definition dac14.h:437
@ DAC14_ERROR
Definition dac14.h:438
err_t(* dac14_master_io_t)(struct dac14_s *, uint8_t, uint16_t *)
DAC 14 Click driver interface.
Definition dac14.h:384
struct dac14_s dac14_t
DAC 14 Click context object.
dac14_drv_t
DAC 14 Click driver selector.
Definition dac14.h:374
@ DAC14_DRV_SEL_SPI
Definition dac14.h:375
@ DAC14_DRV_SEL_I2C
Definition dac14.h:376
err_t dac14_set_dac_vref(dac14_t *ctx, uint8_t dac, uint8_t vref)
DAC 14 set dac vref function.
void dac14_drv_interface_selection(dac14_cfg_t *cfg, dac14_drv_t drv_sel)
DAC 14 driver interface setup function.
err_t dac14_default_cfg(dac14_t *ctx)
DAC 14 default configuration function.
err_t dac14_start_function_gen(dac14_t *ctx, uint8_t dac)
DAC 14 start function gen function.
err_t dac14_init(dac14_t *ctx, dac14_cfg_t *cfg)
DAC 14 initialization function.
err_t dac14_write_register(dac14_t *ctx, uint8_t reg, uint16_t data_in)
DAC 14 write register function.
err_t dac14_set_dac_data(dac14_t *ctx, uint8_t dac, uint16_t dac_data)
DAC 14 set dac data function.
err_t dac14_config_function_gen(dac14_t *ctx, uint8_t dac, uint8_t waveform, uint8_t code_step, uint8_t slew_rate)
DAC 14 config function gen function.
err_t dac14_set_dac_margins(dac14_t *ctx, uint8_t dac, uint16_t margin_l, uint16_t margin_h)
DAC 14 set dac margins function.
void dac14_cfg_setup(dac14_cfg_t *cfg)
DAC 14 configuration object setup function.
err_t dac14_read_register(dac14_t *ctx, uint8_t reg, uint16_t *data_out)
DAC 14 read register function.
err_t dac14_stop_function_gen(dac14_t *ctx, uint8_t dac)
DAC 14 stop function gen function.
uint8_t dac14_get_int_pin(dac14_t *ctx)
DAC 14 get int pin function.
err_t dac14_check_communication(dac14_t *ctx)
DAC 14 check communication function.
err_t dac14_set_dac_vout_enable(dac14_t *ctx, uint8_t dac, uint8_t vout_pdn)
DAC 14 set dac vout enable function.
This file contains SPI specific macros, functions, etc.
DAC 14 Click configuration object.
Definition dac14.h:411
dac14_drv_t drv_sel
Definition dac14.h:427
uint32_t i2c_speed
Definition dac14.h:420
spi_master_chip_select_polarity_t cs_polarity
Definition dac14.h:425
pin_name_t sck
Definition dac14.h:416
spi_master_mode_t spi_mode
Definition dac14.h:424
pin_name_t mosi
Definition dac14.h:415
uint32_t spi_speed
Definition dac14.h:423
pin_name_t scl
Definition dac14.h:412
pin_name_t int_pin
Definition dac14.h:418
pin_name_t miso
Definition dac14.h:414
pin_name_t sda
Definition dac14.h:413
pin_name_t cs
Definition dac14.h:417
uint8_t i2c_address
Definition dac14.h:421
DAC 14 Click context object.
Definition dac14.h:391
spi_master_t spi
Definition dac14.h:395
dac14_drv_t drv_sel
Definition dac14.h:399
dac14_master_io_t write_f
Definition dac14.h:401
digital_in_t int_pin
Definition dac14.h:392
i2c_master_t i2c
Definition dac14.h:394
dac14_master_io_t read_f
Definition dac14.h:402
uint8_t slave_address
Definition dac14.h:397
pin_name_t chip_select
Definition dac14.h:398