daq3 2.0.0.0
daq3.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 DAQ3_H
29#define DAQ3_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
73#define DAQ3_REG_0 0x00
74#define DAQ3_REG_1 0x01
75#define DAQ3_REG_2 0x02
76#define DAQ3_REG_3 0x03
77#define DAQ3_REG_CMD 0x14
78
79 // daq3_reg
80
95#define DAQ3_CMD_WEN 0x00
96#define DAQ3_CMD_REG_READ 0x40
97#define DAQ3_CMD_REG_WRITE 0x00
98
99 // daq3_set
100
110#define DAQ3_CMD_REG_DEFAULT 0xE1
111
112 // daq3_set
113
124#define DAQ3_LOW_POWER_MODE 0x00
125#define DAQ3_FULL_PERFORMANCE_MODE 0x01
126
127 // mode
128
139#define DAQ3_PD_REF_POWER_DOWN 0x00
140#define DAQ3_PD_REF_POWER_UP 0x01
141
142 // pd_ref
143
154#define DAQ3_PD_AMP_POWER_DOWN 0x00
155#define DAQ3_PD_AMP_POWER_UP 0x01
156
157 // pd_amp
158
173#define DAQ3_MAP_MIKROBUS( cfg, mikrobus ) \
174 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
175 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
176 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
177 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
178 cfg.dam = MIKROBUS( mikrobus, MIKROBUS_AN ); \
179 cfg.dre = MIKROBUS( mikrobus, MIKROBUS_RST ); \
180 cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
181 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
182
183 // daq3_map
184 // daq3
185
190typedef struct
191{
192 // Output pins
193
194 digital_out_t dam;
195 digital_out_t dre;
196 digital_out_t mod;
198 // Input pins
199
200 digital_in_t int_pin;
202 // Modules
203
204 spi_master_t spi;
206 pin_name_t chip_select;
208} daq3_t;
209
214typedef struct
215{
217 uint8_t span_comp;
218 uint8_t high_z_mode;
219 uint8_t turbo_mode;
223
228typedef struct
229{
230 // Communication gpio pins
231
232 pin_name_t miso;
233 pin_name_t mosi;
234 pin_name_t sck;
235 pin_name_t cs;
237 // Additional gpio pins
238
239 pin_name_t dam;
240 pin_name_t dre;
241 pin_name_t mod;
242 pin_name_t int_pin;
244 // static variable
245
246 uint32_t spi_speed;
247 spi_master_mode_t spi_mode;
248 spi_master_chip_select_polarity_t cs_polarity;
250} daq3_cfg_t;
251
268
283err_t daq3_init ( daq3_t *ctx, daq3_cfg_t *cfg );
284
296
311void daq3_set_pwr_mode ( daq3_t *ctx, uint8_t mode );
312
327void daq3_set_pwr_down_ref_buf ( daq3_t *ctx, uint8_t pd_ref );
328
343void daq3_set_pwr_down_amp ( daq3_t *ctx, uint8_t pd_amp );
344
345
359uint8_t daq3_get_sdo ( daq3_t *ctx );
360
375err_t daq3_generic_write ( daq3_t *ctx, uint8_t reg, uint8_t data_in );
376
391err_t daq3_generic_read ( daq3_t *ctx, uint8_t reg, uint8_t *data_out );
392
407err_t daq3_set_reg_cfg ( daq3_t *ctx, daq3_reg_cfg_t cfg_data );
408
423err_t daq3_get_reg_cfg ( daq3_t *ctx, daq3_reg_cfg_t *cfg_data );
424
439
454
455#ifdef __cplusplus
456}
457#endif
458#endif // DAQ3_H
459
460 // daq3
461
462// ------------------------------------------------------------------------ END
void daq3_set_pwr_mode(daq3_t *ctx, uint8_t mode)
DAQ 3 set power mode function.
err_t daq3_init(daq3_t *ctx, daq3_cfg_t *cfg)
DAQ 3 initialization function.
err_t daq3_generic_read(daq3_t *ctx, uint8_t reg, uint8_t *data_out)
DAQ 3 data reading function.
uint8_t daq3_get_sdo(daq3_t *ctx)
DAQ 3 get state of SDO function.
float daq3_get_voltage(daq3_t *ctx)
DAQ 3 get voltage function.
void daq3_default_cfg(daq3_t *ctx)
DAQ 3 default configuration function.
void daq3_set_pwr_down_amp(daq3_t *ctx, uint8_t pd_amp)
DAQ 3 set power Amplifier function.
void daq3_cfg_setup(daq3_cfg_t *cfg)
DAQ 3 configuration object setup function.
err_t daq3_generic_write(daq3_t *ctx, uint8_t reg, uint8_t data_in)
DAQ 3 data writing function.
int32_t daq3_get_conversion_result(daq3_t *ctx, daq3_reg_cfg_t cfg_data)
DAQ 3 get conversion result function.
err_t daq3_set_reg_cfg(daq3_t *ctx, daq3_reg_cfg_t cfg_data)
DAQ 3 set command register function.
err_t daq3_get_reg_cfg(daq3_t *ctx, daq3_reg_cfg_t *cfg_data)
DAQ 3 get command register function.
void daq3_set_pwr_down_ref_buf(daq3_t *ctx, uint8_t pd_ref)
DAQ 3 set power reference buffer function.
DAQ 3 Click configuration object.
Definition daq3.h:229
pin_name_t dam
Definition daq3.h:239
spi_master_chip_select_polarity_t cs_polarity
Definition daq3.h:248
pin_name_t sck
Definition daq3.h:234
spi_master_mode_t spi_mode
Definition daq3.h:247
pin_name_t mod
Definition daq3.h:241
pin_name_t mosi
Definition daq3.h:233
uint32_t spi_speed
Definition daq3.h:246
pin_name_t dre
Definition daq3.h:240
pin_name_t int_pin
Definition daq3.h:242
pin_name_t miso
Definition daq3.h:232
pin_name_t cs
Definition daq3.h:235
DAQ 3 Click configuration object.
Definition daq3.h:215
uint8_t span_comp
Definition daq3.h:217
uint8_t ov_clamp_flag
Definition daq3.h:220
uint8_t turbo_mode
Definition daq3.h:219
uint8_t en_six_st_bits
Definition daq3.h:216
uint8_t high_z_mode
Definition daq3.h:218
DAQ 3 Click context object.
Definition daq3.h:191
digital_out_t mod
Definition daq3.h:196
digital_out_t dre
Definition daq3.h:195
spi_master_t spi
Definition daq3.h:204
digital_out_t dam
Definition daq3.h:194
digital_in_t int_pin
Definition daq3.h:200
pin_name_t chip_select
Definition daq3.h:206