hallcurrent17 2.1.0.0
hallcurrent17.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 HALLCURRENT17_H
29#define HALLCURRENT17_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 HALLCURRENT17_ADDR_IN_CH_SEL_1 0x00
75#define HALLCURRENT17_ADDR_IN_CH_SEL_2 0x08
76
77
78 // hallcurrent17_addr
79
94#define HALLCURRENT17_RESOLUTION_12BIT 0x0FFFu
95
100#define HALLCURRENT17_VREF_3V3 3.3f
101#define HALLCURRENT17_VREF_5V 5.0f
102
107#define HALLCURRENT17_RES_R5_R7_100_KOHM 100.0f
108#define HALLCURRENT17_RES_R6_R8_100_KOHM 100.0f
109
114#define HALLCURRENT17_NUM_OF_MEASURE 1000u
115#define HALLCURRENT17_CONV_V_TO_MV 1000.0f
116
121#define HALLCURRENT17_SENSITIVITY_MV_A 40.0f
122
131#define HALLCURRENT17_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
132#define HALLCURRENT17_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
133
134 // hallcurrent17_set
135
150#define HALLCURRENT17_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
152 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
153 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
154 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
155
156 // hallcurrent17_map
157 // hallcurrent17
158
163typedef struct
164{
165 // Modules
166 spi_master_t spi;
168 pin_name_t chip_select;
170 float vref;
173
178typedef struct
179{
180 // Communication gpio pins
181 pin_name_t miso;
182 pin_name_t mosi;
183 pin_name_t sck;
184 pin_name_t cs;
186 // static variable
187 uint32_t spi_speed;
188 spi_master_mode_t spi_mode;
189 spi_master_chip_select_polarity_t cs_polarity;
192
203
220
235
249
262
276err_t hallcurrent17_get_voltage ( hallcurrent17_t *ctx, float *voltage );
277
292err_t hallcurrent17_get_vref ( hallcurrent17_t *ctx, float *adc_vref );
293
308err_t hallcurrent17_get_vout ( hallcurrent17_t *ctx, float *adc_vout );
309
323err_t hallcurrent17_get_current ( hallcurrent17_t *ctx, float *current );
324
325#ifdef __cplusplus
326}
327#endif
328#endif // HALLCURRENT17_H
329
330 // hallcurrent17
331
332// ------------------------------------------------------------------------ END
void hallcurrent17_cfg_setup(hallcurrent17_cfg_t *cfg)
Hall Current 17 configuration object setup function.
err_t hallcurrent17_get_current(hallcurrent17_t *ctx, float *current)
Hall Current 17 get current function.
void hallcurrent17_set_adc_vref(hallcurrent17_t *ctx, float vref)
Hall Current 17 set voltage reference function.
err_t hallcurrent17_get_vout(hallcurrent17_t *ctx, float *adc_vout)
Hall Current 17 get Vout function.
err_t hallcurrent17_get_vref(hallcurrent17_t *ctx, float *adc_vref)
Hall Current 17 get Vref function.
err_t hallcurrent17_get_voltage(hallcurrent17_t *ctx, float *voltage)
Hall Current 17 get voltage function.
err_t hallcurrent17_default_cfg(hallcurrent17_t *ctx)
Hall Current 17 default configuration function.
err_t hallcurrent17_init(hallcurrent17_t *ctx, hallcurrent17_cfg_t *cfg)
Hall Current 17 initialization function.
hallcurrent17_return_value_t
Hall Current 17 Click return value data.
Definition hallcurrent17.h:198
@ HALLCURRENT17_OK
Definition hallcurrent17.h:199
@ HALLCURRENT17_ERROR
Definition hallcurrent17.h:200
This file contains SPI specific macros, functions, etc.
Hall Current 17 Click configuration object.
Definition hallcurrent17.h:179
spi_master_chip_select_polarity_t cs_polarity
Definition hallcurrent17.h:189
pin_name_t sck
Definition hallcurrent17.h:183
spi_master_mode_t spi_mode
Definition hallcurrent17.h:188
pin_name_t mosi
Definition hallcurrent17.h:182
uint32_t spi_speed
Definition hallcurrent17.h:187
pin_name_t miso
Definition hallcurrent17.h:181
pin_name_t cs
Definition hallcurrent17.h:184
Hall Current 17 Click context object.
Definition hallcurrent17.h:164
spi_master_t spi
Definition hallcurrent17.h:166
float vref
Definition hallcurrent17.h:170
pin_name_t chip_select
Definition hallcurrent17.h:168