no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ad7280a.h
Go to the documentation of this file.
1/**************************************************************************/
34
35#ifndef _AD7280A_H_
36#define _AD7280A_H_
37
38
39#include <stdint.h>
40#include "no_os_delay.h"
41#include "no_os_gpio.h"
42#include "no_os_spi.h"
43
44/* GPIOs */
45#define AD7280A_PD_OUT no_os_gpio_direction_output(dev->gpio_pd, \
46 NO_OS_GPIO_HIGH)
47#define AD7280A_PD_HIGH no_os_gpio_set_value(dev->gpio_pd, \
48 NO_OS_GPIO_HIGH)
49#define AD7280A_PD_LOW no_os_gpio_set_value(dev->gpio_pd, \
50 NO_OS_GPIO_LOW)
51#define AD7280A_CNVST_OUT no_os_gpio_direction_output(dev->gpio_cnvst, \
52 NO_OS_GPIO_HIGH)
53#define AD7280A_CNVST_HIGH no_os_gpio_set_value(dev->gpio_cnvst, \
54 NO_OS_GPIO_HIGH)
55#define AD7280A_CNVST_LOW no_os_gpio_set_value(dev->gpio_cnvst, \
56 NO_OS_GPIO_LOW)
57
58#define AD7280A_ALERT_IN no_os_gpio_direction_input(dev->gpio_alert)
59#define AD7280_ALERT (1 << 6)
60
61/* Acquisition time */
62#define AD7280A_ACQ_TIME_400ns 0
63#define AD7280A_ACQ_TIME_800ns 1
64#define AD7280A_ACQ_TIME_1200ns 2
65#define AD7280A_ACQ_TIME_1600ns 3
66
67/* Conversion averaging */
68#define AD7280A_CONV_AVG_DIS 0
69#define AD7280A_CONV_AVG_2 1
70#define AD7280A_CONV_AVG_4 2
71#define AD7280A_CONV_AVG_8 3
72
73/* Alert register bits */
74#define AD7280A_ALERT_REMOVE_VIN5 (1 << 2)
75#define AD7280A_ALERT_REMOVE_VIN4_VIN5 (2 << 2)
76#define AD7280A_ALERT_REMOVE_AUX5 (1 << 0)
77#define AD7280A_ALERT_REMOVE_AUX4_AUX5 (2 << 0)
78
79/* Registers */
80#define AD7280A_CELL_VOLTAGE_1 0x0 /* D11 to D0, Read only */
81#define AD7280A_CELL_VOLTAGE_2 0x1 /* D11 to D0, Read only */
82#define AD7280A_CELL_VOLTAGE_3 0x2 /* D11 to D0, Read only */
83#define AD7280A_CELL_VOLTAGE_4 0x3 /* D11 to D0, Read only */
84#define AD7280A_CELL_VOLTAGE_5 0x4 /* D11 to D0, Read only */
85#define AD7280A_CELL_VOLTAGE_6 0x5 /* D11 to D0, Read only */
86#define AD7280A_AUX_ADC_1 0x6 /* D11 to D0, Read only */
87#define AD7280A_AUX_ADC_2 0x7 /* D11 to D0, Read only */
88#define AD7280A_AUX_ADC_3 0x8 /* D11 to D0, Read only */
89#define AD7280A_AUX_ADC_4 0x9 /* D11 to D0, Read only */
90#define AD7280A_AUX_ADC_5 0xA /* D11 to D0, Read only */
91#define AD7280A_AUX_ADC_6 0xB /* D11 to D0, Read only */
92#define AD7280A_SELF_TEST 0xC /* D11 to D0, Read only */
93#define AD7280A_CONTROL_HB 0xD /* D15 to D8, Read/write */
94#define AD7280A_CONTROL_LB 0xE /* D7 to D0, Read/write */
95#define AD7280A_CELL_OVERVOLTAGE 0xF /* D7 to D0, Read/write */
96#define AD7280A_CELL_UNDERVOLTAGE 0x10 /* D7 to D0, Read/write */
97#define AD7280A_AUX_ADC_OVERVOLTAGE 0x11 /* D7 to D0, Read/write */
98#define AD7280A_AUX_ADC_UNDERVOLTAGE 0x12 /* D7 to D0, Read/write */
99#define AD7280A_ALERT 0x13 /* D7 to D0, Read/write */
100#define AD7280A_CELL_BALANCE 0x14 /* D7 to D0, Read/write */
101#define AD7280A_CB1_TIMER 0x15 /* D7 to D0, Read/write */
102#define AD7280A_CB2_TIMER 0x16 /* D7 to D0, Read/write */
103#define AD7280A_CB3_TIMER 0x17 /* D7 to D0, Read/write */
104#define AD7280A_CB4_TIMER 0x18 /* D7 to D0, Read/write */
105#define AD7280A_CB5_TIMER 0x19 /* D7 to D0, Read/write */
106#define AD7280A_CB6_TIMER 0x1A /* D7 to D0, Read/write */
107#define AD7280A_PD_TIMER 0x1B /* D7 to D0, Read/write */
108#define AD7280A_READ 0x1C /* D7 to D0, Read/write */
109#define AD7280A_CNVST_N_CONTROL 0x1D /* D7 to D0, Read/write */
110
111/* Bits and Masks */
112#define AD7280A_CTRL_HB_CONV_INPUT_ALL (0 << 6)
113#define AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_4 (1 << 6)
114#define AD7280A_CTRL_HB_CONV_INPUT_6CELL (2 << 6)
115#define AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST (3 << 6)
116#define AD7280A_CTRL_HB_CONV_RES_READ_ALL (0 << 4)
117#define AD7280A_CTRL_HB_CONV_RES_READ_6CELL_AUX1_3_4 (1 << 4)
118#define AD7280A_CTRL_HB_CONV_RES_READ_6CELL (2 << 4)
119#define AD7280A_CTRL_HB_CONV_RES_READ_NO (3 << 4)
120#define AD7280A_CTRL_HB_CONV_START_CNVST (0 << 3)
121#define AD7280A_CTRL_HB_CONV_START_CS (1 << 3)
122#define AD7280A_CTRL_HB_CONV_AVG_DIS (0 << 1)
123#define AD7280A_CTRL_HB_CONV_AVG_2 (1 << 1)
124#define AD7280A_CTRL_HB_CONV_AVG_4 (2 << 1)
125#define AD7280A_CTRL_HB_CONV_AVG_8 (3 << 1)
126#define AD7280A_CTRL_HB_CONV_AVG(x) ((x) << 1)
127#define AD7280A_CTRL_HB_PWRDN_SW (1 << 0)
128
129#define AD7280A_CTRL_LB_SWRST (1 << 7)
130#define AD7280A_CTRL_LB_ACQ_TIME_400ns (0 << 5)
131#define AD7280A_CTRL_LB_ACQ_TIME_800ns (1 << 5)
132#define AD7280A_CTRL_LB_ACQ_TIME_1200ns (2 << 5)
133#define AD7280A_CTRL_LB_ACQ_TIME_1600ns (3 << 5)
134#define AD7280A_CTRL_LB_ACQ_TIME(x) ((x) << 5)
135#define AD7280A_CTRL_LB_MUST_SET (1 << 4)
136#define AD7280A_CTRL_LB_THERMISTOR_EN (1 << 3)
137#define AD7280A_CTRL_LB_LOCK_DEV_ADDR (1 << 2)
138#define AD7280A_CTRL_LB_INC_DEV_ADDR (1 << 1)
139#define AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN (1 << 0)
140
141#define AD7280A_ALERT_GEN_STATIC_HIGH (1 << 6)
142#define AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN (3 << 6)
143
144#define AD7280A_ALL_CELLS (0xAD << 16)
145
146#define AD7280A_DEVADDR_MASTER 0
147#define AD7280A_DEVADDR_ALL 0x1F
148
149/* Value to be sent when readings are performed */
150#define AD7280A_READ_TXVAL 0xF800030A
151
152#define NUMBITS_READ 22 // Number of bits for CRC when reading
153#define NUMBITS_WRITE 21 // Number of bits for CRC when writing
154
156 /* SPI */
158 /* GPIO */
162 /* Device Settings */
163 uint32_t read_data[24];
164 float cell_voltage[12];
165 float aux_adc[12];
166};
167
176
177/* Initializes the communication with the device. */
178int8_t ad7280a_init(struct ad7280a_dev **device,
180
181/* Free the resources allocated by AD7280A_Init(). */
182int32_t ad7280a_remove(struct ad7280a_dev *dev);
183
184/* Reads/transmits 32 data bits from/to AD7280A. */
185uint32_t ad7280a_transfer_32bits(struct ad7280a_dev *dev,
186 uint32_t data);
187
188/* Computes the CRC value for a write transmission, and prepares the complete
189 write codeword */
190uint32_t ad7280a_crc_write(uint32_t message);
191
192/* Checks the received message if the received CRC and computed CRC are
193the same. */
194int32_t ad7280a_crc_read(uint32_t message);
195
196/* Performs a read from all registers on 2 devices. */
197int8_t ad7280a_convert_read_all(struct ad7280a_dev *dev);
198
199/* Converts acquired data to float values. */
200int8_t ad7280a_convert_data_all(struct ad7280a_dev *dev);
201
202/* Reads the register content of one selected register. */
203int16_t ad7280a_read_register(struct ad7280a_dev *dev,
204 uint8_t dev_addr,
205 uint8_t read_reg);
206
207/* Reads the conversion of one channel. */
208int16_t ad7280a_read_conversion(struct ad7280a_dev *dev,
209 uint8_t dev_addr,
210 uint8_t read_reg);
211
212/* Converts the input data to a voltage value. */
213float ad7280a_convert_data(uint8_t type,
214 uint16_t data);
215
216/* Writes the content of one selected register from the selected device. */
217void ad7280a_write_register(struct ad7280a_dev *dev,
218 uint8_t dev_addr,
219 uint8_t read_reg,
220 uint8_t reg_val);
221
222/* Performs the self test for two devices(one master and one slave). */
223void ad7280a_selftest_all(struct ad7280a_dev *dev,
224 float *self_test_reg_a,
225 float *self_test_reg_b);
226
227/* Reads the value of Alert Pin from the device. */
228uint8_t ad7280a_alert_pin(struct ad7280a_dev *dev);
229
230#endif /*_AD7280A_H_*/
uint8_t ad7280a_alert_pin(struct ad7280a_dev *dev)
Definition ad7280a.c:739
uint32_t ad7280a_transfer_32bits(struct ad7280a_dev *dev, uint32_t data)
Definition ad7280a.c:136
void ad7280a_selftest_all(struct ad7280a_dev *dev, float *self_test_reg_a, float *self_test_reg_b)
Definition ad7280a.c:674
uint32_t ad7280a_crc_write(uint32_t message)
Definition ad7280a.c:169
int8_t ad7280a_convert_data_all(struct ad7280a_dev *dev)
Definition ad7280a.c:340
int32_t ad7280a_remove(struct ad7280a_dev *dev)
Free the resources allocated by AD7280A_Init().
Definition ad7280a.c:113
int16_t ad7280a_read_conversion(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg)
Definition ad7280a.c:431
int16_t ad7280a_read_register(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg)
Definition ad7280a.c:371
float ad7280a_convert_data(uint8_t type, uint16_t data)
Definition ad7280a.c:505
void ad7280a_write_register(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg, uint8_t reg_val)
Definition ad7280a.c:534
int8_t ad7280a_convert_read_all(struct ad7280a_dev *dev)
Definition ad7280a.c:276
int8_t ad7280a_init(struct ad7280a_dev **device, struct ad7280a_init_param init_param)
Definition ad7280a.c:50
int32_t ad7280a_crc_read(uint32_t message)
Definition ad7280a.c:221
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
Header file of Delay functions.
Header file of GPIO Interface.
Header file of SPI Interface.
Definition ad7280a.h:155
struct no_os_gpio_desc * gpio_pd
Definition ad7280a.h:159
uint32_t read_data[24]
Definition ad7280a.h:163
struct no_os_spi_desc * spi_desc
Definition ad7280a.h:157
float cell_voltage[12]
Definition ad7280a.h:164
struct no_os_gpio_desc * gpio_cnvst
Definition ad7280a.h:160
struct no_os_gpio_desc * gpio_alert
Definition ad7280a.h:161
float aux_adc[12]
Definition ad7280a.h:165
Definition ad7280a.h:168
struct no_os_spi_init_param spi_init
Definition ad7280a.h:170
struct no_os_gpio_init_param gpio_alert
Definition ad7280a.h:174
struct no_os_gpio_init_param gpio_pd
Definition ad7280a.h:172
struct no_os_gpio_init_param gpio_cnvst
Definition ad7280a.h:173
Definition ad9361_util.h:63
Structure holding the GPIO descriptor.
Definition no_os_gpio.h:84
Structure holding the parameters for GPIO initialization.
Definition no_os_gpio.h:67
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128