ina260 - Driver for INA260 precision digital current and power monitor¶
- group ina260
ESP-IDF driver for INA260 precision digital current and power monitor.
Copyright (c) 2020 Ruslan V. Uss unclerus@gmail.com
BSD Licensed as described in the file LICENSE
- Todo:
Add support for SPI interface
Defines
-
INA260_ADDR_PIN_GND¶
-
INA260_ADDR_PIN_VS¶
-
INA260_ADDR_PIN_SDA¶
-
INA260_ADDR_PIN_SCL¶
-
INA260_ADDR(A0, A1)¶
Macro to define I2C address.
Examples: INA260_ADDR(INA260_ADDR_PIN_GND, INA260_ADDR_PIN_GND) = 0x40 (A0 = A1 = GND) INA260_ADDR(INA260_ADDR_PIN_VS, INA260_ADDR_PIN_SDA) = 0x49 (A0 = VS, A1 = SDA)
Enums
-
enum ina260_averaging_mode_t¶
Averaging mode.
Determines the number of samples that are collected and averaged.
Values:
-
enumerator INA260_AVG_1¶
1 sample, default
-
enumerator INA260_AVG_4¶
4 samples
-
enumerator INA260_AVG_16¶
16 samples
-
enumerator INA260_AVG_64¶
64 samples
-
enumerator INA260_AVG_128¶
128 samples
-
enumerator INA260_AVG_256¶
256 samples
-
enumerator INA260_AVG_512¶
512 samples
-
enumerator INA260_AVG_1024¶
1024 samples
-
enumerator INA260_AVG_1¶
-
enum ina260_conversion_time_t¶
Conversion time.
Values:
-
enumerator INA260_CT_140¶
140 us
-
enumerator INA260_CT_204¶
204 us
-
enumerator INA260_CT_332¶
332 us
-
enumerator INA260_CT_588¶
588 us
-
enumerator INA260_CT_1100¶
1.1 ms, default
-
enumerator INA260_CT_2116¶
2.116 ms
-
enumerator INA260_CT_4156¶
4.156 ms
-
enumerator INA260_CT_8244¶
8.244 ms
-
enumerator INA260_CT_140¶
-
enum ina260_mode_t¶
Operating mode.
Values:
-
enumerator INA260_MODE_POWER_DOWN¶
Power-done.
-
enumerator INA260_MODE_TRIG_SHUNT¶
Shunt current, triggered.
-
enumerator INA260_MODE_TRIG_BUS¶
Bus voltage, triggered.
-
enumerator INA260_MODE_TRIG_SHUNT_BUS¶
Shunt current and bus voltage, triggered.
-
enumerator INA260_MODE_POWER_DOWN2¶
Power-done.
-
enumerator INA260_MODE_CONT_SHUNT¶
Shunt current, continuous.
-
enumerator INA260_MODE_CONT_BUS¶
Bus voltage, continuous.
-
enumerator INA260_MODE_CONT_SHUNT_BUS¶
Shunt current and bus voltage, continuous (default)
-
enumerator INA260_MODE_POWER_DOWN¶
-
enum ina260_alert_mode_t¶
Alert function mode.
Values:
-
enumerator INA260_ALERT_DISABLED¶
No alert function.
-
enumerator INA260_ALERT_OCL¶
Over current limit.
-
enumerator INA260_ALERT_UCL¶
Under current limit.
-
enumerator INA260_ALERT_BOL¶
Bus voltage over-voltage.
-
enumerator INA260_ALERT_BUL¶
Bus voltage under-voltage.
-
enumerator INA260_ALERT_POL¶
Power over-limit.
-
enumerator INA260_ALERT_DISABLED¶
Functions
-
esp_err_t ina260_init_desc(ina260_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)¶
Initialize device descriptor.
- Parameters
dev – Device descriptor
addr – Device I2C address
port – I2C port
sda_gpio – SDA GPIO
scl_gpio – SCL GPIO
- Returns
ESP_OK
on success
-
esp_err_t ina260_free_desc(ina260_t *dev)¶
Free device descriptor.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina260_init(ina260_t *dev)¶
Initialize device.
Reads sensor configuration.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina260_reset(ina260_t *dev)¶
Reset sensor.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina260_set_config(ina260_t *dev, ina260_mode_t mode, ina260_averaging_mode_t avg_mode, ina260_conversion_time_t vbus_ct, ina260_conversion_time_t ish_ct)¶
Configure sensor.
- Parameters
dev – Device descriptor
mode – Operating mode
avg_mode – Averaging mode
vbus_ct – Bus voltage conversion time
ish_ct – Shunt current conversion time
- Returns
ESP_OK
on success
-
esp_err_t ina260_get_config(ina260_t *dev, ina260_mode_t *mode, ina260_averaging_mode_t *avg_mode, ina260_conversion_time_t *vbus_ct, ina260_conversion_time_t *ish_ct)¶
Read sensor configuration.
- Parameters
dev – Device descriptor
mode – [out] Operating mode
avg_mode – [out] Averaging mode
vbus_ct – [out] Bus voltage conversion time
ish_ct – [out] Shunt current conversion time
- Returns
ESP_OK
on success
-
esp_err_t ina260_set_alert(ina260_t *dev, ina260_alert_mode_t mode, float limit, bool cvrf, bool active_high, bool latch)¶
Setup ALERT pin.
- Parameters
dev – Device descriptor
mode – Alert function mode
limit – Alert limit value
cvrf – If true also assert ALERT pin when device is ready to next conversion
active_high – Set active ALERT pin level is high
latch – Enable latch mode on ALERT pin (see ina260_get_status())
- Returns
ESP_OK
on success
-
esp_err_t ina260_trigger(ina260_t *dev)¶
Trigger single conversion.
Function will return an error if current operating mode is not
INA260_MODE_TRIG_SHUNT
/INA260_MODE_TRIG_BUS
/INA260_MODE_TRIG_SHUNT_BUS
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina260_get_status(ina260_t *dev, bool *ready, bool *alert, bool *overflow)¶
Get device status.
This function also clears ALERT state if latch mode is enabled for ALERT pin.
- Parameters
dev – Device descriptor
ready – [out] If true, device is ready for the next conversion
alert – [out] If true, there was alert
overflow – [out] If true, power data have exceeded max 419.43 W
- Returns
ESP_OK
on success
-
esp_err_t ina260_get_current(ina260_t *dev, float *current)¶
Read current.
This function works properly only after calibration.
- Parameters
dev – Device descriptor
current – [out] Current, A
- Returns
ESP_OK
on success
-
struct ina260_t¶
- #include <ina260.h>
Device descriptor.