LibDriver INA219
Loading...
Searching...
No Matches
ina219 basic driver function

ina219 basic driver modules More...

Collaboration diagram for ina219 basic driver function:

Data Structures

struct  ina219_handle_s
 ina219 handle structure definition More...
struct  ina219_info_s
 ina219 information structure definition More...

Typedefs

typedef struct ina219_handle_s ina219_handle_t
 ina219 handle structure definition
typedef struct ina219_info_s ina219_info_t
 ina219 information structure definition

Enumerations

enum  ina219_address_t {
  INA219_ADDRESS_0 = (0x40 << 1) , INA219_ADDRESS_1 = (0x41 << 1) , INA219_ADDRESS_2 = (0x42 << 1) , INA219_ADDRESS_3 = (0x43 << 1) ,
  INA219_ADDRESS_4 = (0x44 << 1) , INA219_ADDRESS_5 = (0x45 << 1) , INA219_ADDRESS_6 = (0x46 << 1) , INA219_ADDRESS_7 = (0x47 << 1) ,
  INA219_ADDRESS_8 = (0x48 << 1) , INA219_ADDRESS_9 = (0x49 << 1) , INA219_ADDRESS_A = (0x4A << 1) , INA219_ADDRESS_B = (0x4B << 1) ,
  INA219_ADDRESS_C = (0x4C << 1) , INA219_ADDRESS_D = (0x4D << 1) , INA219_ADDRESS_E = (0x4E << 1) , INA219_ADDRESS_F = (0x4F << 1)
}
 ina219 address enumeration definition More...
enum  ina219_bus_voltage_range_t { INA219_BUS_VOLTAGE_RANGE_16V = 0 , INA219_BUS_VOLTAGE_RANGE_32V = 1 }
 ina219 bus voltage enumeration definition More...
enum  ina219_pga_t { INA219_PGA_40_MV = 0 , INA219_PGA_80_MV = 1 , INA219_PGA_160_MV = 2 , INA219_PGA_320_MV = 3 }
 ina219 pga enumeration definition More...
enum  ina219_adc_mode_t {
  INA219_ADC_MODE_9_BIT_1_SAMPLES = 0x0 , INA219_ADC_MODE_10_BIT_1_SAMPLES = 0x1 , INA219_ADC_MODE_11_BIT_1_SAMPLES = 0x2 , INA219_ADC_MODE_12_BIT_1_SAMPLES = 0x3 ,
  INA219_ADC_MODE_12_BIT_2_SAMPLES = 0x9 , INA219_ADC_MODE_12_BIT_4_SAMPLES = 0xA , INA219_ADC_MODE_12_BIT_8_SAMPLES = 0xB , INA219_ADC_MODE_12_BIT_16_SAMPLES = 0xC ,
  INA219_ADC_MODE_12_BIT_32_SAMPLES = 0xD , INA219_ADC_MODE_12_BIT_64_SAMPLES = 0xE , INA219_ADC_MODE_12_BIT_128_SAMPLES = 0xF
}
 ina219 adc mode enumeration definition More...
enum  ina219_mode_t {
  INA219_MODE_POWER_DOWN = 0x0 , INA219_MODE_SHUNT_VOLTAGE_TRIGGERED = 0x1 , INA219_MODE_BUS_VOLTAGE_TRIGGERED = 0x2 , INA219_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED = 0x3 ,
  INA219_MODE_ADC_OFF = 0x4 , INA219_MODE_SHUNT_VOLTAGE_CONTINUOUS = 0x5 , INA219_MODE_BUS_VOLTAGE_CONTINUOUS = 0x6 , INA219_MODE_SHUNT_BUS_VOLTAGE_CONTINUOUS = 0x7
}
 ina219 mode enumeration definition More...

Functions

uint8_t ina219_info (ina219_info_t *info)
 get chip's information
uint8_t ina219_set_addr_pin (ina219_handle_t *handle, ina219_address_t addr_pin)
 set the iic address pin
uint8_t ina219_get_addr_pin (ina219_handle_t *handle, ina219_address_t *addr_pin)
 get the iic address pin
uint8_t ina219_set_resistance (ina219_handle_t *handle, double resistance)
 set the resistance
uint8_t ina219_get_resistance (ina219_handle_t *handle, double *resistance)
 get the resistance
uint8_t ina219_init (ina219_handle_t *handle)
 initialize the chip
uint8_t ina219_deinit (ina219_handle_t *handle)
 close the chip
uint8_t ina219_read_shunt_voltage (ina219_handle_t *handle, int16_t *raw, float *mV)
 read the shunt voltage
uint8_t ina219_read_bus_voltage (ina219_handle_t *handle, uint16_t *raw, float *mV)
 read the bus voltage
uint8_t ina219_read_current (ina219_handle_t *handle, int16_t *raw, float *mA)
 read the current
uint8_t ina219_read_power (ina219_handle_t *handle, uint16_t *raw, float *mW)
 read the power
uint8_t ina219_soft_reset (ina219_handle_t *handle)
 soft reset the chip
uint8_t ina219_set_bus_voltage_range (ina219_handle_t *handle, ina219_bus_voltage_range_t range)
 set the bus voltage range
uint8_t ina219_get_bus_voltage_range (ina219_handle_t *handle, ina219_bus_voltage_range_t *range)
 get the bus voltage range
uint8_t ina219_set_pga (ina219_handle_t *handle, ina219_pga_t pga)
 set the pga
uint8_t ina219_get_pga (ina219_handle_t *handle, ina219_pga_t *pga)
 get the pga
uint8_t ina219_set_bus_voltage_adc_mode (ina219_handle_t *handle, ina219_adc_mode_t mode)
 set the bus voltage adc mode
uint8_t ina219_get_bus_voltage_adc_mode (ina219_handle_t *handle, ina219_adc_mode_t *mode)
 get the bus voltage adc mode
uint8_t ina219_set_shunt_voltage_adc_mode (ina219_handle_t *handle, ina219_adc_mode_t mode)
 set the shunt voltage adc mode
uint8_t ina219_get_shunt_voltage_adc_mode (ina219_handle_t *handle, ina219_adc_mode_t *mode)
 get the shunt voltage adc mode
uint8_t ina219_set_mode (ina219_handle_t *handle, ina219_mode_t mode)
 set the mode
uint8_t ina219_get_mode (ina219_handle_t *handle, ina219_mode_t *mode)
 get the mode
uint8_t ina219_set_calibration (ina219_handle_t *handle, uint16_t data)
 set the calibration
uint8_t ina219_get_calibration (ina219_handle_t *handle, uint16_t *data)
 get the calibration
uint8_t ina219_calculate_calibration (ina219_handle_t *handle, uint16_t *calibration)
 calculate the calibration

Detailed Description

ina219 basic driver modules

Typedef Documentation

◆ ina219_handle_t

ina219 handle structure definition

◆ ina219_info_t

typedef struct ina219_info_s ina219_info_t

ina219 information structure definition

Enumeration Type Documentation

◆ ina219_adc_mode_t

ina219 adc mode enumeration definition

Enumerator
INA219_ADC_MODE_9_BIT_1_SAMPLES 

9 bit / 1 samples

INA219_ADC_MODE_10_BIT_1_SAMPLES 

10 bit / 1 samples

INA219_ADC_MODE_11_BIT_1_SAMPLES 

11 bit / 1 samples

INA219_ADC_MODE_12_BIT_1_SAMPLES 

12 bit / 1 samples

INA219_ADC_MODE_12_BIT_2_SAMPLES 

12 bit / 2 samples

INA219_ADC_MODE_12_BIT_4_SAMPLES 

12 bit / 4 samples

INA219_ADC_MODE_12_BIT_8_SAMPLES 

12 bit / 8 samples

INA219_ADC_MODE_12_BIT_16_SAMPLES 

12 bit / 16 samples

INA219_ADC_MODE_12_BIT_32_SAMPLES 

12 bit / 32 samples

INA219_ADC_MODE_12_BIT_64_SAMPLES 

12 bit / 64 samples

INA219_ADC_MODE_12_BIT_128_SAMPLES 

12 bit / 128 samples

Definition at line 105 of file driver_ina219.h.

◆ ina219_address_t

ina219 address enumeration definition

Enumerator
INA219_ADDRESS_0 

A0 = GND, A1 = GND

INA219_ADDRESS_1 

A0 = VS+, A1 = GND

INA219_ADDRESS_2 

A0 = SDA, A1 = GND

INA219_ADDRESS_3 

A0 = SCL, A1 = GND

INA219_ADDRESS_4 

A0 = GND, A1 = VS+

INA219_ADDRESS_5 

A0 = VS+, A1 = VS+

INA219_ADDRESS_6 

A0 = SDA, A1 = VS+

INA219_ADDRESS_7 

A0 = SCL, A1 = VS+

INA219_ADDRESS_8 

A0 = GND, A1 = SDA

INA219_ADDRESS_9 

A0 = VS+, A1 = SDA

INA219_ADDRESS_A 

A0 = SDA, A1 = SDA

INA219_ADDRESS_B 

A0 = SCL, A1 = SDA

INA219_ADDRESS_C 

A0 = GND, A1 = SCL

INA219_ADDRESS_D 

A0 = VS+, A1 = SCL

INA219_ADDRESS_E 

A0 = SDA, A1 = SCL

INA219_ADDRESS_F 

A0 = SCL, A1 = SCL

Definition at line 62 of file driver_ina219.h.

◆ ina219_bus_voltage_range_t

ina219 bus voltage enumeration definition

Enumerator
INA219_BUS_VOLTAGE_RANGE_16V 

±16V

INA219_BUS_VOLTAGE_RANGE_32V 

±32V

Definition at line 85 of file driver_ina219.h.

◆ ina219_mode_t

ina219 mode enumeration definition

Enumerator
INA219_MODE_POWER_DOWN 

power down

INA219_MODE_SHUNT_VOLTAGE_TRIGGERED 

shunt voltage triggered

INA219_MODE_BUS_VOLTAGE_TRIGGERED 

bus voltage triggered

INA219_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED 

shunt and bus triggered

INA219_MODE_ADC_OFF 

adc off

INA219_MODE_SHUNT_VOLTAGE_CONTINUOUS 

shunt voltage continuous

INA219_MODE_BUS_VOLTAGE_CONTINUOUS 

bus voltage continuous

INA219_MODE_SHUNT_BUS_VOLTAGE_CONTINUOUS 

shunt and bus voltage continuous

Definition at line 123 of file driver_ina219.h.

◆ ina219_pga_t

ina219 pga enumeration definition

Enumerator
INA219_PGA_40_MV 

±40 mV

INA219_PGA_80_MV 

±80 mV

INA219_PGA_160_MV 

±160 mV

INA219_PGA_320_MV 

±320 mV

Definition at line 94 of file driver_ina219.h.

Function Documentation

◆ ina219_calculate_calibration()

uint8_t ina219_calculate_calibration ( ina219_handle_t * handle,
uint16_t * calibration )

calculate the calibration

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*calibrationpointer to a calibration data buffer
Returns
status code
  • 0 success
  • 1 calibration calibration failed
  • 2 handle is NULL
  • 3 handle is not initialized
  • 4 r can't be zero
  • 5 pga is invalid
Note
none

Definition at line 863 of file driver_ina219.c.

◆ ina219_deinit()

uint8_t ina219_deinit ( ina219_handle_t * handle)

close the chip

Parameters
[in]*handlepointer to an ina219 handle structure
Returns
status code
  • 0 success
  • 1 iic deinit failed
  • 2 handle is NULL
  • 3 handle is not initialized
  • 4 power down failed
Note
none

Definition at line 1092 of file driver_ina219.c.

◆ ina219_get_addr_pin()

uint8_t ina219_get_addr_pin ( ina219_handle_t * handle,
ina219_address_t * addr_pin )

get the iic address pin

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*addr_pinpointer to an address pin buffer
Returns
status code
  • 0 success
  • 2 handle is NULL
Note
none

Definition at line 187 of file driver_ina219.c.

◆ ina219_get_bus_voltage_adc_mode()

uint8_t ina219_get_bus_voltage_adc_mode ( ina219_handle_t * handle,
ina219_adc_mode_t * mode )

get the bus voltage adc mode

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*modepointer to an adc mode buffer
Returns
status code
  • 0 success
  • 1 get bus voltage adc mode failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 435 of file driver_ina219.c.

◆ ina219_get_bus_voltage_range()

uint8_t ina219_get_bus_voltage_range ( ina219_handle_t * handle,
ina219_bus_voltage_range_t * range )

get the bus voltage range

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*rangepointer to a bus voltage range buffer
Returns
status code
  • 0 success
  • 1 get bus voltage range failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 285 of file driver_ina219.c.

◆ ina219_get_calibration()

uint8_t ina219_get_calibration ( ina219_handle_t * handle,
uint16_t * data )

get the calibration

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*datapointer to a calibration data buffer
Returns
status code
  • 0 success
  • 1 get calibration failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 826 of file driver_ina219.c.

◆ ina219_get_mode()

uint8_t ina219_get_mode ( ina219_handle_t * handle,
ina219_mode_t * mode )

get the mode

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*modepointer to a chip mode buffer
Returns
status code
  • 0 success
  • 1 get mode failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 614 of file driver_ina219.c.

◆ ina219_get_pga()

uint8_t ina219_get_pga ( ina219_handle_t * handle,
ina219_pga_t * pga )

get the pga

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*pgapointer to an adc pga buffer
Returns
status code
  • 0 success
  • 1 get pga failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 360 of file driver_ina219.c.

◆ ina219_get_resistance()

uint8_t ina219_get_resistance ( ina219_handle_t * handle,
double * resistance )

get the resistance

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*resistancepointer to a current sampling resistance value buffer
Returns
status code
  • 0 success
  • 2 handle is NULL
Note
none

Definition at line 145 of file driver_ina219.c.

◆ ina219_get_shunt_voltage_adc_mode()

uint8_t ina219_get_shunt_voltage_adc_mode ( ina219_handle_t * handle,
ina219_adc_mode_t * mode )

get the shunt voltage adc mode

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*modepointer to an adc mode buffer
Returns
status code
  • 0 success
  • 1 get shunt voltage adc mode failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 510 of file driver_ina219.c.

◆ ina219_info()

uint8_t ina219_info ( ina219_info_t * info)

get chip's information

Parameters
[out]*infopointer to an ina219 info structure
Returns
status code
  • 0 success
  • 2 handle is NULL
Note
none

Definition at line 1192 of file driver_ina219.c.

◆ ina219_init()

uint8_t ina219_init ( ina219_handle_t * handle)

initialize the chip

Parameters
[in]*handlepointer to an ina219 handle structure
Returns
status code
  • 0 success
  • 1 iic initialization failed
  • 2 handle is NULL
  • 3 linked functions is NULL
  • 4 soft reset failed
Note
none

Definition at line 992 of file driver_ina219.c.

◆ ina219_read_bus_voltage()

uint8_t ina219_read_bus_voltage ( ina219_handle_t * handle,
uint16_t * raw,
float * mV )

read the bus voltage

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*rawpointer to raw data buffer
[out]*mVpointer to converted data buffer
Returns
status code
  • 0 success
  • 1 read bus voltage failed
  • 2 handle is NULL
  • 3 handle is not initialized
  • 4 math overflow
  • 5 conversion not ready
Note
none

Definition at line 697 of file driver_ina219.c.

◆ ina219_read_current()

uint8_t ina219_read_current ( ina219_handle_t * handle,
int16_t * raw,
float * mA )

read the current

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*rawpointer to raw data buffer
[out]*mApointer to converted data buffer
Returns
status code
  • 0 success
  • 1 read current failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 747 of file driver_ina219.c.

◆ ina219_read_power()

uint8_t ina219_read_power ( ina219_handle_t * handle,
uint16_t * raw,
float * mW )

read the power

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*rawpointer to raw data buffer
[out]*mWpointer to converted data buffer
Returns
status code
  • 0 success
  • 1 read power failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 790 of file driver_ina219.c.

◆ ina219_read_shunt_voltage()

uint8_t ina219_read_shunt_voltage ( ina219_handle_t * handle,
int16_t * raw,
float * mV )

read the shunt voltage

Parameters
[in]*handlepointer to an ina219 handle structure
[out]*rawpointer to raw data buffer
[out]*mVpointer to converted data buffer
Returns
status code
  • 0 success
  • 1 read shunt voltage failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 652 of file driver_ina219.c.

◆ ina219_set_addr_pin()

uint8_t ina219_set_addr_pin ( ina219_handle_t * handle,
ina219_address_t addr_pin )

set the iic address pin

Parameters
[in]*handlepointer to an ina219 handle structure
[in]addr_pinaddress pin
Returns
status code
  • 0 success
  • 2 handle is NULL
Note
none

Definition at line 166 of file driver_ina219.c.

◆ ina219_set_bus_voltage_adc_mode()

uint8_t ina219_set_bus_voltage_adc_mode ( ina219_handle_t * handle,
ina219_adc_mode_t mode )

set the bus voltage adc mode

Parameters
[in]*handlepointer to an ina219 handle structure
[in]modeadc mode
Returns
status code
  • 0 success
  • 1 set bus voltage adc mode failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 397 of file driver_ina219.c.

◆ ina219_set_bus_voltage_range()

uint8_t ina219_set_bus_voltage_range ( ina219_handle_t * handle,
ina219_bus_voltage_range_t range )

set the bus voltage range

Parameters
[in]*handlepointer to an ina219 handle structure
[in]rangebus voltage range
Returns
status code
  • 0 success
  • 1 set bus voltage range failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 247 of file driver_ina219.c.

◆ ina219_set_calibration()

uint8_t ina219_set_calibration ( ina219_handle_t * handle,
uint16_t data )

set the calibration

Parameters
[in]*handlepointer to an ina219 handle structure
[in]datacalibration data
Returns
status code
  • 0 success
  • 1 set calibration failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 957 of file driver_ina219.c.

◆ ina219_set_mode()

uint8_t ina219_set_mode ( ina219_handle_t * handle,
ina219_mode_t mode )

set the mode

Parameters
[in]*handlepointer to an ina219 handle structure
[in]modechip mode
Returns
status code
  • 0 success
  • 1 set mode failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 547 of file driver_ina219.c.

◆ ina219_set_pga()

uint8_t ina219_set_pga ( ina219_handle_t * handle,
ina219_pga_t pga )

set the pga

Parameters
[in]*handlepointer to an ina219 handle structure
[in]pgaadc pga
Returns
status code
  • 0 success
  • 1 set pga failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 322 of file driver_ina219.c.

◆ ina219_set_resistance()

uint8_t ina219_set_resistance ( ina219_handle_t * handle,
double resistance )

set the resistance

Parameters
[in]*handlepointer to an ina219 handle structure
[in]resistancecurrent sampling resistance value
Returns
status code
  • 0 success
  • 2 handle is NULL
Note
none

Definition at line 124 of file driver_ina219.c.

◆ ina219_set_shunt_voltage_adc_mode()

uint8_t ina219_set_shunt_voltage_adc_mode ( ina219_handle_t * handle,
ina219_adc_mode_t mode )

set the shunt voltage adc mode

Parameters
[in]*handlepointer to an ina219 handle structure
[in]modeadc mode
Returns
status code
  • 0 success
  • 1 set shunt voltage adc mode failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 472 of file driver_ina219.c.

◆ ina219_soft_reset()

uint8_t ina219_soft_reset ( ina219_handle_t * handle)

soft reset the chip

Parameters
[in]*handlepointer to an ina219 handle structure
Returns
status code
  • 0 success
  • 1 soft reset failed
  • 2 handle is NULL
  • 3 handle is not initialized
Note
none

Definition at line 209 of file driver_ina219.c.