dac12 2.0.0.0
dac12.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 DAC12_H
29#define DAC12_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define DAC12_REG_NOP 0x00
75#define DAC12_REG_DEVICE_ID 0x01
76#define DAC12_REG_SYNC 0x02
77#define DAC12_REG_CONFIG 0x03
78#define DAC12_REG_GAIN 0x04
79#define DAC12_REG_TRIGGER 0x05
80#define DAC12_REG_BROADCAST 0x06
81#define DAC12_REG_STATUS 0x07
82#define DAC12_REG_DAC0 0x08
83#define DAC12_REG_DAC1 0x09
84#define DAC12_REG_DAC2 0x0A
85#define DAC12_REG_DAC3 0x0B
86#define DAC12_REG_DAC4 0x0C
87#define DAC12_REG_DAC5 0x0D
88#define DAC12_REG_DAC6 0x0E
89#define DAC12_REG_DAC7 0x0F
90
91 // dac12_reg
92
107#define DAC12_SELECT_CHANNEL_NONE 0x00
108#define DAC12_SELECT_CHANNEL_0 0x01
109#define DAC12_SELECT_CHANNEL_1 0x02
110#define DAC12_SELECT_CHANNEL_2 0x04
111#define DAC12_SELECT_CHANNEL_3 0x08
112#define DAC12_SELECT_CHANNEL_4 0x10
113#define DAC12_SELECT_CHANNEL_5 0x20
114#define DAC12_SELECT_CHANNEL_6 0x40
115#define DAC12_SELECT_CHANNEL_7 0x80
116#define DAC12_SELECT_CHANNEL_ALL 0xFF
117
122#define DAC12_GAIN_REFDIV_EN 0x0100
123
128#define DAC12_MIN_DAC_VALUE 0x0000
129#define DAC12_MAX_DAC_VALUE 0x0FFF
130
135#define DAC12_INTERNAL_VREF 2.5
136
141#define DAC12_SOFT_RESET 0x000A
142
147#define DAC12_DEVICE_ID 0x2894
148#define DAC12_DEVICE_ID_MASK 0xFFFC
149
154#define DAC12_SPI_READ 0x80
155
164#define DAC12_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
165#define DAC12_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
166
167 // dac12_set
168
183#define DAC12_MAP_MIKROBUS( cfg, mikrobus ) \
184 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
185 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
186 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
187 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
188
189 // dac12_map
190 // dac12
191
196typedef struct
197{
198 // Modules
199 spi_master_t spi;
201 pin_name_t chip_select;
203 pin_name_t channel_gain;
205} dac12_t;
206
211typedef struct
212{
213 // Communication gpio pins
214 pin_name_t miso;
215 pin_name_t mosi;
216 pin_name_t sck;
217 pin_name_t cs;
219 // static variable
220 uint32_t spi_speed;
221 spi_master_mode_t spi_mode;
222 spi_master_chip_select_polarity_t cs_polarity;
225
230typedef enum
231{
233 DAC12_ERROR = -1
234
236
253
268err_t dac12_init ( dac12_t *ctx, dac12_cfg_t *cfg );
269
284
298err_t dac12_write_register ( dac12_t *ctx, uint8_t reg, uint16_t data_in );
299
313err_t dac12_read_register ( dac12_t *ctx, uint8_t reg, uint16_t *data_out );
314
327
340
354err_t dac12_set_gain ( dac12_t *ctx, uint8_t channel );
355
369err_t dac12_set_channel_value ( dac12_t *ctx, uint8_t channel, uint16_t dac_value );
370
384err_t dac12_set_channel_voltage ( dac12_t *ctx, uint8_t channel, float voltage );
385
386#ifdef __cplusplus
387}
388#endif
389#endif // DAC12_H
390
391 // dac12
392
393// ------------------------------------------------------------------------ END
dac12_return_value_t
DAC 12 Click return value data.
Definition dac12.h:231
@ DAC12_ERROR
Definition dac12.h:233
@ DAC12_OK
Definition dac12.h:232
err_t dac12_set_channel_voltage(dac12_t *ctx, uint8_t channel, float voltage)
DAC 12 set channel voltage function.
void dac12_cfg_setup(dac12_cfg_t *cfg)
DAC 12 configuration object setup function.
err_t dac12_check_communication(dac12_t *ctx)
DAC 12 check communication function.
err_t dac12_read_register(dac12_t *ctx, uint8_t reg, uint16_t *data_out)
DAC 12 read register function.
err_t dac12_set_gain(dac12_t *ctx, uint8_t channel)
DAC 12 set gain function.
err_t dac12_default_cfg(dac12_t *ctx)
DAC 12 default configuration function.
err_t dac12_init(dac12_t *ctx, dac12_cfg_t *cfg)
DAC 12 initialization function.
err_t dac12_set_channel_value(dac12_t *ctx, uint8_t channel, uint16_t dac_value)
DAC 12 set channel value function.
err_t dac12_soft_reset(dac12_t *ctx)
DAC 12 soft reset function.
err_t dac12_write_register(dac12_t *ctx, uint8_t reg, uint16_t data_in)
DAC 12 write register function.
This file contains SPI specific macros, functions, etc.
DAC 12 Click configuration object.
Definition dac12.h:212
spi_master_chip_select_polarity_t cs_polarity
Definition dac12.h:222
pin_name_t sck
Definition dac12.h:216
spi_master_mode_t spi_mode
Definition dac12.h:221
pin_name_t mosi
Definition dac12.h:215
uint32_t spi_speed
Definition dac12.h:220
pin_name_t miso
Definition dac12.h:214
pin_name_t cs
Definition dac12.h:217
DAC 12 Click context object.
Definition dac12.h:197
spi_master_t spi
Definition dac12.h:199
pin_name_t channel_gain
Definition dac12.h:203
pin_name_t chip_select
Definition dac12.h:201