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
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 HALLCURRENT17_ADDR_IN_CH_SEL_1 0x00
71 #define HALLCURRENT17_ADDR_IN_CH_SEL_2 0x08
72 
73  // hallcurrent17_addr
75 
90 #define HALLCURRENT17_RESOLUTION_12BIT 0x0FFFu
91 
96 #define HALLCURRENT17_VREF_3V3 3.3f
97 #define HALLCURRENT17_VREF_5V 5.0f
98 
103 #define HALLCURRENT17_RES_R5_R7_100_KOHM 100.0f
104 #define HALLCURRENT17_RES_R6_R8_100_KOHM 100.0f
105 
110 #define HALLCURRENT17_NUM_OF_MEASURE 1000u
111 #define HALLCURRENT17_CONV_V_TO_MV 1000.0f
112 
117 #define HALLCURRENT17_SENSITIVITY_MV_A 40.0f
118 
127 #define HALLCURRENT17_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
128 #define HALLCURRENT17_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
129  // hallcurrent17_set
131 
146 #define HALLCURRENT17_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
148  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
149  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
150  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
151  // hallcurrent17_map // hallcurrent17
154 
159 typedef struct
160 {
161  // Modules
162  spi_master_t spi;
164  pin_name_t chip_select;
166  float vref;
169 
174 typedef struct
175 {
176  // Communication gpio pins
177  pin_name_t miso;
178  pin_name_t mosi;
179  pin_name_t sck;
180  pin_name_t cs;
182  // static variable
183  uint32_t spi_speed;
184  spi_master_mode_t spi_mode;
185  spi_master_chip_select_polarity_t cs_polarity;
188 
193 typedef enum
194 {
197 
199 
216 
231 
245 
257 void hallcurrent17_set_adc_vref ( hallcurrent17_t *ctx, float vref );
258 
272 err_t hallcurrent17_get_voltage ( hallcurrent17_t *ctx, float *voltage );
273 
288 err_t hallcurrent17_get_vref ( hallcurrent17_t *ctx, float *adc_vref );
289 
304 err_t hallcurrent17_get_vout ( hallcurrent17_t *ctx, float *adc_vout );
305 
319 err_t hallcurrent17_get_current ( hallcurrent17_t *ctx, float *current );
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 #endif // HALLCURRENT17_H
325  // hallcurrent17
327 
328 // ------------------------------------------------------------------------ END
hallcurrent17_return_value_t
hallcurrent17_return_value_t
Hall Current 17 Click return value data.
Definition: hallcurrent17.h:194
hallcurrent17_get_vout
err_t hallcurrent17_get_vout(hallcurrent17_t *ctx, float *adc_vout)
Hall Current 17 get Vout function.
hallcurrent17_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent17.h:184
hallcurrent17_get_vref
err_t hallcurrent17_get_vref(hallcurrent17_t *ctx, float *adc_vref)
Hall Current 17 get Vref function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hallcurrent17_cfg_t::mosi
pin_name_t mosi
Definition: hallcurrent17.h:178
hallcurrent17_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent17.h:185
hallcurrent17_cfg_t
Hall Current 17 Click configuration object.
Definition: hallcurrent17.h:175
hallcurrent17_cfg_t::miso
pin_name_t miso
Definition: hallcurrent17.h:177
hallcurrent17_t::vref
float vref
Definition: hallcurrent17.h:166
hallcurrent17_default_cfg
err_t hallcurrent17_default_cfg(hallcurrent17_t *ctx)
Hall Current 17 default configuration function.
hallcurrent17_init
err_t hallcurrent17_init(hallcurrent17_t *ctx, hallcurrent17_cfg_t *cfg)
Hall Current 17 initialization function.
hallcurrent17_get_current
err_t hallcurrent17_get_current(hallcurrent17_t *ctx, float *current)
Hall Current 17 get current function.
hallcurrent17_set_adc_vref
void hallcurrent17_set_adc_vref(hallcurrent17_t *ctx, float vref)
Hall Current 17 set voltage reference function.
HALLCURRENT17_OK
@ HALLCURRENT17_OK
Definition: hallcurrent17.h:195
hallcurrent17_cfg_t::sck
pin_name_t sck
Definition: hallcurrent17.h:179
hallcurrent17_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent17.h:183
hallcurrent17_get_voltage
err_t hallcurrent17_get_voltage(hallcurrent17_t *ctx, float *voltage)
Hall Current 17 get voltage function.
hallcurrent17_cfg_t::cs
pin_name_t cs
Definition: hallcurrent17.h:180
hallcurrent17_t::spi
spi_master_t spi
Definition: hallcurrent17.h:162
hallcurrent17_t
Hall Current 17 Click context object.
Definition: hallcurrent17.h:160
HALLCURRENT17_ERROR
@ HALLCURRENT17_ERROR
Definition: hallcurrent17.h:196
hallcurrent17_t::chip_select
pin_name_t chip_select
Definition: hallcurrent17.h:164
hallcurrent17_cfg_setup
void hallcurrent17_cfg_setup(hallcurrent17_cfg_t *cfg)
Hall Current 17 configuration object setup function.