no-OS
Loading...
Searching...
No Matches
ad719x.c File Reference

Implementation of AD7190/2/3/4/5 Driver. More...

#include <stdlib.h>
#include "ad719x.h"
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"
#include <string.h>
Include dependency graph for ad719x.c:

Functions

int ad719x_init (struct ad719x_dev **device, struct ad719x_init_param init_param)
 Initializes the communication peripheral and the initial Values for AD719X Board and resets the device.
 
int ad719x_remove (struct ad719x_dev *dev)
 Free the resources allocated by ad719x_init().
 
int ad719x_set_register_value (struct ad719x_dev *dev, uint8_t reg_addr, uint32_t reg_val, uint8_t bytes_number)
 Writes data into a register.
 
int ad719x_get_register_value (struct ad719x_dev *dev, uint8_t reg_addr, uint8_t bytes_number, uint32_t *reg_data)
 Reads the value of a register.
 
int ad719x_set_masked_register_value (struct ad719x_dev *dev, uint8_t reg_addr, uint32_t mask, uint32_t reg_data, uint8_t bytes)
 Write masked data into device register.
 
int ad719x_reset (struct ad719x_dev *dev)
 Resets the device.
 
int ad719x_set_operating_mode (struct ad719x_dev *dev, enum ad719x_adc_modes opt_mode)
 Sets device into the specified operating mode.
 
int ad719x_wait_rdy_go_low (struct ad719x_dev *dev)
 Waits for RDY pin to go low.
 
int ad719x_channels_select (struct ad719x_dev *dev, uint16_t chn_mask)
 Selects the channels to be enabled.
 
int ad719x_calibrate (struct ad719x_dev *dev, uint8_t mode, uint8_t channel)
 Performs the given calibration to the specified channel.
 
int ad719x_config_input_mode (struct ad719x_dev *dev, uint8_t mode)
 Configures the input mode of the ADC.
 
int ad719x_buffer_select (struct ad719x_dev *dev, uint8_t buff_en)
 Enables or disables the buffer on the ADC input channels.
 
int ad719x_output_rate_select (struct ad719x_dev *dev, uint16_t out_rate_code)
 Selects the filter output data rate of the ADC.
 
int ad719x_clock_select (struct ad719x_dev *dev, enum ad719x_adc_clock clk_select)
 Selects the clock source of the ADC.
 
int ad719x_set_bridge_switch (struct ad719x_dev *dev, uint8_t bpdsw_select)
 Opens or closes the bridge power-down switch of the ADC.
 
int ad719x_range_setup (struct ad719x_dev *dev, uint8_t polarity, enum ad719x_adc_gain gain)
 Selects the polarity of the conversion and the ADC input range.
 
int ad719x_single_conversion (struct ad719x_dev *dev, uint32_t *reg_data)
 Returns the result of a single conversion.
 
int ad719x_continuous_read_avg (struct ad719x_dev *dev, uint8_t sample_number, uint32_t *samples_avg)
 Returns the average of several conversion results.
 
int ad719x_temperature_read (struct ad719x_dev *dev, float *temp)
 Read data from temperature sensor and converts it to Celsius degrees.
 
float ad719x_convert_to_millivolts (struct ad719x_dev *dev, uint32_t raw_data, float v_ref)
 Converts 24-bit raw data to millivolts.
 
int ad719x_sync_control (struct ad719x_dev *dev, uint8_t value)
 Control SYNC pin for synchronization of multiple devices.
 

Detailed Description

Implementation of AD7190/2/3/4/5 Driver.

Author
DNechita (Dan.N.nosp@m.echi.nosp@m.ta@an.nosp@m.alog.nosp@m..com)

Copyright 2012(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ad719x_buffer_select()

int ad719x_buffer_select ( struct ad719x_dev * dev,
uint8_t buff_en )

Enables or disables the buffer on the ADC input channels.

Parameters
dev- The device structure.
buff_en- Enable/disable option. Example: 0 - Buffer disabled 1 - Buffer Enabled
Returns
0 in case of success or negative error code.

◆ ad719x_calibrate()

int ad719x_calibrate ( struct ad719x_dev * dev,
uint8_t mode,
uint8_t channel )

Performs the given calibration to the specified channel.

Parameters
dev- The device structure.
mode- Calibration type.
channel- Channel to be calibrated.
Returns
0 in case of success or negative error code.

◆ ad719x_channels_select()

int ad719x_channels_select ( struct ad719x_dev * dev,
uint16_t chn_mask )

Selects the channels to be enabled.

Parameters
dev- The device structure.
chn_mask- Channel mask. Example: AD719X_CH_0 - AIN1(+) - AIN2(-); (Pseudo = 0) AD719X_CH_1 - AIN3(+) - AIN4(-); (Pseudo = 0) AD719X_TEMP - Temperature sensor AD719X_SHORT - AIN2(+) - AIN2(-); (Pseudo = 0)
Returns
0 in case of success or negative error code.

◆ ad719x_clock_select()

int ad719x_clock_select ( struct ad719x_dev * dev,
enum ad719x_adc_clock clk_select )

Selects the clock source of the ADC.

Parameters
dev- The device structure.
clk_select- Clock source to be selected. Accepted values: AD719X_EXT_CRYSTAL_MCLK1_MCLK2 AD719X_EXT_CRYSTAL_MCLK2 AD719X_INT_CLK_4_92_MHZ_TRIST AD719X_INT_CLK_4_92_MHZ
Returns
0 in case of success or negative error code.

◆ ad719x_config_input_mode()

int ad719x_config_input_mode ( struct ad719x_dev * dev,
uint8_t mode )

Configures the input mode of the ADC.

Parameters
dev- The device structure.
mode- Mode selection. Example: 0 - Differential Analog Inputs 1 - Pseudo Differential Analog Inputs
Returns
0 in case of success or negative error code.

◆ ad719x_continuous_read_avg()

int ad719x_continuous_read_avg ( struct ad719x_dev * dev,
uint8_t sample_number,
uint32_t * samples_avg )

Returns the average of several conversion results.

Parameters
dev- The device structure.
sample_number- the number of samples
samples_avg- Average of the samples read
Returns
0 in case of success or negative error code.

◆ ad719x_convert_to_millivolts()

float ad719x_convert_to_millivolts ( struct ad719x_dev * dev,
uint32_t raw_data,
float v_ref )

Converts 24-bit raw data to millivolts.

Parameters
dev- The device structure.
raw_data- 24-bit data sample.
v_ref- The value of the voltage reference used by the device.
Returns
millivolts - The result of the conversion expressed as millivolts.

◆ ad719x_get_register_value()

int ad719x_get_register_value ( struct ad719x_dev * dev,
uint8_t reg_addr,
uint8_t bytes_number,
uint32_t * reg_data )

Reads the value of a register.

Parameters
dev- The device structure.
reg_addr- Address of the register.
bytes_number- Number of bytes that will be read.
reg_data- Data read from the register.
Returns
0 in case of success or negative error code.

◆ ad719x_init()

int ad719x_init ( struct ad719x_dev ** device,
struct ad719x_init_param init_param )

Initializes the communication peripheral and the initial Values for AD719X Board and resets the device.

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

◆ ad719x_output_rate_select()

int ad719x_output_rate_select ( struct ad719x_dev * dev,
uint16_t out_rate_code )

Selects the filter output data rate of the ADC.

Parameters
dev- The device structure.
out_rate_code- Filter output data rate code.
Returns
0 in case of success or negative error code.

◆ ad719x_range_setup()

int ad719x_range_setup ( struct ad719x_dev * dev,
uint8_t polarity,
enum ad719x_adc_gain gain )

Selects the polarity of the conversion and the ADC input range.

Parameters
dev- The device structure.
polarity- Polarity select bit. Example: 0 - bipolar operation is selected. 1 - unipolar operation is selected.
gain- Gain select bits. These bits are written by the user to select the ADC input range.
Returns
0 in case of success or negative error code.

◆ ad719x_remove()

int ad719x_remove ( struct ad719x_dev * dev)

Free the resources allocated by ad719x_init().

Parameters
dev- The device structure.
Returns
0 in case of success or negative error code.

◆ ad719x_reset()

int ad719x_reset ( struct ad719x_dev * dev)

Resets the device.

Parameters
dev- The device structure.
Returns
0 in case of success or negative error code.

◆ ad719x_set_bridge_switch()

int ad719x_set_bridge_switch ( struct ad719x_dev * dev,
uint8_t bpdsw_select )

Opens or closes the bridge power-down switch of the ADC.

Parameters
dev- The device structure.
bpdsw_select- Option to open or close bridge power-down switch. 0 - Switch Opened 1 - Switch Closed
Returns
0 in case of success or negative error code.

◆ ad719x_set_masked_register_value()

int ad719x_set_masked_register_value ( struct ad719x_dev * dev,
uint8_t reg_addr,
uint32_t mask,
uint32_t reg_data,
uint8_t bytes )

Write masked data into device register.

Parameters
dev- The device structure.
reg_addr- Address of the register.
mask- The mask.
reg_data- Register data to be written.
bytes- Number of bytes that will be read.
Returns
0 in case of success or negative error code.

◆ ad719x_set_operating_mode()

int ad719x_set_operating_mode ( struct ad719x_dev * dev,
enum ad719x_adc_modes opt_mode )

Sets device into the specified operating mode.

Parameters
dev- The device structure.
opt_mode- Operating mode to be set. Accepted values: AD719X_MODE_CONT AD719X_MODE_SINGLE AD719X_MODE_IDLE AD719X_MODE_PWRDN AD719X_MODE_CAL_INT_ZERO AD719X_MODE_CAL_INT_FULL AD719X_MODE_CAL_SYS_ZERO AD719X_MODE_CAL_SYS_FULL
Returns
0 in case of success or negative error code.

◆ ad719x_set_register_value()

int ad719x_set_register_value ( struct ad719x_dev * dev,
uint8_t reg_addr,
uint32_t reg_val,
uint8_t bytes_number )

Writes data into a register.

Parameters
dev- The device structure.
reg_addr- Address of the register.
reg_val- Data value to write.
bytes_number- Number of bytes to be written.
Returns
0 in case of success or negative error code.

◆ ad719x_single_conversion()

int ad719x_single_conversion ( struct ad719x_dev * dev,
uint32_t * reg_data )

Returns the result of a single conversion.

Parameters
dev- The device structure.
reg_data- Buffer to store sampled register data
Returns
0 in case of success or negative error code.

◆ ad719x_sync_control()

int ad719x_sync_control ( struct ad719x_dev * dev,
uint8_t value )

Control SYNC pin for synchronization of multiple devices.

Parameters
dev- The device structure.
value- Pin level to be written. 0 - LOW 1 - HIGH
Returns
0 in case of success or negative error code.

◆ ad719x_temperature_read()

int ad719x_temperature_read ( struct ad719x_dev * dev,
float * temp )

Read data from temperature sensor and converts it to Celsius degrees.

Parameters
dev- The device structure.
temp- Stores the temperature result.
Returns
0 in case of success or negative error code.

◆ ad719x_wait_rdy_go_low()

int ad719x_wait_rdy_go_low ( struct ad719x_dev * dev)

Waits for RDY pin to go low.

Returns
0 in case of success or negative error code.