INA219.Registers (ina219 v2.0.1)

The INA219 uses a bank of registers for holding configuration settings, measurement results, maximum/minimum limits, and status information.

Registers

Configuration register

All-register reset, settings for bus voltage range, PGA Gain, ADC resolution/averaging. Read write.

Shunt Voltage register

Shunt voltage measurement data. Read only.

Bus Voltage register

Bus voltage measurement data. Read-only,

Power register

Power measurement data. Read only.

Current register

Contains the value of the current flowing through the shunt resistor. Read only.

Calibration register

Sets full-scale range and LSB of current and power measurements. Overall system calibration. Read write.

Link to this section Summary

Functions

Read the contents of the bus_voltage register.

Read the contents of the calibration register.

Read the contents of the configuration register.

Read the contents of the current register.

Read the contents of the power register.

Read the contents of the shunt_voltage register.

Swap the contents of the calibration register.

Swap the contents of the configuration register.

Update the contents of the calibration register using a transformation function.

Update the contents of the configuration register using a transformation function.

Write new contents to the calibration register.

Write new contents to the configuration register.

Link to this section Functions

Link to this function

read_bus_voltage(conn)

@spec read_bus_voltage(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}

Read the contents of the bus_voltage register.

Example

iex> read_bus_voltage(conn)
{:ok, <<0, 0>>}
Link to this function

read_calibration(conn)

@spec read_calibration(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}

Read the contents of the calibration register.

Example

iex> read_calibration(conn)
{:ok, <<0, 0>>}
Link to this function

read_configuration(conn)

@spec read_configuration(Wafer.Conn.t()) ::
  {:ok, binary()} | {:error, reason :: any()}

Read the contents of the configuration register.

Example

iex> read_configuration(conn)
{:ok, <<0, 0>>}
Link to this function

read_current(conn)

@spec read_current(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}

Read the contents of the current register.

Example

iex> read_current(conn)
{:ok, <<0, 0>>}
Link to this function

read_power(conn)

@spec read_power(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}

Read the contents of the power register.

Example

iex> read_power(conn)
{:ok, <<0, 0>>}
Link to this function

read_shunt_voltage(conn)

@spec read_shunt_voltage(Wafer.Conn.t()) ::
  {:ok, binary()} | {:error, reason :: any()}

Read the contents of the shunt_voltage register.

Example

iex> read_shunt_voltage(conn)
{:ok, <<0, 0>>}
Link to this function

swap_calibration(conn, data)

@spec swap_calibration(Wafer.Conn.t(), data :: binary()) ::
  {:ok, Wafer.Conn.t()} | {:error, reason :: any()}

Swap the contents of the calibration register.

Reads the contents of the register, then replaces it, returning the previous contents. Some drivers may implement this atomically.

Example

iex> swap_calibration(conn, <<0, 0>>)
{:ok, <<0, 0>>, _conn}
Link to this function

swap_configuration(conn, data)

@spec swap_configuration(Wafer.Conn.t(), data :: binary()) ::
  {:ok, Wafer.Conn.t()} | {:error, reason :: any()}

Swap the contents of the configuration register.

Reads the contents of the register, then replaces it, returning the previous contents. Some drivers may implement this atomically.

Example

iex> swap_configuration(conn, <<0, 0>>)
{:ok, <<0, 0>>, _conn}
Link to this function

update_calibration(conn, callback)

@spec update_calibration(Wafer.Conn.t(), (<<_::_*16>> -> <<_::_*16>>)) ::
  {:ok, Wafer.Conn.t()} | {:error, reason :: any()}

Update the contents of the calibration register using a transformation function.

Example

iex> transform = fn <<data::size(16)>> -> <<(data * 2)::size(16)>> end
...> update_calibration(conn, transform)
{:ok, _conn}
Link to this function

update_configuration(conn, callback)

@spec update_configuration(Wafer.Conn.t(), (<<_::_*16>> -> <<_::_*16>>)) ::
  {:ok, Wafer.Conn.t()} | {:error, reason :: any()}

Update the contents of the configuration register using a transformation function.

Example

iex> transform = fn <<data::size(16)>> -> <<(data * 2)::size(16)>> end
...> update_configuration(conn, transform)
{:ok, _conn}
Link to this function

write_calibration(conn, data)

@spec write_calibration(Wafer.Conn.t(), data :: binary()) ::
  {:ok, Wafer.Conn.t()} | {:error, reason :: any()}

Write new contents to the calibration register.

Example

iex> write_calibration(conn, <<0, 0>>)
{:ok, _conn}
Link to this function

write_configuration(conn, data)

@spec write_configuration(Wafer.Conn.t(), data :: binary()) ::
  {:ok, Wafer.Conn.t()} | {:error, reason :: any()}

Write new contents to the configuration register.

Example

iex> write_configuration(conn, <<0, 0>>)
{:ok, _conn}