This is a library for the MAX17055 Li+ Battery Fuel Gauge.
Fork of max17055 by
Diff: max17055.cpp
- Revision:
- 3:f77a8345b0e3
- Parent:
- 2:ff7db397b70f
- Child:
- 4:a4d6ae2182c2
diff -r ff7db397b70f -r f77a8345b0e3 max17055.cpp --- a/max17055.cpp Sun Sep 24 19:32:14 2017 +0000 +++ b/max17055.cpp Tue Sep 26 00:15:04 2017 +0000 @@ -159,14 +159,14 @@ //////////////////////////////////////////////////////////////////////////////// /** - * \brief Initialise Function for MAX17055 - * \par Details - * This function intitializes the MAX17055 - * - * \retval 1 on success - * 0 if device is not present - * -1 if errors exist - */ +* \brief Initialise Function for MAX17055 +* \par Details +* This function intitializes the MAX17055 +* +* \retval 1 on success +* 0 if device is not present +* -1 if errors exist +*/ int MAX17055::init() @@ -187,25 +187,32 @@ return -1; //POR is not set. Skip Initialization. /* Step 1: Check if FStat.DNR == 0 */ - // Need ro design other functions here + // Do not continue until FSTAT.DNR == 0 + + while(readReg(MAX17055_FSTAT_REG, read_data)&1) + { + wait_ms(10);//10 ms wait empty loop + } + + return 1; } //////////////////////////////////////////////////////////////////////////////// /** - * \brief Get Internal Temperature Function for MAX17055 - * \par Details - * This function sends a request to access the internal - * of the MAX17055 - * - * \param[in] reg_addr - register address - * \param[out] reg_data - the variable that contains the data to write - * to the register address - * \retval 1 on success - * 0 on success - * -1 if errors exist - */ +* \brief Get Internal Temperature Function for MAX17055 +* \par Details +* This function sends a request to access the internal +* of the MAX17055 +* +* \param[in] reg_addr - register address +* \param[out] reg_data - the variable that contains the data to write +* to the register address +* \retval 1 on success +* +* -1 if errors exist +*/ int MAX17055::get_temperature(int *temp) @@ -229,7 +236,41 @@ return 1; } + + +//////////////////////////////////////////////////////////////////////////////// + +/** +* \brief Forced Exit Hibernate Mode Function for MAX17055 +* \par Details +* This function executes a force exit from hibernate mode. +* +* \retval returns HibCFG original value before forced Exit Hybernate mode +* +*/ + +uint16_t MAX17055::forcedExitHyberMode() +{ + uint16_t hibcfg; + +/* Force exit from hibernate */ + + //STEP 0: Store original HibCFG value + readReg(MAX17055_HIBCFG_REG, hibcfg); + + //STEP 1: Write to Soft-Wakeup Commannd Register + writeReg(MAX17055_VFSOC0_QH0_LOCK_REG, 0x90); //Soft-Wakeup from hybernate + + //STEP 2: Write to Hibernate Configuration register + writeReg(MAX17055_HIBCFG_REG, 0x0); //disable hibernate mode + + //STEP 3:Write to Soft-Wakeup Commannd Register + writeReg(MAX17055_VFSOC0_QH0_LOCK_REG, 0x0); //Clear All commnads + + return hibcfg; +} + //step_1: // // Wait until MAX17055 complete setup operations (Data is Ready) // while(readReg(F_STAT) & 0x0001) delay(10);