isoadc5  2.0.0.0
isoadc5.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 ISOADC5_H
29 #define ISOADC5_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 
69 #define ISOADC5_REG_PROD_ID 0x00
70 #define ISOADC5_REG_ADC_1 0x01
71 #define ISOADC5_REG_ADC_2 0x02
72 #define ISOADC5_REG_ADC_3 0x03
73 #define ISOADC5_REG_ADC_4 0x04
74 #define ISOADC5_REG_FADC_1 0x05
75 #define ISOADC5_REG_FADC_2 0x06
76 #define ISOADC5_REG_FADC_3 0x07
77 #define ISOADC5_REG_FADC_4 0x08
78 #define ISOADC5_REG_COUNTHI_1 0x09
79 #define ISOADC5_REG_COUNTHI_2 0x0A
80 #define ISOADC5_REG_COUNTHI_3 0x0B
81 #define ISOADC5_REG_COUNTHI_4 0x0C
82 #define ISOADC5_REG_COUNTLO_1 0x0D
83 #define ISOADC5_REG_COUNTLO_2 0x0E
84 #define ISOADC5_REG_COUNTLO_3 0x0F
85 #define ISOADC5_REG_COUNTLO_4 0x10
86 #define ISOADC5_REG_COUT_STATUS 0x11
87 #define ISOADC5_REG_INTERRUPT_STATUS 0x12
88 #define ISOADC5_REG_INTERRUPT_ENABLE 0x13
89 #define ISOADC5_REG_CONTROL 0x14
90  // isoadc5_reg
92 
107 #define ISOADC5_DEVICE_ID 0x00
108 #define ISOADC5_NORMAL_OPERATION 0x00
109 #define ISOADC5_WAKE_UP_FROM_POR 0x80
110 #define ISOADC5_DEVICE_REV 0x01
111 
116 #define ISOADC5_ADC_NOT_UPDATED 0x8000
117 #define ISOADC5_ADC_12BIT_MASK 0x0FFF
118 
123 #define ISOADC5_CO_MODE_STATUS 0x80
124 #define ISOADC5_CO_IN_SEL_FILTERED_ADC 0x40
125 
130 #define ISOADC5_STATUS_CO_4 0x08
131 #define ISOADC5_STATUS_CO_3 0x04
132 #define ISOADC5_STATUS_CO_2 0x02
133 #define ISOADC5_STATUS_CO_1 0x01
134 
139 #define ISOADC5_INT_STATUS_EOC 0x1000
140 #define ISOADC5_INT_STATUS_ADCF 0x0800
141 #define ISOADC5_INT_STATUS_FLD 0x0400
142 #define ISOADC5_INT_STATUS_SPIFRM 0x0200
143 #define ISOADC5_INT_STATUS_SPICRC 0x0100
144 #define ISOADC5_INT_STATUS_CO_POS_4 0x0080
145 #define ISOADC5_INT_STATUS_CO_POS_3 0x0040
146 #define ISOADC5_INT_STATUS_CO_POS_2 0x0020
147 #define ISOADC5_INT_STATUS_CO_POS_1 0x0010
148 #define ISOADC5_INT_STATUS_CO_NEG_4 0x0008
149 #define ISOADC5_INT_STATUS_CO_NEG_3 0x0004
150 #define ISOADC5_INT_STATUS_CO_NEG_2 0x0002
151 #define ISOADC5_INT_STATUS_CO_NEG_1 0x0001
152 
157 #define ISOADC5_EN_CRC 0x8000
158 #define ISOADC5_EN_COMMON_COMP 0x4000
159 #define ISOADC5_CLEAR_FLT_4 0x0080
160 #define ISOADC5_CLEAR_FLT_3 0x0040
161 #define ISOADC5_CLEAR_FLT_2 0x0020
162 #define ISOADC5_CLEAR_FLT_1 0x0010
163 #define ISOADC5_DISABLE_PWR 0x0008
164 #define ISOADC5_CLEAR_POR 0x0004
165 #define ISOADC5_SOFT_RESET 0x0002
166 #define ISOADC5_HARD_RESET 0x0001
167 
172 #define ISOADC5_ADC_CHANNEL_1 0x01
173 #define ISOADC5_ADC_CHANNEL_2 0x02
174 #define ISOADC5_ADC_CHANNEL_3 0x03
175 #define ISOADC5_ADC_CHANNEL_4 0x04
176 
181 #define ISOADC5_ADC_UNFILTERED 0x00
182 #define ISOADC5_ADC_FILTERED 0x01
183 
188 #define ISOADC5_MAX_VOLTAGE 48.0
189 
194 #define ISOADC5_SPI_READ 0x00
195 #define ISOADC5_SPI_WRITE 0x02
196 #define ISOADC5_SPI_BURST 0x01
197  // isoadc5_set
199 
214 #define ISOADC5_MAP_MIKROBUS( cfg, mikrobus ) \
215  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
216  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
217  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
218  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
219  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
220  // isoadc5_map // isoadc5
223 
228 typedef struct
229 {
230  digital_in_t int_pin;
232  // Modules
233  spi_master_t spi;
235  pin_name_t chip_select;
237 } isoadc5_t;
238 
243 typedef struct
244 {
245  // Communication gpio pins
246  pin_name_t miso;
247  pin_name_t mosi;
248  pin_name_t sck;
249  pin_name_t cs;
251  // Additional gpio pins
252  pin_name_t int_pin;
254  // static variable
255  uint32_t spi_speed;
256  spi_master_mode_t spi_mode;
257  spi_master_chip_select_polarity_t cs_polarity;
259 } isoadc5_cfg_t;
260 
265 typedef struct
266 {
267  uint16_t adc_1;
268  uint16_t adc_2;
269  uint16_t adc_3;
270  uint16_t adc_4;
271  uint16_t int_status;
272 
274 
279 typedef enum
280 {
282  ISOADC5_ERROR = -1
283 
285 
302 
316 err_t isoadc5_init ( isoadc5_t *ctx, isoadc5_cfg_t *cfg );
317 
331 err_t isoadc5_write_register ( isoadc5_t *ctx, uint8_t reg, uint16_t data_in );
332 
346 err_t isoadc5_read_register ( isoadc5_t *ctx, uint8_t reg, uint16_t *data_out );
347 
363 err_t isoadc5_read_register_burst ( isoadc5_t *ctx, uint8_t filt, isoadc5_burst_payload_t *payload );
364 
379 err_t isoadc5_read_voltage( isoadc5_t *ctx, uint8_t filt, uint8_t ch, float *volt );
380 
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 #endif // ISOADC5_H
395  // isoadc5
397 
398 // ------------------------------------------------------------------------ END
ISOADC5_ERROR
@ ISOADC5_ERROR
Definition: isoadc5.h:282
isoadc5_cfg_t::spi_speed
uint32_t spi_speed
Definition: isoadc5.h:255
isoadc5_write_register
err_t isoadc5_write_register(isoadc5_t *ctx, uint8_t reg, uint16_t data_in)
ISO ADC 5 write register function.
isoadc5_cfg_t::miso
pin_name_t miso
Definition: isoadc5.h:246
isoadc5_return_value_t
isoadc5_return_value_t
ISO ADC 5 Click return value data.
Definition: isoadc5.h:280
isoadc5_cfg_t::cs
pin_name_t cs
Definition: isoadc5.h:249
isoadc5_burst_payload_t::adc_2
uint16_t adc_2
Definition: isoadc5.h:268
isoadc5_burst_payload_t
ISO ADC 5 Click burst payload structure object.
Definition: isoadc5.h:266
isoadc5_burst_payload_t::adc_1
uint16_t adc_1
Definition: isoadc5.h:267
isoadc5_t
ISO ADC 5 Click context object.
Definition: isoadc5.h:229
isoadc5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: isoadc5.h:256
isoadc5_cfg_t::sck
pin_name_t sck
Definition: isoadc5.h:248
isoadc5_burst_payload_t::adc_3
uint16_t adc_3
Definition: isoadc5.h:269
isoadc5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: isoadc5.h:257
isoadc5_init
err_t isoadc5_init(isoadc5_t *ctx, isoadc5_cfg_t *cfg)
ISO ADC 5 initialization function.
isoadc5_t::int_pin
digital_in_t int_pin
Definition: isoadc5.h:230
isoadc5_cfg_t::mosi
pin_name_t mosi
Definition: isoadc5.h:247
isoadc5_cfg_t
ISO ADC 5 Click configuration object.
Definition: isoadc5.h:244
isoadc5_burst_payload_t::adc_4
uint16_t adc_4
Definition: isoadc5.h:270
isoadc5_burst_payload_t::int_status
uint16_t int_status
Definition: isoadc5.h:271
ISOADC5_OK
@ ISOADC5_OK
Definition: isoadc5.h:281
isoadc5_read_register
err_t isoadc5_read_register(isoadc5_t *ctx, uint8_t reg, uint16_t *data_out)
ISO ADC 5 read register function.
isoadc5_get_int_pin
uint8_t isoadc5_get_int_pin(isoadc5_t *ctx)
ISO ADC 5 get int pin function.
isoadc5_read_voltage
err_t isoadc5_read_voltage(isoadc5_t *ctx, uint8_t filt, uint8_t ch, float *volt)
ISO ADC 5 read voltage function.
isoadc5_cfg_t::int_pin
pin_name_t int_pin
Definition: isoadc5.h:252
isoadc5_cfg_setup
void isoadc5_cfg_setup(isoadc5_cfg_t *cfg)
ISO ADC 5 configuration object setup function.
isoadc5_read_register_burst
err_t isoadc5_read_register_burst(isoadc5_t *ctx, uint8_t filt, isoadc5_burst_payload_t *payload)
ISO ADC 5 read register function.
isoadc5_t::chip_select
pin_name_t chip_select
Definition: isoadc5.h:235
isoadc5_t::spi
spi_master_t spi
Definition: isoadc5.h:233