This is a library for the MAX17055 Li+ Battery Fuel Gauge.
Dependents: Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot
Fork of max17055 by
Diff: max17055.cpp
- Revision:
- 2:ff7db397b70f
- Parent:
- 1:a031f0c6a71e
- Child:
- 3:f77a8345b0e3
--- a/max17055.cpp Thu Sep 21 22:35:39 2017 +0000 +++ b/max17055.cpp Sun Sep 24 19:32:14 2017 +0000 @@ -113,7 +113,7 @@ } - +/////////////////////////////////////////////////////////////////////////////// /** * \brief Write and Verify a MAX17055 register * \par Details @@ -155,20 +155,81 @@ } else return 1; } -// -//int MAX17055::init() -//{ -// int temp, data, StatusPOR, RepCap, RepSOC; -// float TTE_val; -// // Attach Interrupt to ALRT pin -// -// // Read the status power up on reset (POR is bit 1 in that register) -// // 0 means that POR has not occured, 1 means that it has just occured, has to be cleared -// StatusPOR = readReg(STATUS) & 0x0002; -// -// if (StatusPOR == 0) { -// goto step_4P3; -// } else { + +//////////////////////////////////////////////////////////////////////////////// + +/** + * \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() +{ + int status; + uint16_t read_data; + + status = readReg(MAX17055_VERSION_REG, read_data); + if (status == 0) + return status; //Device is not present in the i2c Bus + + /* Step 0: Check for POR */ + /* Skip load model if POR bit is cleared */ + + readReg(MAX17055_STATUS_REG, read_data); + + if (!(read_data & MAX17055_STATUS_POR ) ) + return -1; //POR is not set. Skip Initialization. + + /* Step 1: Check if FStat.DNR == 0 */ + // Need ro design other functions here + 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 + */ + + +int MAX17055::get_temperature(int *temp) +{ + + int ret; + uint16_t data; + + ret = readReg(MAX17055_TEMP_REG, data); + if (ret < 0) + return ret; + + *temp = data; + /* The value is signed. */ + if (*temp & 0x8000) + *temp |= 0xFFFF0000; + + /* The value is converted into centigrade scale */ + /* Units of LSB = 1 / 256 degree Celsius */ + *temp >>= 8; + + return 1; +} + //step_1: // // Wait until MAX17055 complete setup operations (Data is Ready) // while(readReg(F_STAT) & 0x0001) delay(10); @@ -274,8 +335,8 @@ // if (write_and_verify_reg(CYCLES, saved_param->cycles) != E_NO_ERROR) { // return -1; // } - +// //return E_NO_ERROR; -//} +// // //saved_fuel_gauge_params_t default_param = {0,0,0,0,0}; \ No newline at end of file