Implementation of ADE7754 Driver. More...
#include "ade7754.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "no_os_util.h"
#include "no_os_spi.h"
#include "no_os_gpio.h"
#include "no_os_irq.h"
#include "no_os_delay.h"
#include "no_os_units.h"
#include "no_os_alloc.h"
#include "no_os_crc16.h"
#include "no_os_print_log.h"
#include <stdlib.h>
#include <errno.h>
#include <math.h>
Functions | |
int | ade7754_init (struct ade7754_dev **device, struct ade7754_init_param init_param) |
Initialize the device. | |
int | ade7754_setup (struct ade7754_dev *dev) |
Setup the ADE7754 device. | |
int | ade7754_read (struct ade7754_dev *dev, uint16_t reg_addr, int32_t *reg_data) |
Read device register. | |
int | ade7754_write (struct ade7754_dev *dev, uint16_t reg_addr, uint32_t reg_data) |
Write device register. | |
int | ade7754_update_bits (struct ade7754_dev *dev, uint16_t reg_addr, uint32_t mask, uint32_t reg_data) |
Update specific register bits. | |
int | ade7754_remove (struct ade7754_dev *dev) |
Remove the device and release resources. | |
int | ade7754_sw_reset (struct ade7754_dev *dev) |
Reset the device using SW reset. | |
int | ade7754_hw_reset (struct ade7754_dev *dev) |
Reset the device using HW reset. | |
int | ade7754_version_product (struct ade7754_dev *dev, uint32_t *data_read) |
Version product. | |
int | ade7754_write_ipk_val (struct ade7754_dev *dev, uint32_t val) |
Write Ipeak val. | |
int | ade7754_write_vpk_val (struct ade7754_dev *dev, uint32_t val) |
Write Vpeak val. | |
int | ade7754_get_int_status (struct ade7754_dev *dev, uint32_t msk, uint8_t *status) |
Get interrupt indicator from STATUS register. | |
int | ade7754_clear_irq_status (struct ade7754_dev *dev, int32_t *reg_data) |
Clear irq status flags. | |
int | ade7754_enable_irq (struct ade7754_dev *dev, uint32_t msk, uint8_t en) |
Enable/Disable interrupt. | |
int | ade7754_wave_update_rate (struct ade7754_dev *dev, enum ade7754_data_rate sel) |
Select waveform register update rate. | |
int | ade7754_wave_sample_data_source (struct ade7754_dev *dev, enum ade7754_wavsel sel) |
Select source of sampled data for wave register. | |
int | ade7754_current_gain (struct ade7754_dev *dev, enum ade7754_pga_gain sel) |
Select the gain of the current channels inputs. | |
int | ade7754_voltage_gain (struct ade7754_dev *dev, enum ade7754_pga_gain sel) |
Select the gain of the voltage channels inputs. | |
int | ade7754_active_energy_formula (struct ade7754_dev *dev, enum ade7754_watm sel) |
Select the formula used for active energy calculation. | |
int | ade7754_apparent_energy_formula (struct ade7754_dev *dev, enum ade7754_vamod sel) |
Select the formula used for apparent energy calculation. | |
int | ade7754_period_source (struct ade7754_dev *dev, enum ade7754_phsel sel) |
Select the source of the measurement of the voltage line period. | |
int | ade7754_zxsel (struct ade7754_dev *dev, enum ade7754_phsel sel) |
Select the phases used for counting the number of zero crossing in the line active and apparent accumulation modes and enables these phases for the zero-crossing timeout detection, zero crossing, period measurement, and SAG detection. | |
int | ade7754_lwat_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel) |
Select part of the line active energy formula separately, depending on the line active energy measurement method. | |
int | ade7754_lva_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel) |
Select part of the line apparent energy formula separately, depending on the line active energy measurement method. | |
int | ade7754_wat_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel) |
Select part of the active energy formula separately, depending on the line active energy measurement method. | |
int | ade7754_va_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel) |
Select part of the apparent energy formula separately, depending on the line active energy measurement method. | |
int | ade7754_peak_source (struct ade7754_dev *dev, enum ade7754_phsel sel) |
Select the source of the voltage & current peak detection. | |
int | ade7754_adcs_mode (struct ade7754_dev *dev, enum ade7754_dismod sel) |
Operation mode of the ADCs. | |
int | ade7754_energy_vals (struct ade7754_dev *dev, struct ade7754_energy_values *data) |
Read energy values. | |
int | ade7754_rms_vals_phase_a (struct ade7754_dev *dev, struct ade7754_rms_values *data) |
Read rms values phase A. | |
int | ade7754_rms_vals_phase_b (struct ade7754_dev *dev, struct ade7754_rms_values *data) |
Read rms values phase B. | |
int | ade7754_rms_vals_phase_c (struct ade7754_dev *dev, struct ade7754_rms_values *data) |
Read rms values phase C. | |
int | ade7754_period_val (struct ade7754_dev *dev, struct ade7754_period_value *data) |
Read period value. | |
int | ade7754_temperature_val (struct ade7754_dev *dev, struct ade7754_temp_value *data) |
Read temperature value. | |
Implementation of ADE7754 Driver.
Copyright 2025(c) Analog Devices, Inc.
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, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 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.
int ade7754_active_energy_formula | ( | struct ade7754_dev * | dev, |
enum ade7754_watm | sel ) |
Select the formula used for active energy calculation.
dev | - The device structure. |
sel | - formula value |
int ade7754_adcs_mode | ( | struct ade7754_dev * | dev, |
enum ade7754_dismod | sel ) |
Operation mode of the ADCs.
dev | - The device structure. |
sel | - mode of the ADCs |
int ade7754_apparent_energy_formula | ( | struct ade7754_dev * | dev, |
enum ade7754_vamod | sel ) |
Select the formula used for apparent energy calculation.
dev | - The device structure. |
sel | - formula value |
int ade7754_clear_irq_status | ( | struct ade7754_dev * | dev, |
int32_t * | reg_data ) |
Clear irq status flags.
dev | - The device structure. |
reg_data | - value of the status register |
int ade7754_current_gain | ( | struct ade7754_dev * | dev, |
enum ade7754_pga_gain | sel ) |
Select the gain of the current channels inputs.
dev | - The device structure. |
sel | - gain value |
int ade7754_enable_irq | ( | struct ade7754_dev * | dev, |
uint32_t | msk, | ||
uint8_t | en ) |
Enable/Disable interrupt.
dev | - The device structure. |
msk | - Interrupt mask. |
en | -Enable/Disable |
int ade7754_energy_vals | ( | struct ade7754_dev * | dev, |
struct ade7754_energy_values * | data ) |
Read energy values.
dev | - The device structure. |
data | - Structure to store energy values |
int ade7754_get_int_status | ( | struct ade7754_dev * | dev, |
uint32_t | msk, | ||
uint8_t * | status ) |
Get interrupt indicator from STATUS register.
dev | - The device structure. |
msk | - Interrupt mask. |
status | - Status indicator. |
int ade7754_hw_reset | ( | struct ade7754_dev * | dev | ) |
Reset the device using HW reset.
dev | - The device structure. |
int ade7754_init | ( | struct ade7754_dev ** | device, |
struct ade7754_init_param | init_param ) |
Initialize the device.
device | - The device structure. |
init_param | - The structure that contains the device initial parameters. |
int ade7754_lva_formula_term | ( | struct ade7754_dev * | dev, |
enum ade7754_formsel | sel ) |
Select part of the line apparent energy formula separately, depending on the line active energy measurement method.
dev | - The device structure. |
sel | - formula part selection |
int ade7754_lwat_formula_term | ( | struct ade7754_dev * | dev, |
enum ade7754_formsel | sel ) |
Select part of the line active energy formula separately, depending on the line active energy measurement method.
dev | - The device structure. |
sel | - formula part selection |
int ade7754_peak_source | ( | struct ade7754_dev * | dev, |
enum ade7754_phsel | sel ) |
Select the source of the voltage & current peak detection.
dev | - The device structure. |
sel | - peak detection source |
int ade7754_period_source | ( | struct ade7754_dev * | dev, |
enum ade7754_phsel | sel ) |
Select the source of the measurement of the voltage line period.
dev | - The device structure. |
sel | - period measurement source |
int ade7754_period_val | ( | struct ade7754_dev * | dev, |
struct ade7754_period_value * | data ) |
Read period value.
dev | - The device structure. |
data | - Structure to store the period val |
int ade7754_read | ( | struct ade7754_dev * | dev, |
uint16_t | reg_addr, | ||
int32_t * | reg_data ) |
Read device register.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The data read from 32bit register. |
int ade7754_remove | ( | struct ade7754_dev * | dev | ) |
Remove the device and release resources.
dev | - The device structure. |
int ade7754_rms_vals_phase_a | ( | struct ade7754_dev * | dev, |
struct ade7754_rms_values * | data ) |
Read rms values phase A.
dev | - The device structure. |
data | - Structure to store rms values |
int ade7754_rms_vals_phase_b | ( | struct ade7754_dev * | dev, |
struct ade7754_rms_values * | data ) |
Read rms values phase B.
dev | - The device structure. |
data | - Structure to store rms values |
int ade7754_rms_vals_phase_c | ( | struct ade7754_dev * | dev, |
struct ade7754_rms_values * | data ) |
Read rms values phase C.
dev | - The device structure. |
data | - Structure to store rms values |
int ade7754_setup | ( | struct ade7754_dev * | dev | ) |
Setup the ADE7754 device.
dev | - The device structure. |
int ade7754_sw_reset | ( | struct ade7754_dev * | dev | ) |
Reset the device using SW reset.
dev | - The device structure. |
int ade7754_temperature_val | ( | struct ade7754_dev * | dev, |
struct ade7754_temp_value * | data ) |
Read temperature value.
dev | - The device structure. |
data | - Structure to store the temperature val |
int ade7754_update_bits | ( | struct ade7754_dev * | dev, |
uint16_t | reg_addr, | ||
uint32_t | mask, | ||
uint32_t | reg_data ) |
Update specific register bits.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - Specific bits mask. |
reg_data | - The data to be written. |
int ade7754_va_formula_term | ( | struct ade7754_dev * | dev, |
enum ade7754_formsel | sel ) |
Select part of the apparent energy formula separately, depending on the line active energy measurement method.
dev | - The device structure. |
sel | - formula part selection |
int ade7754_version_product | ( | struct ade7754_dev * | dev, |
uint32_t * | data_read ) |
Version product.
dev | - The device structure. |
data_read | - The version product read value |
int ade7754_voltage_gain | ( | struct ade7754_dev * | dev, |
enum ade7754_pga_gain | sel ) |
Select the gain of the voltage channels inputs.
dev | - The device structure. |
sel | - gain value |
int ade7754_wat_formula_term | ( | struct ade7754_dev * | dev, |
enum ade7754_formsel | sel ) |
Select part of the active energy formula separately, depending on the line active energy measurement method.
dev | - The device structure. |
sel | - formula part selection |
int ade7754_wave_sample_data_source | ( | struct ade7754_dev * | dev, |
enum ade7754_wavsel | sel ) |
Select source of sampled data for wave register.
dev | - The device structure. |
sel | - Update rate |
int ade7754_wave_update_rate | ( | struct ade7754_dev * | dev, |
enum ade7754_data_rate | sel ) |
Select waveform register update rate.
dev | - The device structure. |
sel | - Update rate |
int ade7754_write | ( | struct ade7754_dev * | dev, |
uint16_t | reg_addr, | ||
uint32_t | reg_data ) |
Write device register.
dev- | The device structure. |
reg_addr | - The register address. |
reg_data | - The data to be written. |
int ade7754_write_ipk_val | ( | struct ade7754_dev * | dev, |
uint32_t | val ) |
Write Ipeak val.
dev | - The device structure. |
val | - Ipeak set val |
int ade7754_write_vpk_val | ( | struct ade7754_dev * | dev, |
uint32_t | val ) |
Write Vpeak val.
dev | - The device structure. |
val | - Vpeak set val |
int ade7754_zxsel | ( | struct ade7754_dev * | dev, |
enum ade7754_phsel | sel ) |
Select the phases used for counting the number of zero crossing in the line active and apparent accumulation modes and enables these phases for the zero-crossing timeout detection, zero crossing, period measurement, and SAG detection.
dev | - The device structure. |
sel | - phase selection |