dac13  2.1.0.0
dac13.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 DAC13_H
29 #define DAC13_H
30 
31 #ifdef __cplusplus
32 extern "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 DAC13_REG_INTERFACE_CONFIG_A 0x00
75 #define DAC13_REG_INTERFACE_CONFIG_B 0x01
76 #define DAC13_REG_DEVICE_CONFIG 0x02
77 #define DAC13_REG_CHIP_TYPE 0x03
78 #define DAC13_REG_PRODUCT_ID_L 0x04
79 #define DAC13_REG_PRODUCT_ID_H 0x05
80 #define DAC13_REG_CHIP_GRADE 0x06
81 #define DAC13_REG_SCRATCH_PAD 0x0A
82 #define DAC13_REG_SPI_REVISION 0x0B
83 #define DAC13_REG_VENDOR_L 0x0C
84 #define DAC13_REG_VENDOR_H 0x0D
85 #define DAC13_REG_STREAM_MODE 0x0E
86 #define DAC13_REG_TRANSFER_REGISTER 0x0F
87 #define DAC13_REG_INTERFACE_CONFIG_C 0x10
88 #define DAC13_REG_INTERFACE_STATUS_A 0x11
89 #define DAC13_REG_INTERFACE_CONFIG_D 0x14
90 #define DAC13_REG_REFERENCE_CONFIG 0x15
91 #define DAC13_REG_ERR_ALARM_MASK 0x16
92 #define DAC13_REG_ERR_STATUS 0x17
93 #define DAC13_REG_POWERDOWN_CONFIG 0x18
94 #define DAC13_REG_CH0_OUTPUT_RANGE 0x19
95 #define DAC13_REG_HW_LDAC_16B 0x28
96 #define DAC13_REG_CH0_DAC_16B 0x2A
97 #define DAC13_REG_DAC_PAGE_16B 0x2E
98 #define DAC13_REG_CH_SELECT_16B 0x2F
99 #define DAC13_REG_INPUT_PAGE_16B 0x31
100 #define DAC13_REG_SW_LDAC_16B 0x32
101 #define DAC13_REG_CH0_INPUT_16B 0x34
102 #define DAC13_REG_HW_LDAC_24B 0x37
103 #define DAC13_REG_CH0_DAC_24B 0x3A
104 #define DAC13_REG_DAC_PAGE_24B 0x40
105 #define DAC13_REG_CH_SELECT_24B 0x41
106 #define DAC13_REG_INPUT_PAGE_24B 0x44
107 #define DAC13_REG_SW_LDAC_24B 0x45
108 #define DAC13_REG_CH0_INPUT_24B 0x48
109  // dac13_reg
111 
126 #define DAC13_SPI_READ_BIT 0x80
127 
132 #define DAC13_PRODUCT_ID 0x400B
133 #define DAC13_VENDOR_ID 0x0456
134 
139 #define DAC13_IDUMP_FASTMODE 0x40
140 #define DAC13_REFERENCE_VOLTAGE_SEL_INT 0x00
141 #define DAC13_REFERENCE_VOLTAGE_SEL_INT_OUT 0x01
142 #define DAC13_REFERENCE_VOLTAGE_SEL_EXT 0x02
143 #define DAC13_REFERENCE_VOLTAGE_SEL_MASK 0x03
144 
149 #define DAC13_OUT_RANGE_0_TO_2p5V 0x00
150 #define DAC13_OUT_RANGE_0_TO_5V 0x01
151 #define DAC13_OUT_RANGE_0_TO_10V 0x02
152 #define DAC13_OUT_RANGE_NEG_5_TO_5V 0x03
153 #define DAC13_OUT_RANGE_NEG_2p5_TO_7p5V 0x04
154 
159 #define DAC13_VZS_OUT_RANGE_0_TO_2p5V ( -0.197f )
160 #define DAC13_VFS_OUT_RANGE_0_TO_2p5V ( 2.701f )
161 #define DAC13_VZS_OUT_RANGE_0_TO_5V ( -0.077f )
162 #define DAC13_VFS_OUT_RANGE_0_TO_5V ( 5.077f )
163 #define DAC13_VZS_OUT_RANGE_0_TO_10V ( -0.162f )
164 #define DAC13_VFS_OUT_RANGE_0_TO_10V ( 10.164f )
165 #define DAC13_VZS_OUT_RANGE_NEG_5_TO_5V ( -5.164f )
166 #define DAC13_VFS_OUT_RANGE_NEG_5_TO_5V ( 5.162f )
167 #define DAC13_VZS_OUT_RANGE_NEG_2p5_TO_7p5V ( -2.663f )
168 #define DAC13_VFS_OUT_RANGE_NEG_2p5_TO_7p5V ( 7.663f )
169 #define DAC13_DAC_RES_16BIT 0xFFFF
170 
179 #define DAC13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
180 #define DAC13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
181  // dac13_set
183 
198 #define DAC13_MAP_MIKROBUS( cfg, mikrobus ) \
199  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
200  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
201  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
202  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
203  cfg.ldc = MIKROBUS( mikrobus, MIKROBUS_AN ); \
204  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
205  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
206  // dac13_map // dac13
209 
214 typedef struct
215 {
216  // Output pins
217  digital_out_t ldc;
218  digital_out_t rst;
220  // Input pins
221  digital_in_t alt;
223  // Modules
224  spi_master_t spi;
226  pin_name_t chip_select;
228  float v_zero_scale;
229  float v_full_scale;
231 } dac13_t;
232 
237 typedef struct
238 {
239  // Communication gpio pins
240  pin_name_t miso;
241  pin_name_t mosi;
242  pin_name_t sck;
243  pin_name_t cs;
245  // Additional gpio pins
246  pin_name_t ldc;
247  pin_name_t rst;
248  pin_name_t alt;
250  // static variable
251  uint32_t spi_speed;
252  spi_master_mode_t spi_mode;
253  spi_master_chip_select_polarity_t cs_polarity;
255 } dac13_cfg_t;
256 
261 typedef enum
262 {
263  DAC13_OK = 0,
264  DAC13_ERROR = -1
265 
267 
284 
298 err_t dac13_init ( dac13_t *ctx, dac13_cfg_t *cfg );
299 
312 err_t dac13_default_cfg ( dac13_t *ctx );
313 
328 err_t dac13_generic_write ( dac13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
329 
344 err_t dac13_generic_read ( dac13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
345 
358 err_t dac13_write_register ( dac13_t *ctx, uint8_t reg, uint8_t data_in );
359 
372 err_t dac13_read_register ( dac13_t *ctx, uint8_t reg, uint8_t *data_out );
373 
387 err_t dac13_write_register_16b ( dac13_t *ctx, uint8_t reg, uint16_t data_in );
388 
402 err_t dac13_read_register_16b ( dac13_t *ctx, uint8_t reg, uint16_t *data_out );
403 
413 void dac13_set_ldc_pin ( dac13_t *ctx, uint8_t state );
414 
424 void dac13_set_rst_pin ( dac13_t *ctx, uint8_t state );
425 
434 uint8_t dac13_get_alert_pin ( dac13_t *ctx );
435 
445 
458 
475 err_t dac13_set_output_range ( dac13_t *ctx, uint8_t out_range );
476 
488 err_t dac13_set_dac_value ( dac13_t *ctx, uint16_t dac_value );
489 
502 err_t dac13_set_output_voltage ( dac13_t *ctx, float voltage );
503 
504 #ifdef __cplusplus
505 }
506 #endif
507 #endif // DAC13_H
508  // dac13
510 
511 // ------------------------------------------------------------------------ END
dac13_generic_write
err_t dac13_generic_write(dac13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DAC 13 data writing function.
dac13_cfg_t
DAC 13 Click configuration object.
Definition: dac13.h:238
dac13_check_communication
err_t dac13_check_communication(dac13_t *ctx)
DAC 13 check communication function.
dac13_cfg_t::miso
pin_name_t miso
Definition: dac13.h:240
dac13_t::v_full_scale
float v_full_scale
Definition: dac13.h:229
dac13_set_ldc_pin
void dac13_set_ldc_pin(dac13_t *ctx, uint8_t state)
DAC 13 set ldc pin function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dac13_write_register_16b
err_t dac13_write_register_16b(dac13_t *ctx, uint8_t reg, uint16_t data_in)
DAC 13 write register 16b function.
dac13_cfg_t::mosi
pin_name_t mosi
Definition: dac13.h:241
dac13_t::v_zero_scale
float v_zero_scale
Definition: dac13.h:228
dac13_t::chip_select
pin_name_t chip_select
Definition: dac13.h:226
dac13_write_register
err_t dac13_write_register(dac13_t *ctx, uint8_t reg, uint8_t data_in)
DAC 13 write register function.
dac13_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac13.h:252
dac13_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac13.h:251
dac13_set_rst_pin
void dac13_set_rst_pin(dac13_t *ctx, uint8_t state)
DAC 13 set rst pin function.
dac13_set_output_voltage
err_t dac13_set_output_voltage(dac13_t *ctx, float voltage)
DAC 13 set output voltage function.
DAC13_ERROR
@ DAC13_ERROR
Definition: dac13.h:264
dac13_return_value_t
dac13_return_value_t
DAC 13 Click return value data.
Definition: dac13.h:262
dac13_reset_device
void dac13_reset_device(dac13_t *ctx)
DAC 13 reset device function.
dac13_cfg_t::ldc
pin_name_t ldc
Definition: dac13.h:246
dac13_cfg_t::cs
pin_name_t cs
Definition: dac13.h:243
dac13_cfg_t::sck
pin_name_t sck
Definition: dac13.h:242
dac13_t::ldc
digital_out_t ldc
Definition: dac13.h:217
dac13_set_dac_value
err_t dac13_set_dac_value(dac13_t *ctx, uint16_t dac_value)
DAC 13 set dac value function.
dac13_read_register
err_t dac13_read_register(dac13_t *ctx, uint8_t reg, uint8_t *data_out)
DAC 13 read register function.
dac13_t::spi
spi_master_t spi
Definition: dac13.h:224
dac13_default_cfg
err_t dac13_default_cfg(dac13_t *ctx)
DAC 13 default configuration function.
dac13_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac13.h:253
dac13_init
err_t dac13_init(dac13_t *ctx, dac13_cfg_t *cfg)
DAC 13 initialization function.
dac13_cfg_setup
void dac13_cfg_setup(dac13_cfg_t *cfg)
DAC 13 configuration object setup function.
dac13_cfg_t::rst
pin_name_t rst
Definition: dac13.h:247
dac13_t::alt
digital_in_t alt
Definition: dac13.h:221
dac13_cfg_t::alt
pin_name_t alt
Definition: dac13.h:248
DAC13_OK
@ DAC13_OK
Definition: dac13.h:263
dac13_t::rst
digital_out_t rst
Definition: dac13.h:218
dac13_get_alert_pin
uint8_t dac13_get_alert_pin(dac13_t *ctx)
DAC 13 get alert pin function.
dac13_generic_read
err_t dac13_generic_read(dac13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DAC 13 data reading function.
dac13_t
DAC 13 Click context object.
Definition: dac13.h:215
dac13_set_output_range
err_t dac13_set_output_range(dac13_t *ctx, uint8_t out_range)
DAC 13 set output range function.
dac13_read_register_16b
err_t dac13_read_register_16b(dac13_t *ctx, uint8_t reg, uint16_t *data_out)
DAC 13 read register 16b function.