ina220.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Eistec AB
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef INA220_H
25 #define INA220_H
26 
27 #include <stdint.h>
28 
29 #include "periph/i2c.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 typedef struct {
40  uint8_t addr;
41 } ina220_t;
42 
44 typedef enum ina220_mode {
54 
56 typedef enum ina220_range {
57  INA220_RANGE_40MV = 0x0000,
58  INA220_RANGE_80MV = 0x0800,
59  INA220_RANGE_160MV = 0x1000,
60  INA220_RANGE_320MV = 0x1800,
62 
64 typedef enum ina220_brng {
68 
74 typedef enum ina220_sadc {
76  INA220_SADC_9BIT = 0x0000,
100 
106 typedef enum ina220_badc {
131 } ina220_badc_t;
132 
134 #define INA220_RESET_BIT (0x8000)
135 
137 #define INA220_BUS_VOLTAGE_SHIFT (3)
138 
149 int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address);
150 
160 int ina220_set_calibration(const ina220_t *dev, uint16_t calibration);
161 
171 int ina220_set_config(const ina220_t *dev, uint16_t config);
172 
182 int ina220_read_shunt(const ina220_t *dev, int16_t *voltage);
183 
198 int ina220_read_bus(const ina220_t *dev, int16_t *voltage);
199 
209 int ina220_read_current(const ina220_t *dev, int16_t *current);
210 
220 int ina220_read_power(const ina220_t *dev, int16_t *power);
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* INA220_H */
227 
12 bit resolution, 532 us conversion time, default
Definition: ina220.h:114
enum ina220_mode ina220_mode_t
INA220 possible mode settings.
enum ina220_range ina220_range_t
Shunt voltage measurement range (PGA settings)
ADC Off (disabled)
Definition: ina220.h:49
ina220_mode
INA220 possible mode settings.
Definition: ina220.h:44
enum ina220_brng ina220_brng_t
Bus voltage measurement range.
enum ina220_sadc ina220_sadc_t
Shunt ADC settings.
4 sample average, 2.13 ms conversion time
Definition: ina220.h:88
int ina220_set_calibration(const ina220_t *dev, uint16_t calibration)
Write to calibration register.
ina220_brng
Bus voltage measurement range.
Definition: ina220.h:64
16 sample average, 8.51 ms conversion time
Definition: ina220.h:92
2 sample average, 1.06 ms conversion time
Definition: ina220.h:118
2 sample average, 1.06 ms conversion time
Definition: ina220.h:86
128 sample average, 68.10 ms conversion time
Definition: ina220.h:98
10 bit resolution, 148 us conversion time
Definition: ina220.h:78
ina220_badc
Bus ADC settings.
Definition: ina220.h:106
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:113
Shunt Voltage, Continuous.
Definition: ina220.h:50
64 sample average, 34.05 ms conversion time
Definition: ina220.h:96
8 sample average, 4.26 ms conversion time
Definition: ina220.h:122
11 bit resolution, 276 us conversion time
Definition: ina220.h:80
16 V bus voltage full scale range
Definition: ina220.h:65
enum ina220_badc ina220_badc_t
Bus ADC settings.
8 sample average, 4.26 ms conversion time
Definition: ina220.h:90
4 sample average, 2.13 ms conversion time
Definition: ina220.h:120
+/- 320 mV range, default
Definition: ina220.h:60
Power down.
Definition: ina220.h:45
int ina220_set_config(const ina220_t *dev, uint16_t config)
Write to configuration register.
+/- 40 mV range
Definition: ina220.h:57
12 bit resolution, 532 us conversion time, same as INA220_SADC_12BIT
Definition: ina220.h:84
Bus Voltage, Continuous.
Definition: ina220.h:51
128 sample average, 68.10 ms conversion time
Definition: ina220.h:130
9 bit resolution, 84 us conversion time
Definition: ina220.h:76
10 bit resolution, 148 us conversion time
Definition: ina220.h:110
32 sample average, 17.02 ms conversion time
Definition: ina220.h:126
12 bit resolution, 532 us conversion time, same as INA220_BADC_12BIT
Definition: ina220.h:116
12 bit resolution, 532 us conversion time, default
Definition: ina220.h:82
Shunt and Bus, Triggered.
Definition: ina220.h:48
int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address)
Initialize a current sensor.
64 sample average, 34.05 ms conversion time
Definition: ina220.h:128
Shunt Voltage, Triggered.
Definition: ina220.h:46
int ina220_read_shunt(const ina220_t *dev, int16_t *voltage)
Read shunt voltage.
ina220_range
Shunt voltage measurement range (PGA settings)
Definition: ina220.h:56
uint8_t addr
the slave address of the sensor on the I2C bus
Definition: ina220.h:40
int ina220_read_bus(const ina220_t *dev, int16_t *voltage)
Read bus voltage register.
32 V bus voltage full scale range, default.
Definition: ina220.h:66
+/- 160 mV range
Definition: ina220.h:59
11 bit resolution, 276 us conversion time
Definition: ina220.h:112
16 sample average, 8.51 ms conversion time
Definition: ina220.h:124
Bus Voltage, Triggered.
Definition: ina220.h:47
i2c_t i2c
I2C device the sensor is connected to.
Definition: ina220.h:39
ina220_sadc
Shunt ADC settings.
Definition: ina220.h:74
32 sample average, 17.02 ms conversion time
Definition: ina220.h:94
9 bit resolution, 84 us conversion time
Definition: ina220.h:108
+/- 80 mV range
Definition: ina220.h:58
int ina220_read_power(const ina220_t *dev, int16_t *power)
Read power consumption.
int ina220_read_current(const ina220_t *dev, int16_t *current)
Read shunt current.
Shunt and Bus, Continuous, default.
Definition: ina220.h:52
Low-level I2C peripheral driver interface definition.
Device descriptor for INA220 sensors.
Definition: ina220.h:38