dac15 2.1.0.0
dac15.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 DAC15_H
29#define DAC15_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 DAC15_REG_NOOP 0x00
76#define DAC15_REG_DEVID 0x01
77#define DAC15_REG_SYNC 0x02
78#define DAC15_REG_CONFIG 0x03
79#define DAC15_REG_GAIN 0x04
80#define DAC15_REG_TRIGGER 0x05
81#define DAC15_REG_BRDCAST 0x06
82#define DAC15_REG_STATUS 0x07
83#define DAC15_REG_DAC_A_DATA 0x08
84#define DAC15_REG_DAC_B_DATA 0x09
85
86 // dac15_reg
87
102#define DAC15_DEVICE_ID 0x0295u
103
108#define DAC15_SYNC_DAC_B_BRDCAST_DIS 0x0000u
109#define DAC15_SYNC_DAC_B_BRDCAST_EN 0x0100u
110#define DAC15_SYNC_DAC_A_BRDCAST_DIS 0x0000u
111#define DAC15_SYNC_DAC_A_BRDCAST_EN 0x0080u
112#define DAC15_SYNC_DAC_B_SYNC_DIS 0x0000u
113#define DAC15_SYNC_DAC_B_SYNC_EN 0x0002u
114#define DAC15_SYNC_DAC_A_SYNC_DIS 0x0000u
115#define DAC15_SYNC_DAC_A_SYNC_EN 0x0001u
116
121#define DAC15_CONFIG_REF_PWUP 0x0000u
122#define DAC15_CONFIG_REF_PWDWN 0x0100u
123#define DAC15_CONFIG_DAC_B_PWUP 0x0000u
124#define DAC15_CONFIG_DAC_B_PWDWN 0x0002u
125#define DAC15_CONFIG_DAC_A_PWUP 0x0000u
126#define DAC15_CONFIG_DAC_A_PWDWN 0x0001u
127
132#define DAC15_GAIN_REF_DIV_1 0x0000u
133#define DAC15_GAIN_REF_DIV_2 0x0100u
134#define DAC15_GAIN_BUFF_B_GAIN_1 0x0000u
135#define DAC15_GAIN_BUFF_B_GAIN_2 0x0002u
136#define DAC15_GAIN_BUFF_A_GAIN_1 0x0000u
137#define DAC15_GAIN_BUFF_A_GAIN_2 0x0001u
138
143#define DAC15_TRIGGER_LDA_SYNC_LOAD_DAC 0x0010u
144#define DAC15_TRIGGER_SOFT_RESET 0x000Au
145
150#define DAC15_SET_DAC_A 0
151#define DAC15_SET_DAC_B 1
152
157#define DAC15_DAC_RES_16BIT 0xFFFFu
158#define DAC15_MAX_DAC_DATA 65535.0f
159#define DAC15_MAX_VOUT_MV 3300.0f
160#define DAC15_VREF_3V3 3.3f
161#define DAC15_VREF_5V 5.0f
162#define DAC15_CONV_DEV_MV_TO_V 1000.0f
163
164
170#define DAC15_DEVICE_ADDRESS_GND 0x48
171#define DAC15_DEVICE_ADDRESS_VCC 0x49
172
181#define DAC15_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
182#define DAC15_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
183
184 // dac15_set
185
200#define DAC15_MAP_MIKROBUS( cfg, mikrobus ) \
201 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
202 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
203 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
204 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
205 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
206 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
207 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
208
209 // dac15_map
210 // dac15
211
222
227typedef err_t ( *dac15_master_io_t )( struct dac15_s*, uint8_t, uint8_t*, uint8_t );
233typedef struct dac15_s
234{
235 digital_out_t rst;
237 i2c_master_t i2c;
238 spi_master_t spi;
241 pin_name_t chip_select;
247 float vref;
250
255typedef struct
256{
257 pin_name_t scl;
258 pin_name_t sda;
259 pin_name_t miso;
260 pin_name_t mosi;
261 pin_name_t sck;
262 pin_name_t cs;
263 pin_name_t rst;
265 uint32_t i2c_speed;
266 uint8_t i2c_address;
268 uint32_t spi_speed;
269 spi_master_mode_t spi_mode;
270 spi_master_chip_select_polarity_t cs_polarity;
273 float vref;
276
281typedef enum
282{
284 DAC15_ERROR = -1
285
287
304
320
334err_t dac15_init ( dac15_t *ctx, dac15_cfg_t *cfg );
335
349
364err_t dac15_generic_write ( dac15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
365
380err_t dac15_generic_read ( dac15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
381
396err_t dac15_write_reg ( dac15_t *ctx, uint8_t reg, uint16_t data_in );
397
412err_t dac15_read_reg ( dac15_t *ctx, uint8_t reg, uint16_t *data_out );
413
425
437
451err_t dac15_get_device_id ( dac15_t *ctx, uint16_t *device_id );
452
466
480
497err_t dac15_set_dac_data ( dac15_t *ctx, uint8_t dac_sel, uint16_t dac_data );
498
515err_t dac15_get_dac_data ( dac15_t *ctx, uint8_t dac_sel, uint16_t *dac_data );
516
533err_t dac15_set_dac_vout ( dac15_t *ctx, uint8_t dac_sel, float vtg );
534
551err_t dac15_get_dac_vout ( dac15_t *ctx, uint8_t dac_sel, float *vtg );
552
553#ifdef __cplusplus
554}
555#endif
556#endif // DAC15_H
557
558 // dac15
559
560// ------------------------------------------------------------------------ END
dac15_return_value_t
DAC 15 Click return value data.
Definition dac15.h:282
@ DAC15_OK
Definition dac15.h:283
@ DAC15_ERROR
Definition dac15.h:284
dac15_drv_t
DAC 15 Click driver selector.
Definition dac15.h:217
@ DAC15_DRV_SEL_SPI
Definition dac15.h:218
@ DAC15_DRV_SEL_I2C
Definition dac15.h:219
err_t(* dac15_master_io_t)(struct dac15_s *, uint8_t, uint8_t *, uint8_t)
DAC 15 Click driver interface.
Definition dac15.h:227
struct dac15_s dac15_t
DAC 15 Click context object.
err_t dac15_get_dac_data(dac15_t *ctx, uint8_t dac_sel, uint16_t *dac_data)
DAC 15 get DAC data function.
err_t dac15_soft_reset(dac15_t *ctx)
DAC 15 soft reset function.
void dac15_drv_interface_selection(dac15_cfg_t *cfg, dac15_drv_t drv_sel)
DAC 15 driver interface setup function.
void dac15_cfg_setup(dac15_cfg_t *cfg)
DAC 15 configuration object setup function.
err_t dac15_write_reg(dac15_t *ctx, uint8_t reg, uint16_t data_in)
DAC 15 write register function.
err_t dac15_set_dac_vout(dac15_t *ctx, uint8_t dac_sel, float vtg)
DAC 15 set DAC output voltage function.
err_t dac15_set_dac_data(dac15_t *ctx, uint8_t dac_sel, uint16_t dac_data)
DAC 15 set DAC data function.
err_t dac15_get_device_id(dac15_t *ctx, uint16_t *device_id)
DAC 15 get device ID function.
err_t dac15_read_reg(dac15_t *ctx, uint8_t reg, uint16_t *data_out)
DAC 15 read register function.
err_t dac15_generic_write(dac15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DAC 15 data writing function.
err_t dac15_default_cfg(dac15_t *ctx)
DAC 15 default configuration function.
err_t dac15_get_dac_vout(dac15_t *ctx, uint8_t dac_sel, float *vtg)
DAC 15 get DAC output voltage function.
err_t dac15_init(dac15_t *ctx, dac15_cfg_t *cfg)
DAC 15 initialization function.
err_t dac15_generic_read(dac15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DAC 15 data reading function.
void dac15_power_up_to_midscale(dac15_t *ctx)
DAC 15 DACs s power up to midscale function.
err_t dac15_set_sync_mode(dac15_t *ctx)
DAC 15 set sync mode function.
void dac15_power_up_to_zero_scale(dac15_t *ctx)
DAC 15 DACs power up to zero scale function.
This file contains SPI specific macros, functions, etc.
DAC 15 Click configuration object.
Definition dac15.h:256
float vref
Definition dac15.h:273
dac15_drv_t drv_sel
Definition dac15.h:272
uint32_t i2c_speed
Definition dac15.h:265
spi_master_chip_select_polarity_t cs_polarity
Definition dac15.h:270
pin_name_t sck
Definition dac15.h:261
spi_master_mode_t spi_mode
Definition dac15.h:269
pin_name_t mosi
Definition dac15.h:260
uint32_t spi_speed
Definition dac15.h:268
pin_name_t scl
Definition dac15.h:257
pin_name_t miso
Definition dac15.h:259
pin_name_t sda
Definition dac15.h:258
pin_name_t rst
Definition dac15.h:263
pin_name_t cs
Definition dac15.h:262
uint8_t i2c_address
Definition dac15.h:266
DAC 15 Click context object.
Definition dac15.h:234
spi_master_t spi
Definition dac15.h:238
dac15_master_io_t read_f
Definition dac15.h:245
float vref
Definition dac15.h:247
dac15_drv_t drv_sel
Definition dac15.h:242
dac15_master_io_t write_f
Definition dac15.h:244
i2c_master_t i2c
Definition dac15.h:237
digital_out_t rst
Definition dac15.h:235
uint8_t slave_address
Definition dac15.h:240
pin_name_t chip_select
Definition dac15.h:241