no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ad7799.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef AD7799_H_
34#define AD7799_H_
35
36#include <stdint.h>
37#include <stdbool.h>
38#include "no_os_spi.h"
39
40/*AD7799 Registers*/
41#define AD7799_REG_COMM 0x0 /* Communications Register(WO, 8-bit) */
42#define AD7799_REG_STAT 0x0 /* Status Register (RO, 8-bit) */
43#define AD7799_REG_MODE 0x1 /* Mode Register (RW, 16-bit) */
44#define AD7799_REG_CONF 0x2 /* Configuration Register (RW, 16-bit)*/
45#define AD7799_REG_DATA 0x3 /* Data Register (RO, 16-/24-bit) */
46#define AD7799_REG_ID 0x4 /* ID Register (RO, 8-bit) */
47#define AD7799_REG_IO 0x5 /* IO Register (RO, 8-bit) */
48#define AD7799_REG_OFFSET 0x6 /* Offset Register (RW, 24-bit) */
49#define AD7799_REG_FULLSCALE 0x7 /* Full-Scale Register (RW, 24-bit) */
50
51/* AD7799 Polarity */
52#define AD7799_BIPOLAR 0x0 /* Bipolar bit */
53#define AD7799_UNIPOLAR 0x1 /* Unipolar bit */
54
55/* Communications Register Bit Designations (AD7799_REG_COMM) */
56#define AD7799_COMM_WEN 0x80 /* Write Enable */
57#define AD7799_COMM_WRITE 0x00 /* Write Operation */
58#define AD7799_COMM_READ 0x40 /* Read Operation */
59#define AD7799_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */
60#define AD7799_COMM_CREAD 0x04 /* Continuous Read */
61
62/* Status Register Bit Designations (AD7799_REG_STAT) */
63#define AD7799_STAT_RDY 0x80 /* Ready */
64#define AD7799_STAT_ERR 0x40 /* Error (Overrange, Underrange) */
65#define AD7799_STAT_CH3 0x04 /* Channel 3 */
66#define AD7799_STAT_CH2 (1 << 1) /* Channel 2 */
67#define AD7799_STAT_CH1 (1 << 0) /* Channel 1 */
68
69/* Mode Register Bit Designations (AD7799_REG_MODE) */
70#define AD7799_MODE_SEL(x) (((x) & 0x7) << 13) /* Operation Mode Select */
71#define AD7799_MODE_PSW(x) 0x1000 /* Power Switch Control Bit */
72#define AD7799_MODE_RATE(x) ((x) & 0xF) /* Filter Update Rate */
73
74/* AD7799_MODE_SEL(x) options */
75#define AD7799_MODE_CONT 0x0 /* Continuous Conversion Mode */
76#define AD7799_MODE_SINGLE 0x1 /* Single Conversion Mode */
77#define AD7799_MODE_IDLE 0x2 /* Idle Mode */
78#define AD7799_MODE_PWRDN 0x3 /* Power-Down Mode */
79#define AD7799_MODE_CAL_INT_ZERO 0x4 /* Internal Zero-Scale Calibration */
80#define AD7799_MODE_CAL_INT_FULL 0x5 /* Internal Full-Scale Calibration */
81#define AD7799_MODE_CAL_SYS_ZERO 0x6 /* System Zero-Scale Calibration */
82#define AD7799_MODE_CAL_SYS_FULL 0x7 /* System Full-Scale Calibration */
83
84/* Configuration Register Bit Designations (AD7799_REG_CONF) */
85#define AD7799_CONF_BO_EN 0x2000 /* Burnout Current */
86#define AD7799_CONF_POLARITY(x) (((x) & 0x1) << 12) /* Unipolar/Bipolar */
87#define AD7799_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */
88#define AD7799_CONF_REFDET(x) (((x) & 0x1) << 5) /* Reference detect */
89#define AD7799_CONF_BUF 0x10 /* Buffered Mode Enable */
90#define AD7799_CONF_CHAN(x) ((x) & 0x7) /* Channel select */
91
92/* AD7799_CONF_GAIN(x) options */
93#define AD7799_GAIN_1 0x0
94#define AD7799_GAIN_2 0x1
95#define AD7799_GAIN_4 0x2
96#define AD7799_GAIN_8 0x3
97#define AD7799_GAIN_16 0x4
98#define AD7799_GAIN_32 0x5
99#define AD7799_GAIN_64 0x6
100#define AD7799_GAIN_128 0x7
101
102/* AD7799 Register size */
103#define AD7799_REG_SIZE_1B 0x1
104#define AD7799_REG_SIZE_2B 0x2
105#define AD7799_REG_SIZE_3B 0x3
106
107/* AD7799_CONF_REFDET(x) options */
108#define AD7799_REFDET_ENA 0x1
109#define AD7799_REFDET_DIS 0x0
110
111/* AD7799_CONF_CHAN(x) options */
112#define AD7799_CH_AIN1P_AIN1M 0x0 /* AIN1(+) - AIN1(-) */
113#define AD7799_CH_AIN2P_AIN2M 0x1 /* AIN2(+) - AIN2(-) */
114#define AD7799_CH_AIN3P_AIN3M 0x2 /* AIN3(+) - AIN3(-) */
115#define AD7799_CH_AIN1M_AIN1M 0x3 /* AIN1(-) - AIN1(-) */
116#define AD7799_CH_AVDD_MONITOR 0x7 /* AVDD Monitor */
117
118/* ID Register Bit Designations (AD7799_REG_ID) */
119#define AD7799_ID_MASK 0xF
120
121/* AD7799 Configuration Mask */
122#define AD7799_REG_MASK 0xF
123
124/* IO (Excitation Current Sources) Register Bit Designations (AD7799_REG_IO) */
125#define AD7799_IOEN 0x40
126#define AD7799_IO1(x) (((x) & 0x1) << 4)
127#define AD7799_IO2(x) (((x) & 0x1) << 5)
128
129/* AD7799 Timeout */
130#define AD7799_TIMEOUT 0xFFFF
131
132/* AD7799 Reset Sequence */
133#define AD7799_RESET_DATA 0xFF
134
144};
145
152
161 uint8_t chip_type;
163 const uint8_t *reg_size;
165 uint8_t gain;
169 uint32_t vref_mv;
172};
173
192
193/* Read device register. */
194int32_t ad7799_read(struct ad7799_dev *device, uint8_t reg_addr,
195 uint32_t *reg_data);
196
197/* Write device register */
198int32_t ad7799_write(struct ad7799_dev *device, uint8_t reg_addr,
199 uint32_t reg_data);
200
201/* Software reset of the device. */
202int32_t ad7799_reset(struct ad7799_dev *device);
203
204/* Set the device mode. */
205int32_t ad7799_set_mode(struct ad7799_dev *device, uint8_t mode);
206
207/* Select the ADC channel. */
208int32_t ad7799_set_channel(struct ad7799_dev *device, uint8_t ch);
209
210/* Read specific ADC channel. */
211int32_t ad7799_get_channel(struct ad7799_dev *device, uint8_t ch,
212 uint32_t *reg_data);
213
214/* Read specific ADC channel data with the specified precision. */
215int32_t ad7799_read_channel(struct ad7799_dev *device, uint8_t ch,
216 int32_t *data_scaled);
217
218/* Set the ADC gain. */
219int32_t ad7799_set_gain(struct ad7799_dev *device, uint8_t gain);
220
221/* Get the ADC gain. */
222int32_t ad7799_get_gain(struct ad7799_dev *device, uint8_t *gain);
223
224/* Enable or disable the reference detect function. */
225int32_t ad7799_set_refdet(struct ad7799_dev *device, uint8_t ref_en);
226
227/* Set ADC polarity. */
228int32_t ad7799_set_polarity(struct ad7799_dev *device, uint8_t polarity);
229
230/* Check the status of the device. */
231int32_t ad7799_dev_ready(struct ad7799_dev *device);
232
233/* Initialize the device. */
234int32_t ad7799_init(struct ad7799_dev **device,
235 const struct ad7799_init_param *init_param);
236
237/* Remove the device and release resources. */
238int32_t ad7799_remove(struct ad7799_dev *device);
239
240#endif /* AD7799_H_ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int32_t ad7799_get_channel(struct ad7799_dev *device, uint8_t ch, uint32_t *reg_data)
Read specific ADC channel.
Definition ad7799.c:198
int32_t ad7799_set_channel(struct ad7799_dev *device, uint8_t ch)
Select the ADC channel.
Definition ad7799.c:176
ad7799_precision
Definition ad7799.h:146
@ AD7799_PRECISION_MV
Definition ad7799.h:148
@ AD7799_PRECISION_UV
Definition ad7799.h:150
int32_t ad7799_dev_ready(struct ad7799_dev *device)
Read the /RDY bit of status register and check the status of the device.
Definition ad7799.c:354
int32_t ad7799_init(struct ad7799_dev **device, const struct ad7799_init_param *init_param)
Initialize the device.
Definition ad7799.c:381
int32_t ad7799_reset(struct ad7799_dev *device)
Software reset of the device.
Definition ad7799.c:129
int32_t ad7799_set_mode(struct ad7799_dev *device, uint8_t mode)
Set the device mode.
Definition ad7799.c:147
ad7799_type
Device type (AD7798/AD7799)
Definition ad7799.h:139
@ ID_AD7799
Definition ad7799.h:143
@ ID_AD7798
Definition ad7799.h:141
int32_t ad7799_write(struct ad7799_dev *device, uint8_t reg_addr, uint32_t reg_data)
Write device register.
Definition ad7799.c:103
int32_t ad7799_set_gain(struct ad7799_dev *device, uint8_t gain)
Set the ADC gain.
Definition ad7799.c:267
int32_t ad7799_set_refdet(struct ad7799_dev *device, uint8_t ref_en)
Enable or disable the reference detect function.
Definition ad7799.c:310
int32_t ad7799_read_channel(struct ad7799_dev *device, uint8_t ch, int32_t *data_scaled)
Read data from specific ADC channel with specified precision.
Definition ad7799.c:229
int32_t ad7799_set_polarity(struct ad7799_dev *device, uint8_t polarity)
Set ADC polarity.
Definition ad7799.c:333
int32_t ad7799_get_gain(struct ad7799_dev *device, uint8_t *gain)
Get the ADC gain.
Definition ad7799.c:288
int32_t ad7799_remove(struct ad7799_dev *device)
Remove the device and release resources.
Definition ad7799.c:464
int32_t ad7799_read(struct ad7799_dev *device, uint8_t reg_addr, uint32_t *reg_data)
Read device register.
Definition ad7799.c:70
Header file of SPI Interface.
AD7798/AD7799 Device description.
Definition ad7799.h:157
enum ad7799_precision precision
Definition ad7799.h:171
bool polarity
Definition ad7799.h:167
const uint8_t * reg_size
Definition ad7799.h:163
struct no_os_spi_desc * spi_desc
Definition ad7799.h:159
uint8_t chip_type
Definition ad7799.h:161
uint32_t vref_mv
Definition ad7799.h:169
uint8_t gain
Definition ad7799.h:165
AD7798/AD7799 Device initialization parameters.
Definition ad7799.h:178
struct no_os_spi_init_param spi_init
Definition ad7799.h:180
bool polarity
Definition ad7799.h:186
uint32_t vref_mv
Definition ad7799.h:188
enum ad7799_precision precision
Definition ad7799.h:190
enum ad7799_type chip_type
Definition ad7799.h:182
uint8_t gain
Definition ad7799.h:184
Definition ad9361_util.h:63
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128
enum no_os_spi_mode mode
Definition no_os_spi.h:136