1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers: Renamed ina220 --> ina2xx

The INA219 has the exact same interface as the INA220 (including values and
semantics of the configuration register). Thus, this driver can be used for
both. The ina220 has been renamed to ina2xx to reflect this and pseudo modules
for the ina220 and ina219 have been added.
This commit is contained in:
Marian Buschsieweke 2019-04-01 16:50:28 +02:00
parent 77801d18e2
commit f424421f79
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
11 changed files with 186 additions and 174 deletions

View File

@ -219,7 +219,11 @@ ifneq (,$(filter hts221,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
endif
ifneq (,$(filter ina220,$(USEMODULE)))
ifneq (,$(filter ina2%,$(USEMODULE)))
USEMODULE += ina2xx
endif
ifneq (,$(filter ina2xx,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
endif

View File

@ -114,8 +114,8 @@ ifneq (,$(filter hts221,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/hts221/include
endif
ifneq (,$(filter ina220,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/ina220/include
ifneq (,$(filter ina2xx,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/ina2xx/include
endif
ifneq (,$(filter ina3221,$(USEMODULE)))

View File

@ -1,50 +0,0 @@
/*
* Copyright (C) 2015 Eistec AB
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup drivers_ina220
* @{
*
* @file
* @brief Register definitions for Texas Instruments INA220 High or Low
* Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire
* Interface
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/
#ifndef INA220_REGS_H
#define INA220_REGS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief INA220 register addresses
*
* All registers in the INA220 are 16 bit wide and transmitted MSB first.
*/
typedef enum ina220_reg {
INA220_REG_CONFIGURATION = 0x00, /**< Configuration register (read/write) */
INA220_REG_SHUNT_VOLTAGE = 0x01, /**< Shunt voltage register (read only) */
INA220_REG_BUS_VOLTAGE = 0x02, /**< Bus voltage register (read only) */
INA220_REG_POWER = 0x03, /**< Power register (read only) */
INA220_REG_CURRENT = 0x04, /**< Current register (read only) */
INA220_REG_CALIBRATION = 0x05, /**< Calibration register (read/write) */
} ina220_reg_t;
#ifdef __cplusplus
}
#endif
#endif /* INA220_REGS_H */
/** @} */

View File

@ -1,3 +1,3 @@
MODULE = ina220
MODULE = ina2xx
include $(RIOTBASE)/Makefile.base

View File

@ -7,11 +7,11 @@
*/
/**
* @ingroup drivers_ina220
* @ingroup drivers_ina2xx
* @{
*
* @file
* @brief Device driver implementation for Texas Instruments INA220 High
* @brief Device driver implementation for Texas Instruments INA2XX High
* or Low Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire
* Interface
*
@ -22,16 +22,16 @@
#include <stdint.h>
#include "ina220.h"
#include "ina220-regs.h"
#include "ina2xx.h"
#include "ina2xx-regs.h"
#include "periph/i2c.h"
#include "byteorder.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/** @brief Read one 16 bit register from a INA220 device and swap byte order, if necessary. */
static int ina220_read_reg(const ina220_t *dev, uint8_t reg, uint16_t *out)
/** @brief Read one 16 bit register from a INA2XX device and swap byte order, if necessary. */
static int ina2xx_read_reg(const ina2xx_t *dev, uint8_t reg, uint16_t *out)
{
union {
uint8_t c[2];
@ -49,8 +49,8 @@ static int ina220_read_reg(const ina220_t *dev, uint8_t reg, uint16_t *out)
return 0;
}
/** @brief Write one 16 bit register to a INA220 device and swap byte order, if necessary. */
static int ina220_write_reg(const ina220_t *dev, uint8_t reg, uint16_t in)
/** @brief Write one 16 bit register to a INA2XX device and swap byte order, if necessary. */
static int ina2xx_write_reg(const ina2xx_t *dev, uint8_t reg, uint16_t in)
{
union {
uint8_t c[2];
@ -70,7 +70,7 @@ static int ina220_write_reg(const ina220_t *dev, uint8_t reg, uint16_t in)
}
int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address)
int ina2xx_init(ina2xx_t *dev, i2c_t i2c, uint8_t address)
{
/* write device descriptor */
dev->i2c = i2c;
@ -78,32 +78,32 @@ int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address)
return 0;
}
int ina220_set_calibration(const ina220_t *dev, uint16_t calibration)
int ina2xx_set_calibration(const ina2xx_t *dev, uint16_t calibration)
{
return ina220_write_reg(dev, INA220_REG_CALIBRATION, calibration);
return ina2xx_write_reg(dev, INA2XX_REG_CALIBRATION, calibration);
}
int ina220_set_config(const ina220_t *dev, uint16_t config)
int ina2xx_set_config(const ina2xx_t *dev, uint16_t config)
{
return ina220_write_reg(dev, INA220_REG_CONFIGURATION, config);
return ina2xx_write_reg(dev, INA2XX_REG_CONFIGURATION, config);
}
int ina220_read_shunt(const ina220_t *dev, int16_t *voltage)
int ina2xx_read_shunt(const ina2xx_t *dev, int16_t *voltage)
{
return ina220_read_reg(dev, INA220_REG_SHUNT_VOLTAGE, (uint16_t *)voltage);
return ina2xx_read_reg(dev, INA2XX_REG_SHUNT_VOLTAGE, (uint16_t *)voltage);
}
int ina220_read_bus(const ina220_t *dev, int16_t *voltage)
int ina2xx_read_bus(const ina2xx_t *dev, int16_t *voltage)
{
return ina220_read_reg(dev, INA220_REG_BUS_VOLTAGE, (uint16_t *)voltage);
return ina2xx_read_reg(dev, INA2XX_REG_BUS_VOLTAGE, (uint16_t *)voltage);
}
int ina220_read_current(const ina220_t *dev, int16_t *current)
int ina2xx_read_current(const ina2xx_t *dev, int16_t *current)
{
return ina220_read_reg(dev, INA220_REG_CURRENT, (uint16_t *)current);
return ina2xx_read_reg(dev, INA2XX_REG_CURRENT, (uint16_t *)current);
}
int ina220_read_power(const ina220_t *dev, int16_t *power)
int ina2xx_read_power(const ina2xx_t *dev, int16_t *power)
{
return ina220_read_reg(dev, INA220_REG_POWER, (uint16_t *)power);
return ina2xx_read_reg(dev, INA2XX_REG_POWER, (uint16_t *)power);
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2015 Eistec AB
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup drivers_ina2xx
* @{
*
* @file
* @brief Register definitions for Texas Instruments INA219/INA220
* Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/
#ifndef INA2XX_REGS_H
#define INA2XX_REGS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief INA2XX register addresses
*
* All registers in the INA2XX are 16 bit wide and transmitted MSB first.
*/
typedef enum ina2xx_reg {
INA2XX_REG_CONFIGURATION = 0x00, /**< Configuration register (read/write) */
INA2XX_REG_SHUNT_VOLTAGE = 0x01, /**< Shunt voltage register (read only) */
INA2XX_REG_BUS_VOLTAGE = 0x02, /**< Bus voltage register (read only) */
INA2XX_REG_POWER = 0x03, /**< Power register (read only) */
INA2XX_REG_CURRENT = 0x04, /**< Current register (read only) */
INA2XX_REG_CALIBRATION = 0x05, /**< Calibration register (read/write) */
} ina2xx_reg_t;
#ifdef __cplusplus
}
#endif
#endif /* INA2XX_REGS_H */
/** @} */

View File

@ -7,22 +7,26 @@
*/
/**
* @defgroup drivers_ina220 INA220 current/power monitor
* @defgroup drivers_ina2xx INA2XX current/power monitor
* @ingroup drivers_sensors
* @brief Device driver for Texas Instruments INA220 High or Low Side,
* @brief Device driver for Texas Instruments INA219/INA220
* Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface
*
* # Supported Hardware
* This driver currently supports the INA219 and the INA220 - and possibly
* other devices of the INA2xx family.
*
* @{
*
* @file
* @brief Device driver interface for Texas Instruments INA220 High or Low
* Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire
* Interface
* @brief Device driver interface for Texas Instruments INA219/INA220
* Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/
#ifndef INA220_H
#define INA220_H
#ifndef INA2XX_H
#define INA2XX_H
#include <stdint.h>
@ -33,114 +37,114 @@ extern "C" {
#endif
/**
* @brief Device descriptor for INA220 sensors
* @brief Device descriptor for INA2XX sensors
*/
typedef struct {
i2c_t i2c; /**< I2C device the sensor is connected to */
uint8_t addr; /**< the slave address of the sensor on the I2C bus */
} ina220_t;
} ina2xx_t;
/**
* @brief INA220 possible mode settings
* @brief INA2XX possible mode settings
*/
typedef enum ina220_mode {
INA220_MODE_POWERDOWN = 0x0000, /**< Power down */
INA220_MODE_TRIGGER_SHUNT_ONLY = 0x0001, /**< Shunt Voltage, Triggered */
INA220_MODE_TRIGGER_BUS_ONLY = 0x0002, /**< Bus Voltage, Triggered */
INA220_MODE_TRIGGER_SHUNT_BUS = 0x0003, /**< Shunt and Bus, Triggered */
INA220_MODE_ADC_DISABLE = 0x0004, /**< ADC Off (disabled) */
INA220_MODE_CONTINUOUS_SHUNT_ONLY = 0x0005, /**< Shunt Voltage, Continuous */
INA220_MODE_CONTINUOUS_BUS_ONLY = 0x0006, /**< Bus Voltage, Continuous */
INA220_MODE_CONTINUOUS_SHUNT_BUS = 0x0007, /**< Shunt and Bus, Continuous, default */
} ina220_mode_t;
typedef enum ina2xx_mode {
INA2XX_MODE_POWERDOWN = 0x0000, /**< Power down */
INA2XX_MODE_TRIGGER_SHUNT_ONLY = 0x0001, /**< Shunt Voltage, Triggered */
INA2XX_MODE_TRIGGER_BUS_ONLY = 0x0002, /**< Bus Voltage, Triggered */
INA2XX_MODE_TRIGGER_SHUNT_BUS = 0x0003, /**< Shunt and Bus, Triggered */
INA2XX_MODE_ADC_DISABLE = 0x0004, /**< ADC Off (disabled) */
INA2XX_MODE_CONTINUOUS_SHUNT_ONLY = 0x0005, /**< Shunt Voltage, Continuous */
INA2XX_MODE_CONTINUOUS_BUS_ONLY = 0x0006, /**< Bus Voltage, Continuous */
INA2XX_MODE_CONTINUOUS_SHUNT_BUS = 0x0007, /**< Shunt and Bus, Continuous, default */
} ina2xx_mode_t;
/**
* @brief Shunt voltage measurement range (PGA settings)
*/
typedef enum ina220_range {
INA220_RANGE_40MV = 0x0000, /**< +/- 40 mV range */
INA220_RANGE_80MV = 0x0800, /**< +/- 80 mV range */
INA220_RANGE_160MV = 0x1000, /**< +/- 160 mV range */
INA220_RANGE_320MV = 0x1800, /**< +/- 320 mV range, default */
} ina220_range_t;
typedef enum ina2xx_range {
INA2XX_RANGE_40MV = 0x0000, /**< +/- 40 mV range */
INA2XX_RANGE_80MV = 0x0800, /**< +/- 80 mV range */
INA2XX_RANGE_160MV = 0x1000, /**< +/- 160 mV range */
INA2XX_RANGE_320MV = 0x1800, /**< +/- 320 mV range, default */
} ina2xx_range_t;
/**
* @brief Bus voltage measurement range
*/
typedef enum ina220_brng {
INA220_BRNG_16V_FSR = 0x0000, /**< 16 V bus voltage full scale range */
INA220_BRNG_32V_FSR = 0x2000, /**< 32 V bus voltage full scale range, default. */
} ina220_brng_t;
typedef enum ina2xx_brng {
INA2XX_BRNG_16V_FSR = 0x0000, /**< 16 V bus voltage full scale range */
INA2XX_BRNG_32V_FSR = 0x2000, /**< 32 V bus voltage full scale range, default. */
} ina2xx_brng_t;
/**
* @brief Shunt ADC settings
*
* @see Table 4 in INA220 data sheet
* @see Table 4 in INA2XX data sheet
*/
typedef enum ina220_sadc {
typedef enum ina2xx_sadc {
/** 9 bit resolution, 84 us conversion time */
INA220_SADC_9BIT = 0x0000,
INA2XX_SADC_9BIT = 0x0000,
/** 10 bit resolution, 148 us conversion time */
INA220_SADC_10BIT = 0x0008,
INA2XX_SADC_10BIT = 0x0008,
/** 11 bit resolution, 276 us conversion time */
INA220_SADC_11BIT = 0x0010,
INA2XX_SADC_11BIT = 0x0010,
/** 12 bit resolution, 532 us conversion time, default */
INA220_SADC_12BIT = 0x0018,
/** 12 bit resolution, 532 us conversion time, same as INA220_SADC_12BIT */
INA220_SADC_AVG_1_SAMPLE = 0x0040,
INA2XX_SADC_12BIT = 0x0018,
/** 12 bit resolution, 532 us conversion time, same as INA2XX_SADC_12BIT */
INA2XX_SADC_AVG_1_SAMPLE = 0x0040,
/** 2 sample average, 1.06 ms conversion time */
INA220_SADC_AVG_2_SAMPLES = 0x0048,
INA2XX_SADC_AVG_2_SAMPLES = 0x0048,
/** 4 sample average, 2.13 ms conversion time */
INA220_SADC_AVG_4_SAMPLES = 0x0050,
INA2XX_SADC_AVG_4_SAMPLES = 0x0050,
/** 8 sample average, 4.26 ms conversion time */
INA220_SADC_AVG_8_SAMPLES = 0x0058,
INA2XX_SADC_AVG_8_SAMPLES = 0x0058,
/** 16 sample average, 8.51 ms conversion time */
INA220_SADC_AVG_16_SAMPLES = 0x0060,
INA2XX_SADC_AVG_16_SAMPLES = 0x0060,
/** 32 sample average, 17.02 ms conversion time */
INA220_SADC_AVG_32_SAMPLES = 0x0068,
INA2XX_SADC_AVG_32_SAMPLES = 0x0068,
/** 64 sample average, 34.05 ms conversion time */
INA220_SADC_AVG_64_SAMPLES = 0x0070,
INA2XX_SADC_AVG_64_SAMPLES = 0x0070,
/** 128 sample average, 68.10 ms conversion time */
INA220_SADC_AVG_128_SAMPLES = 0x0078,
} ina220_sadc_t;
INA2XX_SADC_AVG_128_SAMPLES = 0x0078,
} ina2xx_sadc_t;
/**
* @brief Bus ADC settings
*
* @see Table 4 in INA220 data sheet
* @see Table 4 in INA2XX data sheet
*/
typedef enum ina220_badc {
typedef enum ina2xx_badc {
/** 9 bit resolution, 84 us conversion time */
INA220_BADC_9BIT = 0x0000,
INA2XX_BADC_9BIT = 0x0000,
/** 10 bit resolution, 148 us conversion time */
INA220_BADC_10BIT = 0x0080,
INA2XX_BADC_10BIT = 0x0080,
/** 11 bit resolution, 276 us conversion time */
INA220_BADC_11BIT = 0x0100,
INA2XX_BADC_11BIT = 0x0100,
/** 12 bit resolution, 532 us conversion time, default */
INA220_BADC_12BIT = 0x0180,
/** 12 bit resolution, 532 us conversion time, same as INA220_BADC_12BIT */
INA220_BADC_AVG_1_SAMPLE = 0x0400,
INA2XX_BADC_12BIT = 0x0180,
/** 12 bit resolution, 532 us conversion time, same as INA2XX_BADC_12BIT */
INA2XX_BADC_AVG_1_SAMPLE = 0x0400,
/** 2 sample average, 1.06 ms conversion time */
INA220_BADC_AVG_2_SAMPLES = 0x0480,
INA2XX_BADC_AVG_2_SAMPLES = 0x0480,
/** 4 sample average, 2.13 ms conversion time */
INA220_BADC_AVG_4_SAMPLES = 0x0500,
INA2XX_BADC_AVG_4_SAMPLES = 0x0500,
/** 8 sample average, 4.26 ms conversion time */
INA220_BADC_AVG_8_SAMPLES = 0x0580,
INA2XX_BADC_AVG_8_SAMPLES = 0x0580,
/** 16 sample average, 8.51 ms conversion time */
INA220_BADC_AVG_16_SAMPLES = 0x0600,
INA2XX_BADC_AVG_16_SAMPLES = 0x0600,
/** 32 sample average, 17.02 ms conversion time */
INA220_BADC_AVG_32_SAMPLES = 0x0680,
INA2XX_BADC_AVG_32_SAMPLES = 0x0680,
/** 64 sample average, 34.05 ms conversion time */
INA220_BADC_AVG_64_SAMPLES = 0x0700,
INA2XX_BADC_AVG_64_SAMPLES = 0x0700,
/** 128 sample average, 68.10 ms conversion time */
INA220_BADC_AVG_128_SAMPLES = 0x0780,
} ina220_badc_t;
INA2XX_BADC_AVG_128_SAMPLES = 0x0780,
} ina2xx_badc_t;
/** INA220 reset command bit (in configuration register) */
#define INA220_RESET_BIT (0x8000)
/** INA2XX reset command bit (in configuration register) */
#define INA2XX_RESET_BIT (0x8000)
/** Location of the bus voltage in the INA220 bus voltage register */
#define INA220_BUS_VOLTAGE_SHIFT (3)
/** Location of the bus voltage in the INA2XX bus voltage register */
#define INA2XX_BUS_VOLTAGE_SHIFT (3)
/**
* @brief Initialize a current sensor
@ -152,7 +156,7 @@ typedef enum ina220_badc {
* @return 0 on success
* @return <0 on error
*/
int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address);
int ina2xx_init(ina2xx_t *dev, i2c_t i2c, uint8_t address);
/**
* @brief Write to calibration register
@ -163,7 +167,7 @@ int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address);
* @return 0 on success
* @return <0 on error
*/
int ina220_set_calibration(const ina220_t *dev, uint16_t calibration);
int ina2xx_set_calibration(const ina2xx_t *dev, uint16_t calibration);
/**
* @brief Write to configuration register
@ -174,7 +178,7 @@ int ina220_set_calibration(const ina220_t *dev, uint16_t calibration);
* @return 0 on success
* @return <0 on error
*/
int ina220_set_config(const ina220_t *dev, uint16_t config);
int ina2xx_set_config(const ina2xx_t *dev, uint16_t config);
/**
* @brief Read shunt voltage
@ -185,7 +189,7 @@ int ina220_set_config(const ina220_t *dev, uint16_t config);
* @return 0 on success
* @return <0 on error
*/
int ina220_read_shunt(const ina220_t *dev, int16_t *voltage);
int ina2xx_read_shunt(const ina2xx_t *dev, int16_t *voltage);
/**
* @brief Read bus voltage register
@ -201,7 +205,7 @@ int ina220_read_shunt(const ina220_t *dev, int16_t *voltage);
* @return 0 on success
* @return <0 on error
*/
int ina220_read_bus(const ina220_t *dev, int16_t *voltage);
int ina2xx_read_bus(const ina2xx_t *dev, int16_t *voltage);
/**
* @brief Read shunt current
@ -212,7 +216,7 @@ int ina220_read_bus(const ina220_t *dev, int16_t *voltage);
* @return 0 on success
* @return <0 on error
*/
int ina220_read_current(const ina220_t *dev, int16_t *current);
int ina2xx_read_current(const ina2xx_t *dev, int16_t *current);
/**
* @brief Read power consumption
@ -223,11 +227,11 @@ int ina220_read_current(const ina220_t *dev, int16_t *current);
* @return 0 on success
* @return <0 on error
*/
int ina220_read_power(const ina220_t *dev, int16_t *power);
int ina2xx_read_power(const ina2xx_t *dev, int16_t *power);
#ifdef __cplusplus
}
#endif
#endif /* INA220_H */
#endif /* INA2XX_H */
/** @} */

View File

@ -124,6 +124,10 @@ PSEUDOMODULES += cc1101
PSEUDOMODULES += mpu9150
PSEUDOMODULES += mpu9250
# include variants of INA2xx drivers as pseudo modules
PSEUDOMODULES += ina219
PSEUDOMODULES += ina220
# include variants of mrf24j40 drivers as pseudo modules
PSEUDOMODULES += mrf24j40m%

View File

@ -4,11 +4,11 @@ USEMODULE += ina220
USEMODULE += xtimer
# set default device parameters in case they are undefined
TEST_INA220_I2C ?= I2C_DEV\(0\)
TEST_INA220_ADDR ?= 0x40
TEST_INA2XX_I2C ?= I2C_DEV\(0\)
TEST_INA2XX_ADDR ?= 0x40
# export parameters
CFLAGS += -DTEST_INA220_I2C=$(TEST_INA220_I2C)
CFLAGS += -DTEST_INA220_ADDR=$(TEST_INA220_ADDR)
CFLAGS += -DTEST_INA2XX_I2C=$(TEST_INA2XX_I2C)
CFLAGS += -DTEST_INA2XX_ADDR=$(TEST_INA2XX_ADDR)
include $(RIOTBASE)/Makefile.include

View File

@ -1,5 +1,6 @@
# About
This is a manual test application for the INA220 current and power monitor driver.
This is a manual test application for the INA210/INA220 current and power
monitor driver.
# Usage
This test application will initialize the sensor with the following parameters:

View File

@ -11,24 +11,24 @@
* @{
*
* @file
* @brief Test application for the INA220 sensor driver
* @brief Test application for the INA2XX sensor driver
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*
* @}
*/
#ifndef TEST_INA220_I2C
#error "TEST_INA220_I2C not defined"
#ifndef TEST_INA2XX_I2C
#error "TEST_INA2XX_I2C not defined"
#endif
#ifndef TEST_INA220_ADDR
#error "TEST_INA220_ADDR not defined"
#ifndef TEST_INA2XX_ADDR
#error "TEST_INA2XX_ADDR not defined"
#endif
#include <stdio.h>
#include "xtimer.h"
#include "ina220.h"
#include "ina2xx.h"
/* Use the following configuration:
*
@ -37,28 +37,28 @@
* - 32 V maximum bus voltage
* - 12 bit ADC resolution, no hardware averaging
*/
#define CONFIG (INA220_MODE_CONTINUOUS_SHUNT_BUS | INA220_RANGE_320MV | \
INA220_BRNG_32V_FSR | INA220_SADC_12BIT | INA220_BADC_12BIT)
#define CONFIG (INA2XX_MODE_CONTINUOUS_SHUNT_BUS | INA2XX_RANGE_320MV | \
INA2XX_BRNG_32V_FSR | INA2XX_SADC_12BIT | INA2XX_BADC_12BIT)
#define CALIBRATION (4096)
#define SLEEP_USEC (100 * 1000U)
int main(void)
{
ina220_t dev;
ina2xx_t dev;
int16_t val;
puts("INA220 sensor driver test application\n");
puts("INA2XX sensor driver test application\n");
printf("Initializing INA220 sensor at I2C_%i, address 0x%02x... ",
TEST_INA220_I2C, TEST_INA220_ADDR);
if (ina220_init(&dev, TEST_INA220_I2C, TEST_INA220_ADDR) == 0) {
printf("Initializing INA2XX sensor at I2C_%i, address 0x%02x... ",
TEST_INA2XX_I2C, TEST_INA2XX_ADDR);
if (ina2xx_init(&dev, TEST_INA2XX_I2C, TEST_INA2XX_ADDR) == 0) {
puts("[OK]\n");
} else {
puts("[Failed]");
return 1;
}
puts("Set configuration register");
if (ina220_set_config(&dev, CONFIG) == 0) {
if (ina2xx_set_config(&dev, CONFIG) == 0) {
puts("[OK]\n");
} else {
puts("[Failed]");
@ -66,7 +66,7 @@ int main(void)
}
puts("Set calibration register");
if (ina220_set_calibration(&dev, CALIBRATION) == 0) {
if (ina2xx_set_calibration(&dev, CALIBRATION) == 0) {
puts("[OK]\n");
} else {
puts("[Failed]");
@ -75,24 +75,24 @@ int main(void)
while (1) {
/* Read shunt resistor voltage, in millivolts */
ina220_read_shunt(&dev, &val);
ina2xx_read_shunt(&dev, &val);
printf("shunt: %6d", val);
/* Read VBUS voltage, in millivolts */
ina220_read_bus(&dev, &val);
ina2xx_read_bus(&dev, &val);
/* The bus voltage is found in the topmost 13 bits of the bus voltage
* register */
val = (val >> INA220_BUS_VOLTAGE_SHIFT);
val = (val >> INA2XX_BUS_VOLTAGE_SHIFT);
printf("\tbus: %6d", val);
/* Read current register, the scale depends on the value of the
* calibration register */
ina220_read_current(&dev, &val);
ina2xx_read_current(&dev, &val);
printf("\tcurrent: %6d", val);
/* Read power register, the scale depends on the value of the
* calibration register */
ina220_read_power(&dev, &val);
ina2xx_read_power(&dev, &val);
printf("\tpower: %6d\n", val);
xtimer_usleep(SLEEP_USEC);