no-OS
Classes | Macros | Enumerations | Functions
ad7799.h File Reference

Header file of AD7798/AD7799 Driver. More...

#include <stdint.h>
#include <stdbool.h>
#include "no_os_spi.h"
Include dependency graph for ad7799.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ad7799_dev
 AD7798/AD7799 Device description. More...
 
struct  ad7799_init_param
 AD7798/AD7799 Device initialization parameters. More...
 

Macros

#define AD7799_REG_COMM   0x0 /* Communications Register(WO, 8-bit) */
 
#define AD7799_REG_STAT   0x0 /* Status Register (RO, 8-bit) */
 
#define AD7799_REG_MODE   0x1 /* Mode Register (RW, 16-bit) */
 
#define AD7799_REG_CONF   0x2 /* Configuration Register (RW, 16-bit)*/
 
#define AD7799_REG_DATA   0x3 /* Data Register (RO, 16-/24-bit) */
 
#define AD7799_REG_ID   0x4 /* ID Register (RO, 8-bit) */
 
#define AD7799_REG_IO   0x5 /* IO Register (RO, 8-bit) */
 
#define AD7799_REG_OFFSET   0x6 /* Offset Register (RW, 24-bit) */
 
#define AD7799_REG_FULLSCALE   0x7 /* Full-Scale Register (RW, 24-bit) */
 
#define AD7799_BIPOLAR   0x0 /* Bipolar bit */
 
#define AD7799_UNIPOLAR   0x1 /* Unipolar bit */
 
#define AD7799_COMM_WEN   0x80 /* Write Enable */
 
#define AD7799_COMM_WRITE   0x00 /* Write Operation */
 
#define AD7799_COMM_READ   0x40 /* Read Operation */
 
#define AD7799_COMM_ADDR(x)   (((x) & 0x7) << 3) /* Register Address */
 
#define AD7799_COMM_CREAD   0x04 /* Continuous Read */
 
#define AD7799_STAT_RDY   0x80 /* Ready */
 
#define AD7799_STAT_ERR   0x40 /* Error (Overrange, Underrange) */
 
#define AD7799_STAT_CH3   0x04 /* Channel 3 */
 
#define AD7799_STAT_CH2   (1 << 1) /* Channel 2 */
 
#define AD7799_STAT_CH1   (1 << 0) /* Channel 1 */
 
#define AD7799_MODE_SEL(x)   (((x) & 0x7) << 13) /* Operation Mode Select */
 
#define AD7799_MODE_PSW(x)   0x1000 /* Power Switch Control Bit */
 
#define AD7799_MODE_RATE(x)   ((x) & 0xF) /* Filter Update Rate */
 
#define AD7799_MODE_CONT   0x0 /* Continuous Conversion Mode */
 
#define AD7799_MODE_SINGLE   0x1 /* Single Conversion Mode */
 
#define AD7799_MODE_IDLE   0x2 /* Idle Mode */
 
#define AD7799_MODE_PWRDN   0x3 /* Power-Down Mode */
 
#define AD7799_MODE_CAL_INT_ZERO   0x4 /* Internal Zero-Scale Calibration */
 
#define AD7799_MODE_CAL_INT_FULL   0x5 /* Internal Full-Scale Calibration */
 
#define AD7799_MODE_CAL_SYS_ZERO   0x6 /* System Zero-Scale Calibration */
 
#define AD7799_MODE_CAL_SYS_FULL   0x7 /* System Full-Scale Calibration */
 
#define AD7799_CONF_BO_EN   0x2000 /* Burnout Current */
 
#define AD7799_CONF_POLARITY(x)   (((x) & 0x1) << 12) /* Unipolar/Bipolar */
 
#define AD7799_CONF_GAIN(x)   (((x) & 0x7) << 8) /* Gain Select */
 
#define AD7799_CONF_REFDET(x)   (((x) & 0x1) << 5) /* Reference detect */
 
#define AD7799_CONF_BUF   0x10 /* Buffered Mode Enable */
 
#define AD7799_CONF_CHAN(x)   ((x) & 0x7) /* Channel select */
 
#define AD7799_GAIN_1   0x0
 
#define AD7799_GAIN_2   0x1
 
#define AD7799_GAIN_4   0x2
 
#define AD7799_GAIN_8   0x3
 
#define AD7799_GAIN_16   0x4
 
#define AD7799_GAIN_32   0x5
 
#define AD7799_GAIN_64   0x6
 
#define AD7799_GAIN_128   0x7
 
#define AD7799_REG_SIZE_1B   0x1
 
#define AD7799_REG_SIZE_2B   0x2
 
#define AD7799_REG_SIZE_3B   0x3
 
#define AD7799_REFDET_ENA   0x1
 
#define AD7799_REFDET_DIS   0x0
 
#define AD7799_CH_AIN1P_AIN1M   0x0 /* AIN1(+) - AIN1(-) */
 
#define AD7799_CH_AIN2P_AIN2M   0x1 /* AIN2(+) - AIN2(-) */
 
#define AD7799_CH_AIN3P_AIN3M   0x2 /* AIN3(+) - AIN3(-) */
 
#define AD7799_CH_AIN1M_AIN1M   0x3 /* AIN1(-) - AIN1(-) */
 
#define AD7799_CH_AVDD_MONITOR   0x7 /* AVDD Monitor */
 
#define AD7799_ID_MASK   0xF
 
#define AD7799_REG_MASK   0xF
 
#define AD7799_IOEN   0x40
 
#define AD7799_IO1(x)   (((x) & 0x1) << 4)
 
#define AD7799_IO2(x)   (((x) & 0x1) << 5)
 
#define AD7799_TIMEOUT   0xFFFF
 
#define AD7799_RESET_DATA   0xFF
 

Enumerations

enum  ad7799_type {
  ID_AD7798 = 0x8,
  ID_AD7799 = 0x9
}
 Device type (AD7798/AD7799) More...
 
enum  ad7799_precision {
  AD7799_PRECISION_MV,
  AD7799_PRECISION_UV
}
 

Functions

int32_t ad7799_read (struct ad7799_dev *device, uint8_t reg_addr, uint32_t *reg_data)
 Read device register. More...
 
int32_t ad7799_write (struct ad7799_dev *device, uint8_t reg_addr, uint32_t reg_data)
 Write device register. More...
 
int32_t ad7799_reset (struct ad7799_dev *device)
 Software reset of the device. More...
 
int32_t ad7799_set_mode (struct ad7799_dev *device, uint8_t mode)
 Set the device mode. More...
 
int32_t ad7799_set_channel (struct ad7799_dev *device, uint8_t ch)
 Select the ADC channel. More...
 
int32_t ad7799_get_channel (struct ad7799_dev *device, uint8_t ch, uint32_t *reg_data)
 Read specific ADC channel. More...
 
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. More...
 
int32_t ad7799_set_gain (struct ad7799_dev *device, uint8_t gain)
 Set the ADC gain. More...
 
int32_t ad7799_get_gain (struct ad7799_dev *device, uint8_t *gain)
 Get the ADC gain. More...
 
int32_t ad7799_set_refdet (struct ad7799_dev *device, uint8_t ref_en)
 Enable or disable the reference detect function. More...
 
int32_t ad7799_set_polarity (struct ad7799_dev *device, uint8_t polarity)
 Set ADC polarity. More...
 
int32_t ad7799_dev_ready (struct ad7799_dev *device)
 Read the /RDY bit of status register and check the status of the device. More...
 
int32_t ad7799_init (struct ad7799_dev **device, const struct ad7799_init_param *init_param)
 Initialize the device. More...
 
int32_t ad7799_remove (struct ad7799_dev *device)
 Remove the device and release resources. More...
 

Detailed Description

Header file of AD7798/AD7799 Driver.

Author
Antoniu Miclaus (anton.nosp@m.iu.m.nosp@m.iclau.nosp@m.s@an.nosp@m.alog..nosp@m.com)

Copyright 2020(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ AD7799_BIPOLAR

#define AD7799_BIPOLAR   0x0 /* Bipolar bit */

◆ AD7799_CH_AIN1M_AIN1M

#define AD7799_CH_AIN1M_AIN1M   0x3 /* AIN1(-) - AIN1(-) */

◆ AD7799_CH_AIN1P_AIN1M

#define AD7799_CH_AIN1P_AIN1M   0x0 /* AIN1(+) - AIN1(-) */

◆ AD7799_CH_AIN2P_AIN2M

#define AD7799_CH_AIN2P_AIN2M   0x1 /* AIN2(+) - AIN2(-) */

◆ AD7799_CH_AIN3P_AIN3M

#define AD7799_CH_AIN3P_AIN3M   0x2 /* AIN3(+) - AIN3(-) */

◆ AD7799_CH_AVDD_MONITOR

#define AD7799_CH_AVDD_MONITOR   0x7 /* AVDD Monitor */

◆ AD7799_COMM_ADDR

#define AD7799_COMM_ADDR (   x)    (((x) & 0x7) << 3) /* Register Address */

◆ AD7799_COMM_CREAD

#define AD7799_COMM_CREAD   0x04 /* Continuous Read */

◆ AD7799_COMM_READ

#define AD7799_COMM_READ   0x40 /* Read Operation */

◆ AD7799_COMM_WEN

#define AD7799_COMM_WEN   0x80 /* Write Enable */

◆ AD7799_COMM_WRITE

#define AD7799_COMM_WRITE   0x00 /* Write Operation */

◆ AD7799_CONF_BO_EN

#define AD7799_CONF_BO_EN   0x2000 /* Burnout Current */

◆ AD7799_CONF_BUF

#define AD7799_CONF_BUF   0x10 /* Buffered Mode Enable */

◆ AD7799_CONF_CHAN

#define AD7799_CONF_CHAN (   x)    ((x) & 0x7) /* Channel select */

◆ AD7799_CONF_GAIN

#define AD7799_CONF_GAIN (   x)    (((x) & 0x7) << 8) /* Gain Select */

◆ AD7799_CONF_POLARITY

#define AD7799_CONF_POLARITY (   x)    (((x) & 0x1) << 12) /* Unipolar/Bipolar */

◆ AD7799_CONF_REFDET

#define AD7799_CONF_REFDET (   x)    (((x) & 0x1) << 5) /* Reference detect */

◆ AD7799_GAIN_1

#define AD7799_GAIN_1   0x0

◆ AD7799_GAIN_128

#define AD7799_GAIN_128   0x7

◆ AD7799_GAIN_16

#define AD7799_GAIN_16   0x4

◆ AD7799_GAIN_2

#define AD7799_GAIN_2   0x1

◆ AD7799_GAIN_32

#define AD7799_GAIN_32   0x5

◆ AD7799_GAIN_4

#define AD7799_GAIN_4   0x2

◆ AD7799_GAIN_64

#define AD7799_GAIN_64   0x6

◆ AD7799_GAIN_8

#define AD7799_GAIN_8   0x3

◆ AD7799_ID_MASK

#define AD7799_ID_MASK   0xF

◆ AD7799_IO1

#define AD7799_IO1 (   x)    (((x) & 0x1) << 4)

◆ AD7799_IO2

#define AD7799_IO2 (   x)    (((x) & 0x1) << 5)

◆ AD7799_IOEN

#define AD7799_IOEN   0x40

◆ AD7799_MODE_CAL_INT_FULL

#define AD7799_MODE_CAL_INT_FULL   0x5 /* Internal Full-Scale Calibration */

◆ AD7799_MODE_CAL_INT_ZERO

#define AD7799_MODE_CAL_INT_ZERO   0x4 /* Internal Zero-Scale Calibration */

◆ AD7799_MODE_CAL_SYS_FULL

#define AD7799_MODE_CAL_SYS_FULL   0x7 /* System Full-Scale Calibration */

◆ AD7799_MODE_CAL_SYS_ZERO

#define AD7799_MODE_CAL_SYS_ZERO   0x6 /* System Zero-Scale Calibration */

◆ AD7799_MODE_CONT

#define AD7799_MODE_CONT   0x0 /* Continuous Conversion Mode */

◆ AD7799_MODE_IDLE

#define AD7799_MODE_IDLE   0x2 /* Idle Mode */

◆ AD7799_MODE_PSW

#define AD7799_MODE_PSW (   x)    0x1000 /* Power Switch Control Bit */

◆ AD7799_MODE_PWRDN

#define AD7799_MODE_PWRDN   0x3 /* Power-Down Mode */

◆ AD7799_MODE_RATE

#define AD7799_MODE_RATE (   x)    ((x) & 0xF) /* Filter Update Rate */

◆ AD7799_MODE_SEL

#define AD7799_MODE_SEL (   x)    (((x) & 0x7) << 13) /* Operation Mode Select */

◆ AD7799_MODE_SINGLE

#define AD7799_MODE_SINGLE   0x1 /* Single Conversion Mode */

◆ AD7799_REFDET_DIS

#define AD7799_REFDET_DIS   0x0

◆ AD7799_REFDET_ENA

#define AD7799_REFDET_ENA   0x1

◆ AD7799_REG_COMM

#define AD7799_REG_COMM   0x0 /* Communications Register(WO, 8-bit) */

◆ AD7799_REG_CONF

#define AD7799_REG_CONF   0x2 /* Configuration Register (RW, 16-bit)*/

◆ AD7799_REG_DATA

#define AD7799_REG_DATA   0x3 /* Data Register (RO, 16-/24-bit) */

◆ AD7799_REG_FULLSCALE

#define AD7799_REG_FULLSCALE   0x7 /* Full-Scale Register (RW, 24-bit) */

◆ AD7799_REG_ID

#define AD7799_REG_ID   0x4 /* ID Register (RO, 8-bit) */

◆ AD7799_REG_IO

#define AD7799_REG_IO   0x5 /* IO Register (RO, 8-bit) */

◆ AD7799_REG_MASK

#define AD7799_REG_MASK   0xF

◆ AD7799_REG_MODE

#define AD7799_REG_MODE   0x1 /* Mode Register (RW, 16-bit) */

◆ AD7799_REG_OFFSET

#define AD7799_REG_OFFSET   0x6 /* Offset Register (RW, 24-bit) */

◆ AD7799_REG_SIZE_1B

#define AD7799_REG_SIZE_1B   0x1

◆ AD7799_REG_SIZE_2B

#define AD7799_REG_SIZE_2B   0x2

◆ AD7799_REG_SIZE_3B

#define AD7799_REG_SIZE_3B   0x3

◆ AD7799_REG_STAT

#define AD7799_REG_STAT   0x0 /* Status Register (RO, 8-bit) */

◆ AD7799_RESET_DATA

#define AD7799_RESET_DATA   0xFF

◆ AD7799_STAT_CH1

#define AD7799_STAT_CH1   (1 << 0) /* Channel 1 */

◆ AD7799_STAT_CH2

#define AD7799_STAT_CH2   (1 << 1) /* Channel 2 */

◆ AD7799_STAT_CH3

#define AD7799_STAT_CH3   0x04 /* Channel 3 */

◆ AD7799_STAT_ERR

#define AD7799_STAT_ERR   0x40 /* Error (Overrange, Underrange) */

◆ AD7799_STAT_RDY

#define AD7799_STAT_RDY   0x80 /* Ready */

◆ AD7799_TIMEOUT

#define AD7799_TIMEOUT   0xFFFF

◆ AD7799_UNIPOLAR

#define AD7799_UNIPOLAR   0x1 /* Unipolar bit */

Enumeration Type Documentation

◆ ad7799_precision

Enumerator
AD7799_PRECISION_MV 

ADC channel precision in mV

AD7799_PRECISION_UV 

ADC channel precision in uV

◆ ad7799_type

Device type (AD7798/AD7799)

Enumerator
ID_AD7798 

AD7798 device

ID_AD7799 

AD7799 device

Function Documentation

◆ ad7799_dev_ready()

int32_t ad7799_dev_ready ( struct ad7799_dev device)

Read the /RDY bit of status register and check the status of the device.

Parameters
device- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7799_get_channel()

int32_t ad7799_get_channel ( struct ad7799_dev device,
uint8_t  ch,
uint32_t *  reg_data 
)

Read specific ADC channel.

Parameters
device- The device structure.
ch- The ADC channel.
reg_data- The content of the data register.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7799_get_gain()

int32_t ad7799_get_gain ( struct ad7799_dev device,
uint8_t *  gain 
)

Get the ADC gain.

Parameters
device- The device structure.
gain- the gain value from the register.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_init()

int32_t ad7799_init ( struct ad7799_dev **  device,
const struct ad7799_init_param init_param 
)

Initialize the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_read()

int32_t ad7799_read ( struct ad7799_dev device,
uint8_t  reg_addr,
uint32_t *  reg_data 
)

Read device register.

Parameters
device- The device structure.
reg_addr- The register address.
reg_data- The data read from the register.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7799_read_channel()

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.

Parameters
device- The device structure.
ch- The ADC channel.
data_scaled- The content of the data in mV/uV.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_remove()

int32_t ad7799_remove ( struct ad7799_dev device)

Remove the device and release resources.

Parameters
device- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_reset()

int32_t ad7799_reset ( struct ad7799_dev device)

Software reset of the device.

Parameters
device- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_set_channel()

int32_t ad7799_set_channel ( struct ad7799_dev device,
uint8_t  ch 
)

Select the ADC channel.

Parameters
device- The device structure.
ch- The channel number.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7799_set_gain()

int32_t ad7799_set_gain ( struct ad7799_dev device,
uint8_t  gain 
)

Set the ADC gain.

Parameters
device- The device structure.
gain- the channel number.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_set_mode()

int32_t ad7799_set_mode ( struct ad7799_dev device,
uint8_t  mode 
)

Set the device mode.

Parameters
device- The device structure.
mode- The device mode.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7799_set_polarity()

int32_t ad7799_set_polarity ( struct ad7799_dev device,
uint8_t  polarity 
)

Set ADC polarity.

Parameters
device- The device structure.
polarity- set the device polarity: 0 - Bipolar coding 1 - Unipolar coding
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_set_refdet()

int32_t ad7799_set_refdet ( struct ad7799_dev device,
uint8_t  ref_en 
)

Enable or disable the reference detect function.

Parameters
device- The device structure.
ref_en- 1 reference detect enable.
  • 0 reference detect disable.
Returns
0 in case of success, negative error code otherwise.

◆ ad7799_write()

int32_t ad7799_write ( struct ad7799_dev device,
uint8_t  reg_addr,
uint32_t  reg_data 
)

Write device register.

Parameters
device- The device structure.
reg_addr- The register address.
reg_data- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function: