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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define DAC13_REG_INTERFACE_CONFIG_A 0x00
71 #define DAC13_REG_INTERFACE_CONFIG_B 0x01
72 #define DAC13_REG_DEVICE_CONFIG 0x02
73 #define DAC13_REG_CHIP_TYPE 0x03
74 #define DAC13_REG_PRODUCT_ID_L 0x04
75 #define DAC13_REG_PRODUCT_ID_H 0x05
76 #define DAC13_REG_CHIP_GRADE 0x06
77 #define DAC13_REG_SCRATCH_PAD 0x0A
78 #define DAC13_REG_SPI_REVISION 0x0B
79 #define DAC13_REG_VENDOR_L 0x0C
80 #define DAC13_REG_VENDOR_H 0x0D
81 #define DAC13_REG_STREAM_MODE 0x0E
82 #define DAC13_REG_TRANSFER_REGISTER 0x0F
83 #define DAC13_REG_INTERFACE_CONFIG_C 0x10
84 #define DAC13_REG_INTERFACE_STATUS_A 0x11
85 #define DAC13_REG_INTERFACE_CONFIG_D 0x14
86 #define DAC13_REG_REFERENCE_CONFIG 0x15
87 #define DAC13_REG_ERR_ALARM_MASK 0x16
88 #define DAC13_REG_ERR_STATUS 0x17
89 #define DAC13_REG_POWERDOWN_CONFIG 0x18
90 #define DAC13_REG_CH0_OUTPUT_RANGE 0x19
91 #define DAC13_REG_HW_LDAC_16B 0x28
92 #define DAC13_REG_CH0_DAC_16B 0x2A
93 #define DAC13_REG_DAC_PAGE_16B 0x2E
94 #define DAC13_REG_CH_SELECT_16B 0x2F
95 #define DAC13_REG_INPUT_PAGE_16B 0x31
96 #define DAC13_REG_SW_LDAC_16B 0x32
97 #define DAC13_REG_CH0_INPUT_16B 0x34
98 #define DAC13_REG_HW_LDAC_24B 0x37
99 #define DAC13_REG_CH0_DAC_24B 0x3A
100 #define DAC13_REG_DAC_PAGE_24B 0x40
101 #define DAC13_REG_CH_SELECT_24B 0x41
102 #define DAC13_REG_INPUT_PAGE_24B 0x44
103 #define DAC13_REG_SW_LDAC_24B 0x45
104 #define DAC13_REG_CH0_INPUT_24B 0x48
105  // dac13_reg
107 
122 #define DAC13_SPI_READ_BIT 0x80
123 
128 #define DAC13_PRODUCT_ID 0x400B
129 #define DAC13_VENDOR_ID 0x0456
130 
135 #define DAC13_IDUMP_FASTMODE 0x40
136 #define DAC13_REFERENCE_VOLTAGE_SEL_INT 0x00
137 #define DAC13_REFERENCE_VOLTAGE_SEL_INT_OUT 0x01
138 #define DAC13_REFERENCE_VOLTAGE_SEL_EXT 0x02
139 #define DAC13_REFERENCE_VOLTAGE_SEL_MASK 0x03
140 
145 #define DAC13_OUT_RANGE_0_TO_2p5V 0x00
146 #define DAC13_OUT_RANGE_0_TO_5V 0x01
147 #define DAC13_OUT_RANGE_0_TO_10V 0x02
148 #define DAC13_OUT_RANGE_NEG_5_TO_5V 0x03
149 #define DAC13_OUT_RANGE_NEG_2p5_TO_7p5V 0x04
150 
155 #define DAC13_VZS_OUT_RANGE_0_TO_2p5V ( -0.197f )
156 #define DAC13_VFS_OUT_RANGE_0_TO_2p5V ( 2.701f )
157 #define DAC13_VZS_OUT_RANGE_0_TO_5V ( -0.077f )
158 #define DAC13_VFS_OUT_RANGE_0_TO_5V ( 5.077f )
159 #define DAC13_VZS_OUT_RANGE_0_TO_10V ( -0.162f )
160 #define DAC13_VFS_OUT_RANGE_0_TO_10V ( 10.164f )
161 #define DAC13_VZS_OUT_RANGE_NEG_5_TO_5V ( -5.164f )
162 #define DAC13_VFS_OUT_RANGE_NEG_5_TO_5V ( 5.162f )
163 #define DAC13_VZS_OUT_RANGE_NEG_2p5_TO_7p5V ( -2.663f )
164 #define DAC13_VFS_OUT_RANGE_NEG_2p5_TO_7p5V ( 7.663f )
165 #define DAC13_DAC_RES_16BIT 0xFFFF
166 
175 #define DAC13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
176 #define DAC13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
177  // dac13_set
179 
194 #define DAC13_MAP_MIKROBUS( cfg, mikrobus ) \
195  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
196  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
197  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
198  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
199  cfg.ldc = MIKROBUS( mikrobus, MIKROBUS_AN ); \
200  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
201  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
202  // dac13_map // dac13
205 
210 typedef struct
211 {
212  // Output pins
213  digital_out_t ldc;
214  digital_out_t rst;
216  // Input pins
217  digital_in_t alt;
219  // Modules
220  spi_master_t spi;
222  pin_name_t chip_select;
224  float v_zero_scale;
225  float v_full_scale;
227 } dac13_t;
228 
233 typedef struct
234 {
235  // Communication gpio pins
236  pin_name_t miso;
237  pin_name_t mosi;
238  pin_name_t sck;
239  pin_name_t cs;
241  // Additional gpio pins
242  pin_name_t ldc;
243  pin_name_t rst;
244  pin_name_t alt;
246  // static variable
247  uint32_t spi_speed;
248  spi_master_mode_t spi_mode;
249  spi_master_chip_select_polarity_t cs_polarity;
251 } dac13_cfg_t;
252 
257 typedef enum
258 {
259  DAC13_OK = 0,
260  DAC13_ERROR = -1
261 
263 
280 
294 err_t dac13_init ( dac13_t *ctx, dac13_cfg_t *cfg );
295 
308 err_t dac13_default_cfg ( dac13_t *ctx );
309 
324 err_t dac13_generic_write ( dac13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
325 
340 err_t dac13_generic_read ( dac13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
341 
354 err_t dac13_write_register ( dac13_t *ctx, uint8_t reg, uint8_t data_in );
355 
368 err_t dac13_read_register ( dac13_t *ctx, uint8_t reg, uint8_t *data_out );
369 
383 err_t dac13_write_register_16b ( dac13_t *ctx, uint8_t reg, uint16_t data_in );
384 
398 err_t dac13_read_register_16b ( dac13_t *ctx, uint8_t reg, uint16_t *data_out );
399 
409 void dac13_set_ldc_pin ( dac13_t *ctx, uint8_t state );
410 
420 void dac13_set_rst_pin ( dac13_t *ctx, uint8_t state );
421 
430 uint8_t dac13_get_alert_pin ( dac13_t *ctx );
431 
441 
454 
471 err_t dac13_set_output_range ( dac13_t *ctx, uint8_t out_range );
472 
484 err_t dac13_set_dac_value ( dac13_t *ctx, uint16_t dac_value );
485 
498 err_t dac13_set_output_voltage ( dac13_t *ctx, float voltage );
499 
500 #ifdef __cplusplus
501 }
502 #endif
503 #endif // DAC13_H
504  // dac13
506 
507 // ------------------------------------------------------------------------ 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:234
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:236
dac13_t::v_full_scale
float v_full_scale
Definition: dac13.h:225
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:237
dac13_t::v_zero_scale
float v_zero_scale
Definition: dac13.h:224
dac13_t::chip_select
pin_name_t chip_select
Definition: dac13.h:222
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:248
dac13_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac13.h:247
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:260
dac13_return_value_t
dac13_return_value_t
DAC 13 Click return value data.
Definition: dac13.h:258
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:242
dac13_cfg_t::cs
pin_name_t cs
Definition: dac13.h:239
dac13_cfg_t::sck
pin_name_t sck
Definition: dac13.h:238
dac13_t::ldc
digital_out_t ldc
Definition: dac13.h:213
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:220
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:249
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:243
dac13_t::alt
digital_in_t alt
Definition: dac13.h:217
dac13_cfg_t::alt
pin_name_t alt
Definition: dac13.h:244
DAC13_OK
@ DAC13_OK
Definition: dac13.h:259
dac13_t::rst
digital_out_t rst
Definition: dac13.h:214
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:211
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.