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 
46 typedef enum ina220_mode {
56 
60 typedef enum ina220_range {
61  INA220_RANGE_40MV = 0x0000,
62  INA220_RANGE_80MV = 0x0800,
63  INA220_RANGE_160MV = 0x1000,
64  INA220_RANGE_320MV = 0x1800,
66 
70 typedef enum ina220_brng {
74 
80 typedef enum ina220_sadc {
82  INA220_SADC_9BIT = 0x0000,
105 } ina220_sadc_t;
106 
112 typedef enum ina220_badc {
137 } ina220_badc_t;
138 
140 #define INA220_RESET_BIT (0x8000)
141 
143 #define INA220_BUS_VOLTAGE_SHIFT (3)
144 
155 int ina220_init(ina220_t *dev, i2c_t i2c, uint8_t address);
156 
166 int ina220_set_calibration(const ina220_t *dev, uint16_t calibration);
167 
177 int ina220_set_config(const ina220_t *dev, uint16_t config);
178 
188 int ina220_read_shunt(const ina220_t *dev, int16_t *voltage);
189 
204 int ina220_read_bus(const ina220_t *dev, int16_t *voltage);
205 
215 int ina220_read_current(const ina220_t *dev, int16_t *current);
216 
226 int ina220_read_power(const ina220_t *dev, int16_t *power);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif /* INA220_H */
233 
12 bit resolution, 532 us conversion time, default
Definition: ina220.h:120
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:51
ina220_mode
INA220 possible mode settings.
Definition: ina220.h:46
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:94
int ina220_set_calibration(const ina220_t *dev, uint16_t calibration)
Write to calibration register.
ina220_brng
Bus voltage measurement range.
Definition: ina220.h:70
16 sample average, 8.51 ms conversion time
Definition: ina220.h:98
2 sample average, 1.06 ms conversion time
Definition: ina220.h:124
2 sample average, 1.06 ms conversion time
Definition: ina220.h:92
128 sample average, 68.10 ms conversion time
Definition: ina220.h:104
10 bit resolution, 148 us conversion time
Definition: ina220.h:84
ina220_badc
Bus ADC settings.
Definition: ina220.h:112
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:108
Shunt Voltage, Continuous.
Definition: ina220.h:52
64 sample average, 34.05 ms conversion time
Definition: ina220.h:102
8 sample average, 4.26 ms conversion time
Definition: ina220.h:128
11 bit resolution, 276 us conversion time
Definition: ina220.h:86
16 V bus voltage full scale range
Definition: ina220.h:71
enum ina220_badc ina220_badc_t
Bus ADC settings.
8 sample average, 4.26 ms conversion time
Definition: ina220.h:96
4 sample average, 2.13 ms conversion time
Definition: ina220.h:126
+/- 320 mV range, default
Definition: ina220.h:64
Power down.
Definition: ina220.h:47
int ina220_set_config(const ina220_t *dev, uint16_t config)
Write to configuration register.
+/- 40 mV range
Definition: ina220.h:61
12 bit resolution, 532 us conversion time, same as INA220_SADC_12BIT
Definition: ina220.h:90
Bus Voltage, Continuous.
Definition: ina220.h:53
128 sample average, 68.10 ms conversion time
Definition: ina220.h:136
9 bit resolution, 84 us conversion time
Definition: ina220.h:82
10 bit resolution, 148 us conversion time
Definition: ina220.h:116
32 sample average, 17.02 ms conversion time
Definition: ina220.h:132
12 bit resolution, 532 us conversion time, same as INA220_BADC_12BIT
Definition: ina220.h:122
12 bit resolution, 532 us conversion time, default
Definition: ina220.h:88
Shunt and Bus, Triggered.
Definition: ina220.h:50
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:134
Shunt Voltage, Triggered.
Definition: ina220.h:48
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:60
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:72
+/- 160 mV range
Definition: ina220.h:63
11 bit resolution, 276 us conversion time
Definition: ina220.h:118
16 sample average, 8.51 ms conversion time
Definition: ina220.h:130
Bus Voltage, Triggered.
Definition: ina220.h:49
i2c_t i2c
I2C device the sensor is connected to.
Definition: ina220.h:39
ina220_sadc
Shunt ADC settings.
Definition: ina220.h:80
32 sample average, 17.02 ms conversion time
Definition: ina220.h:100
9 bit resolution, 84 us conversion time
Definition: ina220.h:114
+/- 80 mV range
Definition: ina220.h:62
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:54
Low-level I2C peripheral driver interface definition.
Device descriptor for INA220 sensors.
Definition: ina220.h:38