a
INA226.hpp@3:e0ddd1dfa2cc, 2021-07-31 (annotated)
- Committer:
- MPPT51
- Date:
- Sat Jul 31 06:25:47 2021 +0000
- Revision:
- 3:e0ddd1dfa2cc
- Parent:
- 2:8950b0f31d73
ina226 commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 1:e0ebc6af5e04 | 1 | /** |
tosihisa | 1:e0ebc6af5e04 | 2 | * @section LICENSE |
tosihisa | 0:3a05c5755625 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
tosihisa | 1:e0ebc6af5e04 | 4 | * Copyright (C) 2012 tosihisa |
tosihisa | 1:e0ebc6af5e04 | 5 | * |
tosihisa | 1:e0ebc6af5e04 | 6 | * @section DESCRIPTION |
tosihisa | 1:e0ebc6af5e04 | 7 | * INA226 - Bi-Directional CURRENT/POWER MONITOR with I2C |
tosihisa | 1:e0ebc6af5e04 | 8 | * http://strawberry-linux.com/catalog/items?code=12031 |
tosihisa | 1:e0ebc6af5e04 | 9 | * |
tosihisa | 0:3a05c5755625 | 10 | */ |
tosihisa | 0:3a05c5755625 | 11 | #ifndef __INA226_INCLUDE // { |
tosihisa | 0:3a05c5755625 | 12 | #define __INA226_INCLUDE |
tosihisa | 0:3a05c5755625 | 13 | #include "mbed.h" |
tosihisa | 2:8950b0f31d73 | 14 | /** |
tosihisa | 2:8950b0f31d73 | 15 | * INA226 Class. |
tosihisa | 2:8950b0f31d73 | 16 | */ |
tosihisa | 0:3a05c5755625 | 17 | class INA226 { |
tosihisa | 0:3a05c5755625 | 18 | public: |
tosihisa | 1:e0ebc6af5e04 | 19 | /** |
tosihisa | 1:e0ebc6af5e04 | 20 | * Constructor. |
tosihisa | 1:e0ebc6af5e04 | 21 | * |
tosihisa | 1:e0ebc6af5e04 | 22 | * @param i2c_ instance of I2C. |
tosihisa | 1:e0ebc6af5e04 | 23 | * @param addr_ I2C slave address. |
tosihisa | 1:e0ebc6af5e04 | 24 | * @param freq_ I2C frequency. |
MPPT51 | 3:e0ddd1dfa2cc | 25 | */ //GNDGND(G-G):0x80, Vs+Vs+(1-1):0x8A, SDASDA(D-D):0x94, SCLSCL(C-C):0x9E, GNDVs+(G-1):0x82 |
MPPT51 | 3:e0ddd1dfa2cc | 26 | INA226(I2C &i2c_,int addr_ = 0x80,int freq_ = 100000); //0x94= ?, 0x8A=VsVs_11, 0x80=GNDGND_GG |
tosihisa | 1:e0ebc6af5e04 | 27 | /** |
tosihisa | 1:e0ebc6af5e04 | 28 | * Check INA226 exist. |
tosihisa | 1:e0ebc6af5e04 | 29 | * |
tosihisa | 1:e0ebc6af5e04 | 30 | * @param none |
tosihisa | 1:e0ebc6af5e04 | 31 | * @return 0:NOT EXIST / !0:EXIST |
tosihisa | 1:e0ebc6af5e04 | 32 | */ |
tosihisa | 0:3a05c5755625 | 33 | int isExist(void); |
tosihisa | 1:e0ebc6af5e04 | 34 | /** |
tosihisa | 1:e0ebc6af5e04 | 35 | * INA226 raw level read. |
tosihisa | 1:e0ebc6af5e04 | 36 | * |
tosihisa | 1:e0ebc6af5e04 | 37 | * @param pointer_addr INA226 pointer address. |
tosihisa | 1:e0ebc6af5e04 | 38 | * @param val_ read value. |
tosihisa | 1:e0ebc6af5e04 | 39 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 40 | */ |
tosihisa | 0:3a05c5755625 | 41 | int rawRead(char pointer_addr,unsigned short *val_); |
tosihisa | 1:e0ebc6af5e04 | 42 | /** |
tosihisa | 1:e0ebc6af5e04 | 43 | * INA226 raw level write. |
tosihisa | 1:e0ebc6af5e04 | 44 | * |
tosihisa | 1:e0ebc6af5e04 | 45 | * @param pointer_addr INA226 pointer address. |
tosihisa | 1:e0ebc6af5e04 | 46 | * @param val_ write value. |
tosihisa | 1:e0ebc6af5e04 | 47 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 48 | */ |
tosihisa | 0:3a05c5755625 | 49 | int rawWrite(char pointer_addr,unsigned short val_); |
tosihisa | 1:e0ebc6af5e04 | 50 | /** |
tosihisa | 1:e0ebc6af5e04 | 51 | * Get voltage. |
tosihisa | 1:e0ebc6af5e04 | 52 | * |
tosihisa | 1:e0ebc6af5e04 | 53 | * @param V_ read value; |
tosihisa | 1:e0ebc6af5e04 | 54 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 55 | */ |
tosihisa | 0:3a05c5755625 | 56 | int getVoltage(double *V_); |
tosihisa | 1:e0ebc6af5e04 | 57 | /** |
tosihisa | 1:e0ebc6af5e04 | 58 | * Get current. |
tosihisa | 1:e0ebc6af5e04 | 59 | * |
tosihisa | 1:e0ebc6af5e04 | 60 | * @param I_ read value; |
tosihisa | 1:e0ebc6af5e04 | 61 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 62 | */ |
tosihisa | 0:3a05c5755625 | 63 | int getCurrent(double *I_); |
tosihisa | 1:e0ebc6af5e04 | 64 | /** |
tosihisa | 1:e0ebc6af5e04 | 65 | * Set current calibration. |
tosihisa | 1:e0ebc6af5e04 | 66 | * |
tosihisa | 1:e0ebc6af5e04 | 67 | * @param val write value; |
tosihisa | 1:e0ebc6af5e04 | 68 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 69 | */ |
MPPT51 | 3:e0ddd1dfa2cc | 70 | int setCurrentCalibration(unsigned short val = 0x1AAA); |
MPPT51 | 3:e0ddd1dfa2cc | 71 | //int setConfigResister(unsigned short config = 0x6600 | 0x01C0 | 0x0038 | 0x0007); //0x456F=>0b 0100 010 101 101 111(datasheet pp21-23確認) |
MPPT51 | 3:e0ddd1dfa2cc | 72 | int setConfigResister(unsigned short config = 0x456F); |
MPPT51 | 3:e0ddd1dfa2cc | 73 | |
tosihisa | 0:3a05c5755625 | 74 | private: |
tosihisa | 0:3a05c5755625 | 75 | I2C &i2c; |
tosihisa | 0:3a05c5755625 | 76 | int i2c_addr; |
tosihisa | 0:3a05c5755625 | 77 | int freq; |
tosihisa | 0:3a05c5755625 | 78 | }; |
tosihisa | 0:3a05c5755625 | 79 | #endif // } |