Library DS2782 Stand-Alone Fuel Gauge IC
Diff: ds2782.h
- Revision:
- 1:7cd80eb4df4c
- Parent:
- 0:e6d413e57654
--- a/ds2782.h Sun Nov 30 23:23:42 2014 +0000 +++ b/ds2782.h Wed Dec 17 21:14:59 2014 +0000 @@ -13,6 +13,12 @@ Documentation regarding the MAX9611 might be found here: http://www.maximintegrated.com/en/products/power/battery-management/DS2782.html + + and some very useful tutorials: + http://www.maximintegrated.com/en/products/power/battery-management/DS2782.html/tb_tab2 + http://www.maximintegrated.com/en/app-notes/index.mvp/id/3584 + http://www.maximintegrated.com/en/app-notes/index.mvp/id/3463 + */ @@ -71,6 +77,46 @@ }RegAddr; + typedef enum { + + CONTROL = 0x60, //Control Register + AB =0x61, //Accumulation Bias + AC_MSB = 0x62, //Aging Capacity MSB + AC_LSB = 0x63, //Aging Capacity LSB + VCHG = 0x64, //Charge Voltage + IMIN =0x65, //Minimum Charge Current + VAE = 0x66, //Active Empty Voltage + IAE = 0x67, //Active Empty Current + ACTIVE_EMPTY_40, + RSNSP, //Sense Resistor Prime + FULL_40_MSB, + FULL_40_LSB, + FULL_3040_SLOPE, + FULL_2030_SLOPE, + FULL_1020_SLOPE, + FULL_0010_SLOPE, + AE_3040_SLOPE, + AE_2030_SLOPE, + AE_1020_SLOPE, + AE_0010_SLOPE, + SE_3040_SLOPE, + SE_2030_SLOPE, + SE_1020_SLOPE, + SE_0010_SLOPE, + RSGAIN_MSB, //Sense Resistor Gain MSB + RSGAIN_LSB, //Sense Resistor Gain LSB + RSTC, //Sense Resistor Temp. Coeff. + FRSGAIN_MSB, //Factory Gain MSB + FRSGAIN_LSB, //Factory Gain LSB + I2C_SLAVE_ADDR= 0x7E //2-Wire Slave Address + }ParamEepromReg; + + + + + + + /** Write data to the given register * * @returns @@ -98,6 +144,15 @@ uint16_t data16Bit= (msbByte<<8)|(lsbByte); return data16Bit; } + + /** divide 16 bit word to 2 8bit bytes + * @param 1st byte + * @param buf + */ + inline void fillBuf(uint16_t varVal, uint8_t* buf){ + buf[0]= ((varVal>>8)&0xFF); + buf[1]= ((varVal)&0xFF); + } I2C mI2c; uint8_t mI2cAddr; @@ -111,6 +166,15 @@ /**********public methods********************************/ public: + + typedef enum { + PORF = 0x02, //Power-On Reset Flag – Useful for reset detection, see text below. + UVF =0x04, //Under-Voltage Flag + LEARNF = 0x10, //Learn Flag – When set to 1, a charge cycle can be used to learn battery capacity. + SEF = 0x20, //Standby Empty Flag + AEF = 0x40, //Active Empty Flag + CHGTF =0x80, //Charge Termination Flag + }StatusReg ; /** Create an SI7020 instance * @param sda pin @@ -136,13 +200,18 @@ bool readTemperature(void); bool readCurrent(void); bool readVoltage(void); + bool setACRRegister(uint16_t reg); // set to 0 clears LEARNF and other flags + bool setEepromBlockRegister(ParamEepromReg reg, uint8_t * value, uint8_t length); + uint8_t readStatusReg(void); + float readAcrReg(void); + uint8_t readRarcReg(void); + // setters-getters float getTemperature(void); float getCurrent(void); float getVoltage(void); - - float readTest(void); + }; #endif \ No newline at end of file