INA3221 current/power monitor

Device driver for Texas Instruments INA3221 three-channel ,high-side current and bus voltage monitor. More...

Detailed Description

Device driver for Texas Instruments INA3221 three-channel ,high-side current and bus voltage monitor.

Files

file  ina3221_defines.h
 Internal definitions for Texas Instruments INA3221 three-channel, high-side current and bus voltage monitor.
 
file  ina3221_internal.h
 Functions to convert register values of INA3221 to actual voltage values and vice versa.
 
file  ina3221_params.h
 Driver configuration parameters for Texas Instruments INA3221 three-channel, high-side current and bus voltage monitor.
 
file  ina3221_regs.h
 Register definitions for Texas Instruments INA3221 three-channel, high-side current and bus voltage monitor.
 
file  ina3221.h
 Device driver interface for Texas Instruments INA3221 three-channel ,high-side current and bus voltage monitor.
 

Data Structures

struct  ina3221_params_t
 INA3221 device parameters. More...
 
struct  ina3221_t
 INA3221 device handle struct. More...
 

Macros

#define INA3221_NUM_CH   (3)
 Number of channels.
 
#define INA3221_NUM_ALERTS   (4)
 Number of alerts.
 
#define INA3221_MODE_MASK   (0x0007)
 Device operation mode bit mask.
 
#define INA3221_CONV_TIME_SADC_MASK   (0x0038)
 ADC shunt voltage conversion times bit mask.
 
#define INA3221_CONV_TIME_BADC_MASK   (0x01C0)
 ADC bus voltage conversion times bit mask.
 
#define INA3221_NUM_SAMPLES_MASK   (0x0E00)
 Number of samples to calculate average shunt/bus voltage value bit mask.
 
#define INA3221_ENABLE_CH_MASK
 Enable channel bit mask. More...
 
#define INA3221_ENABLE_SUM_CH_MASK
 Enable shunt voltage sum calculation channel bit mask. More...
 
#define INA3221_ENABLE_LATCH_MASK
 Enable latch bit mask. More...
 
#define INA3221_DEFCONFIG   (0x7127)
 Default configuration register value.
 
#define INA3221_RESET   (0x8000)
 Reset configuration register value.
 
#define INA3221_FLAG_CRIT_ALERT_CH1   (0x0200)
 Critical alert channel 1 flag.
 
#define INA3221_FLAG_CRIT_ALERT_CH2   (0x0100)
 Critical alert channel 2 flag.
 
#define INA3221_FLAG_CRIT_ALERT_CH3   (0x0080)
 Critical alert channel 3 flag.
 
#define INA3221_FLAG_SHUNT_SUM_ALERT   (0x0040)
 Alert channel sum flag.
 
#define INA3221_FLAG_WARN_ALERT_CH1   (0x0020)
 Warning alert channel 1 flag.
 
#define INA3221_FLAG_WARN_ALERT_CH2   (0x0010)
 Warning alert channel 2 flag.
 
#define INA3221_FLAG_WARN_ALERT_CH3   (0x0008)
 Warning alert channel 3 flag.
 
#define INA3221_FLAG_POWER_VALID   (0x0004)
 Power valid flag.
 
#define INA3221_FLAG_TIMING_CONTROL   (0x0002)
 Timing Control flag.
 
#define INA3221_FLAG_CONV_READY   (0x0001)
 Conversion ready flag.
 
#define INA3221_FLAGS_MASK
 Flags bit mask. More...
 
#define INA3221_TRIGGER_SHUNT(dev)   ina3221_set_mode(dev, INA3221_MODE_TRIGGER_SHUNT_ONLY)
 Set operation mode to INA3221_MODE_TRIGGER_SHUNT_ONLY to trigger shunt voltage measurement. More...
 
#define INA3221_TRIGGER_BUS(dev)   ina3221_set_mode(dev, INA3221_MODE_TRIGGER_BUS_ONLY)
 Set operation mode to INA3221_MODE_TRIGGER_BUS_ONLY to trigger bus voltage measurement. More...
 
#define INA3221_TRIGGER_SHUNT_AND_BUS(dev)   ina3221_set_mode(dev, INA3221_MODE_TRIGGER_SHUNT_BUS)
 Set operation mode to INA3221_MODE_TRIGGER_SHUNT_BUS to trigger shunt and bus voltage measurement. More...
 

Typedefs

typedef void(* ina3221_alert_cb_t) (void *arg)
 INA3221 alert callback for alert pins CRT, WRN, TC, PV.
 
typedef enum ina3221_ret_val ina3221_ret_val_t
 Return codes.
 
typedef enum ina3221_dev_addr ina3221_dav_addr_t
 I2C device addresses.
 
typedef enum ina3221_channel ina3221_channel_t
 Channel flags.
 
typedef enum ina3221_alert ina3221_alert_t
 Alert indices.
 
typedef enum ina3221_mode ina3221_mode_t
 Device operation modes.
 
typedef enum ina3221_conv_time_shunt_adc ina3221_conv_time_shunt_adc_t
 ADC shunt voltage conversion times.
 
typedef enum ina3221_conv_time_bus_adc ina3221_conv_time_bus_adc_t
 ADC bus voltage conversion times.
 
typedef enum ina3221_num_samples ina3221_num_samples_t
 Number of samples to calculate average shunt/bus voltage value.
 
typedef enum ina3221_enable_ch ina3221_enable_ch_t
 Enable channel flags.
 
typedef enum ina3221_channel_state ina3221_channel_state_t
 Channel state enabled/disabled.
 
typedef enum ina3221_enable_sum_ch ina3221_enable_sum_ch_t
 Enable shunt voltage sum calculation channel flags.
 
typedef enum ina3221_enable_latch ina3221_enable_latch_t
 Enable latch flags.
 

Enumerations

enum  ina3221_ret_val {
  INA3221_OK, INA3221_I2C_ERROR, INA3221_BAD_MANUF_ID, INA3221_BAD_DIE_ID,
  INA3221_RESET_FAILED, INA3221_CONFIG_FAILED
}
 Return codes. More...
 
enum  ina3221_dev_addr { INA3221_ADDR_00 = 0x40, INA3221_ADDR_01 = 0x41, INA3221_ADDR_10 = 0x42, INA3221_ADDR_11 = 0x43 }
 I2C device addresses. More...
 
enum  ina3221_channel { INA3221_CH1 = (1 << 0), INA3221_CH2 = (1 << 1), INA3221_CH3 = (1 << 2) }
 Channel flags. More...
 
enum  ina3221_alert { INA3221_ALERT_WRN = 0, INA3221_ALERT_CRT = 1, INA3221_ALERT_TC = 2, INA3221_ALERT_PV = 3 }
 Alert indices. More...
 
enum  ina3221_mode {
  INA3221_MODE_POWER_DOWN = 0x0000, INA3221_MODE_TRIGGER_SHUNT_ONLY = 0x0001, INA3221_MODE_TRIGGER_BUS_ONLY = 0x0002, INA3221_MODE_TRIGGER_SHUNT_BUS = 0x0003,
  INA3221_MODE_POWER_DOWN_ = 0x0004, INA3221_MODE_CONTINUOUS_SHUNT_ONLY = 0x0005, INA3221_MODE_CONTINUOUS_BUS_ONLY = 0x0006, INA3221_MODE_CONTINUOUS_SHUNT_BUS = 0x0007
}
 Device operation modes. More...
 
enum  ina3221_conv_time_shunt_adc {
  INA3221_CONV_TIME_SADC_140US = 0x0000, INA3221_CONV_TIME_SADC_204US = 0x0008, INA3221_CONV_TIME_SADC_332US = 0x0010, INA3221_CONV_TIME_SADC_588US = 0x0018,
  INA3221_CONV_TIME_SADC_1100US = 0x0020, INA3221_CONV_TIME_SADC_2116US = 0x0028, INA3221_CONV_TIME_SADC_4156US = 0x0030, INA3221_CONV_TIME_SADC_8244US = 0x0038
}
 ADC shunt voltage conversion times. More...
 
enum  ina3221_conv_time_bus_adc {
  INA3221_CONV_TIME_BADC_140US = 0x0000, INA3221_CONV_TIME_BADC_204US = 0x0040, INA3221_CONV_TIME_BADC_332US = 0x0080, INA3221_CONV_TIME_BADC_588US = 0x00C0,
  INA3221_CONV_TIME_BADC_1100US = 0x0100, INA3221_CONV_TIME_BADC_2116US = 0x0140, INA3221_CONV_TIME_BADC_4156US = 0x0180, INA3221_CONV_TIME_BADC_8244US = 0x01C0
}
 ADC bus voltage conversion times. More...
 
enum  ina3221_num_samples {
  INA3221_NUM_SAMPLES_1 = 0x0000, INA3221_NUM_SAMPLES_4 = 0x0200, INA3221_NUM_SAMPLES_16 = 0x0400, INA3221_NUM_SAMPLES_64 = 0x0600,
  INA3221_NUM_SAMPLES_128 = 0x0800, INA3221_NUM_SAMPLES_256 = 0x0A00, INA3221_NUM_SAMPLES_512 = 0x0C00, INA3221_NUM_SAMPLES_1024 = 0x0E00
}
 Number of samples to calculate average shunt/bus voltage value. More...
 
enum  ina3221_enable_ch { INA3221_ENABLE_CH1 = 0x4000, INA3221_ENABLE_CH2 = 0x2000, INA3221_ENABLE_CH3 = 0x1000 }
 Enable channel flags. More...
 
enum  ina3221_channel_state { INA3221_CH_DISABLE, INA3221_CH_ENABLE }
 Channel state enabled/disabled. More...
 
enum  ina3221_enable_sum_ch { INA3221_ENABLE_SUM_CH1 = 0x4000, INA3221_ENABLE_SUM_CH2 = 0x2000, INA3221_ENABLE_SUM_CH3 = 0x1000 }
 Enable shunt voltage sum calculation channel flags. More...
 
enum  ina3221_enable_latch { INA3221_ENABLE_WARN_LATCH = 0x0800, INA3221_ENABLE_CRIT_LATCH = 0x0400 }
 Enable latch flags. More...
 

Functions

int ina3221_reset (ina3221_t *dev)
 Reset device, i.e. More...
 
int ina3221_init (ina3221_t *dev, const ina3221_params_t *params)
 Initialize device. More...
 
int _ina3221_enable_alert (ina3221_t *dev, ina3221_alert_t alert, ina3221_alert_cb_t cb, void *arg)
 Enable alert callback and argument for alert alert. More...
 
static int ina3221_enable_warning_alert (ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
 Wrapper around. More...
 
static int ina3221_enable_critical_alert (ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
 Wrapper around. More...
 
static int ina3221_enable_timing_control_alert (ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
 Wrapper around. More...
 
static int ina3221_enable_power_valid_alert (ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
 Wrapper around. More...
 
int _ina3221_disable_alert (ina3221_t *dev, ina3221_alert_t alert)
 Disable alert callback and argument for alert alert. More...
 
static int ina3221_disable_warning_alert (ina3221_t *dev)
 Wrapper around. More...
 
static int ina3221_disable_critical_alert (ina3221_t *dev)
 Wrapper around. More...
 
static int ina3221_disable_timing_control_alert (ina3221_t *dev)
 Wrapper around. More...
 
static int ina3221_disable_power_valid_alert (ina3221_t *dev)
 Wrapper around. More...
 
int _ina3221_set_config (ina3221_t *dev, uint16_t cfg)
 Write configuration register value to configuration register. More...
 
static int ina3221_set_config (ina3221_t *dev, ina3221_enable_ch_t chs, ina3221_num_samples_t ns, ina3221_conv_time_bus_adc_t ctbadc, ina3221_conv_time_shunt_adc_t ctsadc, ina3221_mode_t mode)
 Wrapper around. More...
 
int _ina3221_get_config (const ina3221_t *dev, uint16_t *cfg)
 Read currently saved configuration register value. More...
 
static int ina3221_get_config (const ina3221_t *dev, ina3221_enable_ch_t *chs, ina3221_num_samples_t *ns, ina3221_conv_time_bus_adc_t *ctbadc, ina3221_conv_time_shunt_adc_t *ctsadc, ina3221_mode_t *mode)
 Wrapper around. More...
 
int _ina3221_set_enable_channel (ina3221_t *dev, ina3221_enable_ch_t ech)
 Enable channels. More...
 
static int ina3221_set_channel_state (ina3221_t *dev, ina3221_channel_state_t ch1, ina3221_channel_state_t ch2, ina3221_channel_state_t ch3)
 Wrapper around. More...
 
int _ina3221_get_enable_channel (const ina3221_t *dev, ina3221_enable_ch_t *ech)
 Read which channels are currently enabled. More...
 
static int ina3221_get_channel_state (const ina3221_t *dev, ina3221_channel_state_t *ch1, ina3221_channel_state_t *ch2, ina3221_channel_state_t *ch3)
 Wrapper around _ina3221_get_enable_channel. More...
 
int ina3221_set_num_samples (ina3221_t *dev, ina3221_num_samples_t ns)
 Update number of samples and write to configuration register. More...
 
int ina3221_get_num_samples (const ina3221_t *dev, ina3221_num_samples_t *ns)
 Read currently applied number of samples. More...
 
int ina3221_set_conv_time_bus_adc (ina3221_t *dev, ina3221_conv_time_bus_adc_t ctb)
 Update conversion time of bus voltage ADC and write to configuration register. More...
 
int ina3221_get_conv_time_bus_adc (const ina3221_t *dev, ina3221_conv_time_bus_adc_t *ctb)
 Read currently applied bus voltage ADC conversion time. More...
 
int ina3221_set_conv_time_shunt_adc (ina3221_t *dev, ina3221_conv_time_shunt_adc_t cts)
 Update conversion time of shunt voltage ADC and write to configuration register. More...
 
int ina3221_get_conv_time_shunt_adc (const ina3221_t *dev, ina3221_conv_time_shunt_adc_t *cts)
 Read currently applied shunt voltage ADC conversion time. More...
 
int ina3221_set_mode (ina3221_t *dev, ina3221_mode_t mode)
 Update device operation mode. More...
 
int ina3221_get_mode (const ina3221_t *dev, ina3221_mode_t *mode)
 Read currently applied device operation mode. More...
 
int _ina3221_set_enable_sum_channel (const ina3221_t *dev, ina3221_enable_sum_ch_t esch)
 Enable channels for shunt voltage sum calculation. More...
 
static int ina3221_set_enable_sum_channel (const ina3221_t *dev, ina3221_channel_state_t ch1, ina3221_channel_state_t ch2, ina3221_channel_state_t ch3)
 Wrapper around. More...
 
int _ina3221_get_enable_sum_channel (const ina3221_t *dev, ina3221_enable_sum_ch_t *esch)
 Read enabled channels for shunt voltage sum calculation. More...
 
static int ina3221_get_enable_sum_channel (const ina3221_t *dev, ina3221_channel_state_t *ch1, ina3221_channel_state_t *ch2, ina3221_channel_state_t *ch3)
 Wrapper for. More...
 
int ina3221_set_latch (const ina3221_t *dev, ina3221_enable_latch_t latch)
 Enable latches for critical/warning alert pins. More...
 
int ina3221_get_latch (const ina3221_t *dev, ina3221_enable_latch_t *latch)
 Read enabled latches for critical/warning alert pins. More...
 
int ina3221_set_crit_alert_limit (const ina3221_t *dev, ina3221_channel_t ch, int32_t in_uv)
 Set critical shunt voltage alert limit to in_uv for each channel in ch. More...
 
int ina3221_get_crit_alert_limit (const ina3221_t *dev, ina3221_channel_t ch, int32_t *out_uv)
 Read critical shunt voltage alert limit for each channel in ch. More...
 
int ina3221_set_warn_alert_limit (const ina3221_t *dev, ina3221_channel_t ch, int32_t in_uv)
 Set warning shunt voltage alert limit to in_uv for each channel in ch. More...
 
int ina3221_get_warn_alert_limit (const ina3221_t *dev, ina3221_channel_t ch, int32_t *out_uv)
 Read warning shunt voltage alert limit for each channel in ch. More...
 
int ina3221_set_shunt_voltage_sum_alert_limit (const ina3221_t *dev, int32_t in_uv)
 Set shunt voltage sum alert limit to in_uv. More...
 
int ina3221_get_shunt_voltage_sum_alert_limit (const ina3221_t *dev, int32_t *out_uv)
 Read shunt voltage sum alert limit. More...
 
int ina3221_set_power_valid_upper_limit (const ina3221_t *dev, int32_t in_mv)
 Set bus voltage power valid upper limit to in_mv. More...
 
int ina3221_get_power_valid_upper_limit (const ina3221_t *dev, int32_t *out_mv)
 Read bus voltage power valid upper limit. More...
 
int ina3221_set_power_valid_lower_limit (const ina3221_t *dev, int32_t in_mv)
 Set bus voltage power valid lower limit to in_mv. More...
 
int ina3221_get_power_valid_lower_limit (const ina3221_t *dev, int32_t *out_mv)
 Read bus voltage power valid lower limit. More...
 
int ina3221_read_flags (const ina3221_t *dev, uint16_t *flags)
 Read status flags. More...
 
int ina3221_read_shunt_sum_uv (const ina3221_t *dev, int32_t *out_uv, uint16_t *flags)
 Read sum of shunt voltages. More...
 
int ina3221_read_shunt_uv (const ina3221_t *dev, ina3221_channel_t ch, int32_t *out_uv, uint16_t *flags)
 Read shunt voltages for each channel in ch. More...
 
int ina3221_read_bus_mv (const ina3221_t *dev, ina3221_channel_t ch, int16_t *out_mv, uint16_t *flags)
 Read bus voltages for each channel in ch. More...
 
int ina3221_calculate_current_ua (const ina3221_t *dev, ina3221_channel_t ch, int32_t *in_uv, int32_t *out_ma)
 Calculate current for each channel in ch. More...
 
int ina3221_calculate_power_uw (int16_t *in_mv, int32_t *in_ua, uint8_t num, int32_t *out_mw)
 Calculate power from bus voltage and current values. More...
 
void ina3221_ch_align (ina3221_channel_t ch, const void *in_res, void *out_res, size_t res_val_size)
 Align in_res to the number of channels For example: ch = (INA3221_CH1 | INA3221_CH3) in_res = {value_ch1, value_ch3}, then out_res will be {value_ch1, 0, value_ch3}. More...
 

Macro Definition Documentation

◆ INA3221_ENABLE_CH_MASK

#define INA3221_ENABLE_CH_MASK
Value:

Enable channel bit mask.

Definition at line 194 of file ina3221.h.

◆ INA3221_ENABLE_LATCH_MASK

#define INA3221_ENABLE_LATCH_MASK
Value:

Enable latch bit mask.

Definition at line 225 of file ina3221.h.

◆ INA3221_ENABLE_SUM_CH_MASK

#define INA3221_ENABLE_SUM_CH_MASK
Value:

Enable shunt voltage sum calculation channel bit mask.

Definition at line 214 of file ina3221.h.

◆ INA3221_FLAGS_MASK

◆ INA3221_TRIGGER_BUS

#define INA3221_TRIGGER_BUS (   dev)    ina3221_set_mode(dev, INA3221_MODE_TRIGGER_BUS_ONLY)

Set operation mode to INA3221_MODE_TRIGGER_BUS_ONLY to trigger bus voltage measurement.

Parameters
devDevice handle

Definition at line 1101 of file ina3221.h.

◆ INA3221_TRIGGER_SHUNT

#define INA3221_TRIGGER_SHUNT (   dev)    ina3221_set_mode(dev, INA3221_MODE_TRIGGER_SHUNT_ONLY)

Set operation mode to INA3221_MODE_TRIGGER_SHUNT_ONLY to trigger shunt voltage measurement.

Parameters
devDevice handle

Definition at line 1093 of file ina3221.h.

◆ INA3221_TRIGGER_SHUNT_AND_BUS

#define INA3221_TRIGGER_SHUNT_AND_BUS (   dev)    ina3221_set_mode(dev, INA3221_MODE_TRIGGER_SHUNT_BUS)

Set operation mode to INA3221_MODE_TRIGGER_SHUNT_BUS to trigger shunt and bus voltage measurement.

Parameters
devDevice handle

Definition at line 1109 of file ina3221.h.

Enumeration Type Documentation

◆ ina3221_alert

Alert indices.

Enumerator
INA3221_ALERT_WRN 

Warning alert.

INA3221_ALERT_CRT 

Critical alert.

INA3221_ALERT_TC 

Timing control.

INA3221_ALERT_PV 

Power valid alert.

Definition at line 119 of file ina3221.h.

◆ ina3221_channel

Channel flags.

Enumerator
INA3221_CH1 

Channel 1.

INA3221_CH2 

Channel 2.

INA3221_CH3 

Channel 3.

Definition at line 110 of file ina3221.h.

◆ ina3221_channel_state

Channel state enabled/disabled.

Enumerator
INA3221_CH_DISABLE 

Channel disabled.

INA3221_CH_ENABLE 

Channel enabled.

Definition at line 201 of file ina3221.h.

◆ ina3221_conv_time_bus_adc

ADC bus voltage conversion times.

Enumerator
INA3221_CONV_TIME_BADC_140US 

140 us

INA3221_CONV_TIME_BADC_204US 

204 us

INA3221_CONV_TIME_BADC_332US 

332 us

INA3221_CONV_TIME_BADC_588US 

588 us

INA3221_CONV_TIME_BADC_1100US 

1100 us

INA3221_CONV_TIME_BADC_2116US 

2116 us

INA3221_CONV_TIME_BADC_4156US 

4156 us

INA3221_CONV_TIME_BADC_8244US 

8244 us

Definition at line 159 of file ina3221.h.

◆ ina3221_conv_time_shunt_adc

ADC shunt voltage conversion times.

Enumerator
INA3221_CONV_TIME_SADC_140US 

140 us

INA3221_CONV_TIME_SADC_204US 

204 us

INA3221_CONV_TIME_SADC_332US 

332 us

INA3221_CONV_TIME_SADC_588US 

588 us

INA3221_CONV_TIME_SADC_1100US 

1100 us

INA3221_CONV_TIME_SADC_2116US 

2116 us

INA3221_CONV_TIME_SADC_4156US 

4156 us

INA3221_CONV_TIME_SADC_8244US 

8244 us

Definition at line 144 of file ina3221.h.

◆ ina3221_dev_addr

I2C device addresses.

Enumerator
INA3221_ADDR_00 

A0 connected to GND.

INA3221_ADDR_01 

A0 connected to VS

INA3221_ADDR_10 

A0 connected to SDA.

INA3221_ADDR_11 

A0 connected to SCL.

Definition at line 100 of file ina3221.h.

◆ ina3221_enable_ch

Enable channel flags.

Enumerator
INA3221_ENABLE_CH1 

Enable channel 1.

INA3221_ENABLE_CH2 

Enable channel 2.

INA3221_ENABLE_CH3 

Enable channel 3.

Definition at line 189 of file ina3221.h.

◆ ina3221_enable_latch

Enable latch flags.

Enumerator
INA3221_ENABLE_WARN_LATCH 

Enable warning alert latch.

INA3221_ENABLE_CRIT_LATCH 

Enable critical alert latch.

Definition at line 221 of file ina3221.h.

◆ ina3221_enable_sum_ch

Enable shunt voltage sum calculation channel flags.

Enumerator
INA3221_ENABLE_SUM_CH1 

Enable sum channel 1.

INA3221_ENABLE_SUM_CH2 

Enable sum channel 2.

INA3221_ENABLE_SUM_CH3 

Enable sum channel 3.

Definition at line 209 of file ina3221.h.

◆ ina3221_mode

Device operation modes.

Enumerator
INA3221_MODE_POWER_DOWN 

Sleep mode.

INA3221_MODE_TRIGGER_SHUNT_ONLY 

Trigger shunt voltage measurement only.

INA3221_MODE_TRIGGER_BUS_ONLY 

Trigger bus voltage measurement only.

INA3221_MODE_TRIGGER_SHUNT_BUS 

Trigger shunt and bus voltage measurement.

INA3221_MODE_POWER_DOWN_ 

Also power down (see datasheet)

INA3221_MODE_CONTINUOUS_SHUNT_ONLY 

Continuous shunt voltage measurement only.

INA3221_MODE_CONTINUOUS_BUS_ONLY 

Continuous bus voltage measurement only.

INA3221_MODE_CONTINUOUS_SHUNT_BUS 

Continuous shunt and bus voltage measurement.

Definition at line 129 of file ina3221.h.

◆ ina3221_num_samples

Number of samples to calculate average shunt/bus voltage value.

Enumerator
INA3221_NUM_SAMPLES_1 

1

INA3221_NUM_SAMPLES_4 

4

INA3221_NUM_SAMPLES_16 

16

INA3221_NUM_SAMPLES_64 

64

INA3221_NUM_SAMPLES_128 

128

INA3221_NUM_SAMPLES_256 

256

INA3221_NUM_SAMPLES_512 

512

INA3221_NUM_SAMPLES_1024 

1024

Definition at line 174 of file ina3221.h.

◆ ina3221_ret_val

Return codes.

Enumerator
INA3221_OK 

Everything is fine.

INA3221_I2C_ERROR 

I2C bus acquirenment failed.

INA3221_BAD_MANUF_ID 

Read device manufacturer ID failed.

INA3221_BAD_DIE_ID 

Read device DIE ID failed.

INA3221_RESET_FAILED 

Device reset failed.

INA3221_CONFIG_FAILED 

Device configuration failed.

Definition at line 88 of file ina3221.h.

Function Documentation

◆ _ina3221_disable_alert()

int _ina3221_disable_alert ( ina3221_t dev,
ina3221_alert_t  alert 
)

Disable alert callback and argument for alert alert.

Parameters
[in,out]devDevice handle
[in]alertAlert index
Returns
INA3221_OK, on success
-ERANGE, if alert was out of bounds
-ENUTSUP, if alert pin was initialized with GPIO_UNDEF

◆ _ina3221_enable_alert()

int _ina3221_enable_alert ( ina3221_t dev,
ina3221_alert_t  alert,
ina3221_alert_cb_t  cb,
void *  arg 
)

Enable alert callback and argument for alert alert.

Parameters
[in,out]devDevice handle
[in]alertAlert index
[in]cbAlert callback
[in]argAlert callback argument
Returns
INA3221_OK, on success
-ERANGE, if alert was out of bounds
-ENUTSUP, if alert pin was initialized with GPIO_UNDEF

◆ _ina3221_get_config()

int _ina3221_get_config ( const ina3221_t dev,
uint16_t *  cfg 
)

Read currently saved configuration register value.

Parameters
[in]devDevice handle
[out]cfgPointer to configuration register output value in host byte order
Returns
INA3221_OK

◆ _ina3221_get_enable_channel()

int _ina3221_get_enable_channel ( const ina3221_t dev,
ina3221_enable_ch_t ech 
)

Read which channels are currently enabled.

Parameters
[in]devDevice handle
[out]echPointer to enabled channels output variable
Returns
Number of enabled channels

◆ _ina3221_get_enable_sum_channel()

int _ina3221_get_enable_sum_channel ( const ina3221_t dev,
ina3221_enable_sum_ch_t esch 
)

Read enabled channels for shunt voltage sum calculation.

Parameters
[in]devDevice handle
[out]eschPointer to enabled channels for shunt voltage sum calculation output variable
Returns
Number of enabled channels for shunt voltage sum calculation, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ _ina3221_set_config()

int _ina3221_set_config ( ina3221_t dev,
uint16_t  cfg 
)

Write configuration register value to configuration register.

Parameters
[in,out]devDevice handle
[in]cfgConfiguration register value in host byte order
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_write_regs

◆ _ina3221_set_enable_channel()

int _ina3221_set_enable_channel ( ina3221_t dev,
ina3221_enable_ch_t  ech 
)

Enable channels.

Parameters
[in,out]devDevice handle
[in]echChannel enable flags
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ _ina3221_set_enable_sum_channel()

int _ina3221_set_enable_sum_channel ( const ina3221_t dev,
ina3221_enable_sum_ch_t  esch 
)

Enable channels for shunt voltage sum calculation.

Parameters
[in]devDevice handle
[in]eschEnable channel shunt voltage sum flags in host byte order
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_calculate_current_ua()

int ina3221_calculate_current_ua ( const ina3221_t dev,
ina3221_channel_t  ch,
int32_t *  in_uv,
int32_t *  out_ma 
)

Calculate current for each channel in ch.

Parameters
[in]devDevice handle
[in]chChannel flags
[in]in_uvArray of input shunt voltage values
[out]out_maArray of output current values
Returns
Number of clculated current values

◆ ina3221_calculate_power_uw()

int ina3221_calculate_power_uw ( int16_t *  in_mv,
int32_t *  in_ua,
uint8_t  num,
int32_t *  out_mw 
)

Calculate power from bus voltage and current values.

Parameters
[in]in_mvArray of input bus voltage values in mV
[in]in_uaArray of input current values in uA
[in]numNumber of values in in_mv
[out]out_mwArray of output power values in uW
Returns
Number of calculated power values, on success
-ERANGE, if num is greater than INA3221_NUM_CH

◆ ina3221_ch_align()

void ina3221_ch_align ( ina3221_channel_t  ch,
const void *  in_res,
void *  out_res,
size_t  res_val_size 
)

Align in_res to the number of channels For example: ch = (INA3221_CH1 | INA3221_CH3) in_res = {value_ch1, value_ch3}, then out_res will be {value_ch1, 0, value_ch3}.

Parameters
[in]chChannel flags
[in]in_resOutput of e.g.
See also
ina3221_calculate_current_ua
Parameters
[out]out_resChannel aligned result
[in]res_val_sizeSize of a value in in_res in bytes

◆ ina3221_disable_critical_alert()

static int ina3221_disable_critical_alert ( ina3221_t dev)
inlinestatic

Wrapper around.

See also
_ina3221_disable_alert, to disable critical alert
Parameters
[in,out]devDevice handle
Returns
See also
_ina3221_disable_alert

Definition at line 470 of file ina3221.h.

◆ ina3221_disable_power_valid_alert()

static int ina3221_disable_power_valid_alert ( ina3221_t dev)
inlinestatic

Wrapper around.

See also
_ina3221_disable_alert, to disable power valid alert
Parameters
[in,out]devDevice handle
Returns
See also
_ina3221_disable_alert

Definition at line 496 of file ina3221.h.

◆ ina3221_disable_timing_control_alert()

static int ina3221_disable_timing_control_alert ( ina3221_t dev)
inlinestatic

Wrapper around.

See also
_ina3221_disable_alert, to disable timing control alert
Parameters
[in,out]devDevice handle
Returns
See also
_ina3221_disable_alert

Definition at line 483 of file ina3221.h.

◆ ina3221_disable_warning_alert()

static int ina3221_disable_warning_alert ( ina3221_t dev)
inlinestatic

Wrapper around.

See also
_ina3221_disable_alert, to disable warning alert
Parameters
[in,out]devDevice handle
Returns
See also
_ina3221_disable_alert

Definition at line 457 of file ina3221.h.

◆ ina3221_enable_critical_alert()

static int ina3221_enable_critical_alert ( ina3221_t dev,
ina3221_alert_cb_t  cb,
void *  arg 
)
inlinestatic

Wrapper around.

See also
_ina3221_enable_alert, to enable critical alert
Parameters
[in,out]devDevice handle
[in]cbAlert callback
[in]argAlert callback argument
Returns
See also
_ina3221_enable_alert

Definition at line 396 of file ina3221.h.

◆ ina3221_enable_power_valid_alert()

static int ina3221_enable_power_valid_alert ( ina3221_t dev,
ina3221_alert_cb_t  cb,
void *  arg 
)
inlinestatic

Wrapper around.

See also
_ina3221_enable_alert, to enable power valid alert
Parameters
[in,out]devDevice handle
[in]cbAlert callback
[in]argAlert callback argument
Returns
See also
_ina3221_enable_alert

Definition at line 430 of file ina3221.h.

◆ ina3221_enable_timing_control_alert()

static int ina3221_enable_timing_control_alert ( ina3221_t dev,
ina3221_alert_cb_t  cb,
void *  arg 
)
inlinestatic

Wrapper around.

See also
_ina3221_enable_alert, to enable timing control alert
Parameters
[in,out]devDevice handle
[in]cbAlert callback
[in]argAlert callback argument
Returns
See also
_ina3221_enable_alert

Definition at line 413 of file ina3221.h.

◆ ina3221_enable_warning_alert()

static int ina3221_enable_warning_alert ( ina3221_t dev,
ina3221_alert_cb_t  cb,
void *  arg 
)
inlinestatic

Wrapper around.

See also
_ina3221_enable_alert, to enable warning alert
Parameters
[in,out]devDevice handle
[in]cbAlert callback
[in]argAlert callback argument
Returns
See also
_ina3221_enable_alert

Definition at line 380 of file ina3221.h.

◆ ina3221_get_channel_state()

static int ina3221_get_channel_state ( const ina3221_t dev,
ina3221_channel_state_t ch1,
ina3221_channel_state_t ch2,
ina3221_channel_state_t ch3 
)
inlinestatic

Wrapper around _ina3221_get_enable_channel.

Parameters
[in]devDevice handle
[out]ch1Pointer to channel 1 state variable
[out]ch2Pointer to channel 2 state variable
[out]ch3Pointer to channel 3 state variable
Returns
See also
_ina3221_get_enable_channel

Definition at line 631 of file ina3221.h.

◆ ina3221_get_config()

static int ina3221_get_config ( const ina3221_t dev,
ina3221_enable_ch_t chs,
ina3221_num_samples_t ns,
ina3221_conv_time_bus_adc_t ctbadc,
ina3221_conv_time_shunt_adc_t ctsadc,
ina3221_mode_t mode 
)
inlinestatic

Wrapper around.

See also
_ina3221_get_config
Parameters
[in]devDevice handle
[out]chsPointer to enabled channels variable
[out]nsPointer to number of samples variable
[out]ctbadcPointer to conversion time bus adc variable
[out]ctsadcPointer to conversion time shunt adc variable
[out]modePointer to measurement mode variable
Returns
See also
_ina3221_get_config

Definition at line 559 of file ina3221.h.

◆ ina3221_get_conv_time_bus_adc()

int ina3221_get_conv_time_bus_adc ( const ina3221_t dev,
ina3221_conv_time_bus_adc_t ctb 
)

Read currently applied bus voltage ADC conversion time.

Parameters
[in]devDevice handle
[out]ctbPointer to bus voltage ADC conversion time output variable
Returns
INA3221_OK

◆ ina3221_get_conv_time_shunt_adc()

int ina3221_get_conv_time_shunt_adc ( const ina3221_t dev,
ina3221_conv_time_shunt_adc_t cts 
)

Read currently applied shunt voltage ADC conversion time.

Parameters
[in]devDevice handle
[out]ctsPointer to shunt voltage ADC conversion time output variable
Returns
INA3221_OK

◆ ina3221_get_crit_alert_limit()

int ina3221_get_crit_alert_limit ( const ina3221_t dev,
ina3221_channel_t  ch,
int32_t *  out_uv 
)

Read critical shunt voltage alert limit for each channel in ch.

The function exits on the first channel whose critical alert limit could not be read.

Parameters
[in]devDevice handle
[in]chChannel flags
[out]out_uvOutput array of shunt voltage alert limits in uV
Returns
Number of channels whose critical shunt voltage alert limits could be read, if any
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_get_enable_sum_channel()

static int ina3221_get_enable_sum_channel ( const ina3221_t dev,
ina3221_channel_state_t ch1,
ina3221_channel_state_t ch2,
ina3221_channel_state_t ch3 
)
inlinestatic

Wrapper for.

See also
_ina3221_get_enable_sum_channel
Parameters
[in]devDevice handle
[out]ch1Pointer to channel 1 state variable for sum voltage drop calculation
[out]ch2Pointer to channel 2 state variable for sum voltage drop calculation
[out]ch3Pointer to channel 3 state variable for sum voltage drop calculation
Returns
See also
_ina3221_get_enable_sum_channel

Definition at line 799 of file ina3221.h.

◆ ina3221_get_latch()

int ina3221_get_latch ( const ina3221_t dev,
ina3221_enable_latch_t latch 
)

Read enabled latches for critical/warning alert pins.

Parameters
[in]devDevice handle
[in]latchPointer to latch flags output variable
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_get_mode()

int ina3221_get_mode ( const ina3221_t dev,
ina3221_mode_t mode 
)

Read currently applied device operation mode.

Parameters
[in]devDevice handle
[out]modePointer to device operation mode output variable
Returns
INA3221_OK

◆ ina3221_get_num_samples()

int ina3221_get_num_samples ( const ina3221_t dev,
ina3221_num_samples_t ns 
)

Read currently applied number of samples.

Parameters
[in]devDevice handle
[out]nsPointer to number of samples output variable
Returns
INA3221_OK

◆ ina3221_get_power_valid_lower_limit()

int ina3221_get_power_valid_lower_limit ( const ina3221_t dev,
int32_t *  out_mv 
)

Read bus voltage power valid lower limit.

Parameters
[in]devDevice handle
[out]out_mvPointer to bus voltage power valid lower limit output variable
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_get_power_valid_upper_limit()

int ina3221_get_power_valid_upper_limit ( const ina3221_t dev,
int32_t *  out_mv 
)

Read bus voltage power valid upper limit.

Parameters
[in]devDevice handle
[out]out_mvPointer to bus voltage power valid upper limit output variable
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_get_shunt_voltage_sum_alert_limit()

int ina3221_get_shunt_voltage_sum_alert_limit ( const ina3221_t dev,
int32_t *  out_uv 
)

Read shunt voltage sum alert limit.

Parameters
[in]devDevice handle
[out]out_uvPointer to sum voltage sum alert limit output variable
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_get_warn_alert_limit()

int ina3221_get_warn_alert_limit ( const ina3221_t dev,
ina3221_channel_t  ch,
int32_t *  out_uv 
)

Read warning shunt voltage alert limit for each channel in ch.

The function exits on the first channel whose warning alert limit could not be read.

Parameters
[in]devDevice handle
[in]chChannel flags
[out]out_uvOutput array of shunt voltage alert limits in uV
Returns
Number of channels whose warning shunt voltage alert limits could be read, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_init()

int ina3221_init ( ina3221_t dev,
const ina3221_params_t params 
)

Initialize device.

Parameters
[out]devDevice handle
[in]paramsDevice parameters
Returns
INA3221_OK, on success
-EINVAL, if NULL pointer was passed
-INA3221_I2C_ERROR, if I2C bus acquirement failed
-INA3221_BAD_MANUF_ID, if manufacturer ID does not match
-INA3221_DIE_ID, if DIE ID does not match
-INA3221_RESET_FAILED, if reset failed
-INA3221_CONFIG_FAILED, if configuration could not be applied
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_read_bus_mv()

int ina3221_read_bus_mv ( const ina3221_t dev,
ina3221_channel_t  ch,
int16_t *  out_mv,
uint16_t *  flags 
)

Read bus voltages for each channel in ch.

The function exits on the first channel whose bus voltage could not be read

Parameters
[in]devDevice handle
[in]chChannel flags
[out]out_mvArray of output bus voltage values in mV
[out]flagsPointer to flags output variable, may be NULL
Returns
Number of channels whose bus voltages could be read, if any
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_read_flags()

int ina3221_read_flags ( const ina3221_t dev,
uint16_t *  flags 
)

Read status flags.

Parameters
[in]devDevice handle
[out]flagsPointer to flags output variable
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_read_shunt_sum_uv()

int ina3221_read_shunt_sum_uv ( const ina3221_t dev,
int32_t *  out_uv,
uint16_t *  flags 
)

Read sum of shunt voltages.

Parameters
[in]devDevice handle
[out]out_uvPointer to shunt voltage sum output variable
[out]flagsPointer to flags output variable, may be NULL
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_read_shunt_uv()

int ina3221_read_shunt_uv ( const ina3221_t dev,
ina3221_channel_t  ch,
int32_t *  out_uv,
uint16_t *  flags 
)

Read shunt voltages for each channel in ch.

The function exits on the first channel whose shunt voltage could not be read

Parameters
[in]devDevice handle
[in]chChannel flags
[out]out_uvArray of output shunt voltage values in uV
[out]flagsPointer to flags output variable, may be NULL
Returns
Number of channels whose shunt voltages could be read, if any
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs

◆ ina3221_reset()

int ina3221_reset ( ina3221_t dev)

Reset device, i.e.

apply default configuration

Parameters
[in,out]devDevice handle
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
-INA3221_RESET_FAILED, if device could not be reset
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_set_channel_state()

static int ina3221_set_channel_state ( ina3221_t dev,
ina3221_channel_state_t  ch1,
ina3221_channel_state_t  ch2,
ina3221_channel_state_t  ch3 
)
inlinestatic

Wrapper around.

See also
_ina3221_set_enable_channel
Parameters
[in,out]devDevice handle
[in]ch1Channel 1 state
[in]ch2Channel 2 state
[in]ch3Channel 3 state
Returns
See also
_ina3221_set_enable_channel

Definition at line 600 of file ina3221.h.

◆ ina3221_set_config()

static int ina3221_set_config ( ina3221_t dev,
ina3221_enable_ch_t  chs,
ina3221_num_samples_t  ns,
ina3221_conv_time_bus_adc_t  ctbadc,
ina3221_conv_time_shunt_adc_t  ctsadc,
ina3221_mode_t  mode 
)
inlinestatic

Wrapper around.

See also
_ina3221_set_config
Parameters
[in,out]devDevice handle
[in]chsChannel enable flags
[in]nsNumber of samples
[in]ctbadcConversion time for bus voltage ADC
[in]ctsadcConversion time for shunt voltage ADC
[in]modeDevice operation mode
Returns
See also
_ina3221_set_config

Definition at line 527 of file ina3221.h.

◆ ina3221_set_conv_time_bus_adc()

int ina3221_set_conv_time_bus_adc ( ina3221_t dev,
ina3221_conv_time_bus_adc_t  ctb 
)

Update conversion time of bus voltage ADC and write to configuration register.

Parameters
[in,out]devDevice handle
[in]ctbBus voltage conversion time
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_set_conv_time_shunt_adc()

int ina3221_set_conv_time_shunt_adc ( ina3221_t dev,
ina3221_conv_time_shunt_adc_t  cts 
)

Update conversion time of shunt voltage ADC and write to configuration register.

Parameters
[in,out]devDevice handle
[in]ctsShunt voltage conversion time value
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_set_crit_alert_limit()

int ina3221_set_crit_alert_limit ( const ina3221_t dev,
ina3221_channel_t  ch,
int32_t  in_uv 
)

Set critical shunt voltage alert limit to in_uv for each channel in ch.

The function exits on the first channel that could not be updated.

Parameters
[in]devDevice handle
[in]chChannel flags
[in]in_uvCritical shunt voltage limit in uv
Returns
Number of channels whose critical shunt voltage alert limit could be set, if any
-ERANGE, if in_uv was not in [INA3221_MIN_SHUNT_UV; INA3221_MAX_SHUNT_UV]
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_write_regs

◆ ina3221_set_enable_sum_channel()

static int ina3221_set_enable_sum_channel ( const ina3221_t dev,
ina3221_channel_state_t  ch1,
ina3221_channel_state_t  ch2,
ina3221_channel_state_t  ch3 
)
inlinestatic

Wrapper around.

See also
_ina3221_set_enable_sum_channel
Parameters
[in]devDevice handle
[in]ch1Channel 1 state for sum voltage drop calculation
[in]ch2Channel 2 state for sum voltage drop calculation
[in]ch3Channel 3 state for sum voltage drop calculation
Returns
See also
_ina3221_set_enable_sum_channel

Definition at line 765 of file ina3221.h.

◆ ina3221_set_latch()

int ina3221_set_latch ( const ina3221_t dev,
ina3221_enable_latch_t  latch 
)

Enable latches for critical/warning alert pins.

Parameters
[in]devDevice handle
[in]latchEnable latch flags
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_set_mode()

int ina3221_set_mode ( ina3221_t dev,
ina3221_mode_t  mode 
)

Update device operation mode.

Parameters
[in,out]devDevice handle
[in]modeOperation mode value in host byte order
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_set_num_samples()

int ina3221_set_num_samples ( ina3221_t dev,
ina3221_num_samples_t  ns 
)

Update number of samples and write to configuration register.

Parameters
[in,out]devDevice handle
[in]nsNumber of samples
Returns
INA3221_OK, on success
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_read_regs
Returns
See also
i2c_write_regs

◆ ina3221_set_power_valid_lower_limit()

int ina3221_set_power_valid_lower_limit ( const ina3221_t dev,
int32_t  in_mv 
)

Set bus voltage power valid lower limit to in_mv.

Parameters
[in]devDevice handle
[in]in_mvbus voltage power valid lower limit in mV
Returns
INA3221_OK, on success
-ERANGE, if in_mv was not in [INA3221_MIN_BUS_MV; INA3221_MAX_BUS_MV]
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_write_regs

◆ ina3221_set_power_valid_upper_limit()

int ina3221_set_power_valid_upper_limit ( const ina3221_t dev,
int32_t  in_mv 
)

Set bus voltage power valid upper limit to in_mv.

Parameters
[in]devDevice handle
[in]in_mvbus voltage power valid upper limit in mv
Returns
INA3221_OK, on success
-ERANGE, if in_mv was not in [INA3221_MIN_BUS_MV; INA3221_MAX_BUS_MV]
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_write_regs

◆ ina3221_set_shunt_voltage_sum_alert_limit()

int ina3221_set_shunt_voltage_sum_alert_limit ( const ina3221_t dev,
int32_t  in_uv 
)

Set shunt voltage sum alert limit to in_uv.

Parameters
[in]devDevice handle
[in]in_uvshunt voltage sum limit in uv
Returns
INA3221_OK, on success
-ERANGE, if in_uv was not in [INA3221_MIN_SHUNT_SUM_UV; INA3221_MAX_SHUNT_SUM_UV]
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_write_regs

◆ ina3221_set_warn_alert_limit()

int ina3221_set_warn_alert_limit ( const ina3221_t dev,
ina3221_channel_t  ch,
int32_t  in_uv 
)

Set warning shunt voltage alert limit to in_uv for each channel in ch.

The function exits on the first channel that could not be updated.

Parameters
[in]devDevice handle
[in]chChannel flags
[in]in_uvWarning shunt voltage limit in uV in host byte order
Returns
Number of channels whose warning shunt voltage alert limit could be set, if any
-ERANGE, if in_uv was not in [INA3221_MIN_SHUNT_UV; INA3221_MAX_SHUNT_UV]
-INA3221_I2C_ERROR, if I2C bus acquirement failed
See also
i2c_write_regs
INA3221_ENABLE_CH3
@ INA3221_ENABLE_CH3
Enable channel 3.
Definition: ina3221.h:192
INA3221_ENABLE_CRIT_LATCH
@ INA3221_ENABLE_CRIT_LATCH
Enable critical alert latch.
Definition: ina3221.h:223
INA3221_FLAG_CRIT_ALERT_CH3
#define INA3221_FLAG_CRIT_ALERT_CH3
Critical alert channel 3 flag.
Definition: ina3221.h:267
INA3221_ENABLE_SUM_CH1
@ INA3221_ENABLE_SUM_CH1
Enable sum channel 1.
Definition: ina3221.h:210
INA3221_ENABLE_SUM_CH2
@ INA3221_ENABLE_SUM_CH2
Enable sum channel 2.
Definition: ina3221.h:211
INA3221_ENABLE_WARN_LATCH
@ INA3221_ENABLE_WARN_LATCH
Enable warning alert latch.
Definition: ina3221.h:222
INA3221_FLAG_TIMING_CONTROL
#define INA3221_FLAG_TIMING_CONTROL
Timing Control flag.
Definition: ina3221.h:277
INA3221_FLAG_WARN_ALERT_CH1
#define INA3221_FLAG_WARN_ALERT_CH1
Warning alert channel 1 flag.
Definition: ina3221.h:271
INA3221_FLAG_CRIT_ALERT_CH1
#define INA3221_FLAG_CRIT_ALERT_CH1
Critical alert channel 1 flag.
Definition: ina3221.h:265
INA3221_FLAG_WARN_ALERT_CH3
#define INA3221_FLAG_WARN_ALERT_CH3
Warning alert channel 3 flag.
Definition: ina3221.h:273
INA3221_FLAG_CRIT_ALERT_CH2
#define INA3221_FLAG_CRIT_ALERT_CH2
Critical alert channel 2 flag.
Definition: ina3221.h:266
INA3221_FLAG_WARN_ALERT_CH2
#define INA3221_FLAG_WARN_ALERT_CH2
Warning alert channel 2 flag.
Definition: ina3221.h:272
INA3221_ENABLE_CH1
@ INA3221_ENABLE_CH1
Enable channel 1.
Definition: ina3221.h:190
INA3221_FLAG_CONV_READY
#define INA3221_FLAG_CONV_READY
Conversion ready flag.
Definition: ina3221.h:279
INA3221_ENABLE_CH2
@ INA3221_ENABLE_CH2
Enable channel 2.
Definition: ina3221.h:191
INA3221_FLAG_SHUNT_SUM_ALERT
#define INA3221_FLAG_SHUNT_SUM_ALERT
Alert channel sum flag.
Definition: ina3221.h:269
INA3221_FLAG_POWER_VALID
#define INA3221_FLAG_POWER_VALID
Power valid flag.
Definition: ina3221.h:275
INA3221_ENABLE_SUM_CH3
@ INA3221_ENABLE_SUM_CH3
Enable sum channel 3.
Definition: ina3221.h:212