Maxim Integrated / MAX17055_EZconfig

Dependents:   Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot

Fork of max17055 by Maxim Integrated

Files at this revision

API Documentation at this revision

Comitter:
fneirab
Date:
Sun Sep 24 19:32:14 2017 +0000
Parent:
1:a031f0c6a71e
Child:
3:f77a8345b0e3
Commit message:
New partial Init function and a complete get_temp function;

Changed in this revision

max17055.cpp Show annotated file Show diff for this revision Revisions of this file
max17055.h Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/max17055.h	Thu Sep 21 22:35:39 2017 +0000
+++ b/max17055.h	Sun Sep 24 19:32:14 2017 +0000
@@ -36,6 +36,10 @@
 // Include
 #include "mbed.h"
 
+/* STATUS register bits */
+#define MAX17055_STATUS_BST             (1 << 3)
+#define MAX17055_STATUS_POR             (1 << 1)
+
 
 /**
  * @brief Library for the MAX17055\n
@@ -246,8 +250,56 @@
     ~MAX17055();
     
     
+    /**
+    * \brief        Write and Verify a MAX17055 register
+    * \par          Details
+    *               This function wites and verifies if the writing process was successful
+    *
+    * \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 write errors
+    *              -2 if read errors
+    *              -3 if data curruption
+    * 
+    */
+    
+    
+    int write_and_verify_reg(Registers_e reg_addr, uint16_t reg_data);
+    
+    /**
+    * \brief        Initialise Function for MAX17055
+    * \par          Details
+    *               This function intitializes the MAX17055
+    *
+    * \retval       1 on success 
+    *              -1 if errors exist
+    */
+    
+    
+    int init();
+    
+    ////////////////////////////////////////////////////////////////////////////////
 
-//protected:
+/**
+    * \brief        Get Internal Temperature Function for MAX17055
+    * \par          Details
+    *               This function sends a request to access the internal
+    *               of the MAX17055
+    *
+    * \param[out]   *temp     - pointer? or Reference? to the volue of the temperature
+    * \retval       1 on success 
+    *               0 on success
+    *              -1 if errors exist
+    */
+    
+    
+    int get_temperature(int *temp);
+       
+
+protected:
     /**
      * @brief       Write Register
      * @details     Writes data to max17055 Register
@@ -265,23 +317,9 @@
      */
     int32_t readReg(Registers_e reg_addr, uint16_t &value);
     
-    /**
-    * \brief        Write and Verify a MAX17055 register
-    * \par          Details
-    *               This function wites and verifies if the writing process was successful
-    *
-    * \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 write_and_verify_reg(Registers_e reg_addr, uint16_t reg_data);
+
 
-   
+
 
 private: