123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #ifndef INA219_h
- #define INA219_h
- #include "stm8s.h"
- #define CURRENT_SHUNT_RESISTANCE 10
- #define INA219_ADDRESS (uint8_t)(0x40 << 1)
- #define INA219_ADDR_RD (INA219_ADDRESS | 0x01)
- #define CURRENT_LSB 244
- #define POWER_LSB 4880
- #define CALIBRATION_VALUE 16777
- #define INA219_REG_CONFIG 0x00
- #define INA219_REG_SHUNTVOLTAGE 0x01
- #define INA219_REG_BUSVOLTAGE 0x02
- #define INA219_REG_POWER 0x03
- #define INA219_REG_CURRENT 0x04
- #define INA219_REG_CALIBRATION 0x05
- typedef enum
- {
- INA219_RESET_OFF = 0x0000,
- INA219_RESET_ON = 0x8000
- } ina219_reset_t;
- typedef enum
- {
- INA219_RANGE_16V = 0x0000,
- INA219_RANGE_32V = 0x2000
- } ina219_bvr_t;
- typedef enum
- {
- INA219_GAIN_40MV = 0x0000,
- INA219_GAIN_80MV = 0x0800,
- INA219_GAIN_160MV = 0x1000,
- INA219_GAIN_320MV = 0x1800
- } ina219_pg_t;
- typedef enum
- {
- INA219_BUS_RES_9BIT = 0x0000,
- INA219_BUS_RES_10BIT = 0x0080,
- INA219_BUS_RES_11BIT = 0x0100,
- INA219_BUS_RES_12BIT = 0x0180,
- INA219_BUS_RES_12BIT_1S = 0x0400,
- INA219_BUS_RES_12BIT_2S = 0x0480,
- INA219_BUS_RES_12BIT_4S = 0x0500,
- INA219_BUS_RES_12BIT_8S = 0x0580,
- INA219_BUS_RES_12BIT_16S = 0x0600,
- INA219_BUS_RES_12BIT_32S = 0x0680,
- INA219_BUS_RES_12BIT_64S = 0x0700,
- INA219_BUS_RES_12BIT_128S = 0x0780
- } ina219_badc_t;
- typedef enum
- {
- INA219_SHUNT_RES_9BIT = 0x0000,
- INA219_SHUNT_RES_10BIT = 0x0008,
- INA219_SHUNT_RES_11BIT = 0x0010,
- INA219_SHUNT_RES_12BIT = 0x0018,
- INA219_SHUNT_RES_12BIT_1S = 0x0040,
- INA219_SHUNT_RES_12BIT_2S = 0x0048,
- INA219_SHUNT_RES_12BIT_4S = 0x0050,
- INA219_SHUNT_RES_12BIT_8S = 0x0058,
- INA219_SHUNT_RES_12BIT_16S = 0x0060,
- INA219_SHUNT_RES_12BIT_32S = 0x0068,
- INA219_SHUNT_RES_12BIT_64S = 0x0070,
- INA219_SHUNT_RES_12BIT_128S = 0x0078
- } ina219_sadc_t;
- typedef enum
- {
- INA219_MODE_POWER_DOWN = 0x0000,
- INA219_MODE_SHUNT_TRIG = 0x0001,
- INA219_MODE_BUS_TRIG = 0x0002,
- INA219_MODE_SHUNT_BUS_TRIG = 0x0003,
- INA219_MODE_ADC_OFF = 0x0004,
- INA219_MODE_SHUNT_CONT = 0x0005,
- INA219_MODE_BUS_CONT = 0x0006,
- INA219_MODE_SHUNT_BUS_CONT = 0x0007
- } ina219_mode_t;
- typedef struct {
- uint8_t INA219_Addr;
- ina219_reset_t INA219_RST;
- ina219_bvr_t INA219_BVR;
- ina219_pg_t INA219_PG;
- ina219_badc_t INA219_BADC;
- ina219_sadc_t INA219_SADC;
- ina219_mode_t INA219_MODE;
- } INA219_InitTypeDef;
- void INA219_Config(void);
- ina219_bvr_t getRange(void);
- ina219_pg_t getGain(void);
- ina219_badc_t getBusRes(void);
- ina219_sadc_t getShuntRes(void);
- ina219_mode_t getMode(void);
- int16_t readShuntVoltage(void);
- uint16_t readBusVoltage(void);
- uint16_t readBusCurrent(void);
- uint32_t readBusPower(void);
- uint16_t getMaxPossibleCurrent(void);
- uint16_t getMaxCurrent(void);
- uint16_t getMaxShuntVoltage(void);
- uint32_t getMaxPower(void);
- #endif
|