i2c working with old hk

Dependencies:   mbed-rtos mbed

Fork of BAE_vr2_1_1 by green rosh

Files at this revision

API Documentation at this revision

Comitter:
sakthipriya
Date:
Wed Dec 17 06:06:59 2014 +0000
Parent:
13:1b37d98840d3
Commit message:
i2c working with old hk

Changed in this revision

HK.cpp Show annotated file Show diff for this revision Revisions of this file
HK.h Show annotated file Show diff for this revision Revisions of this file
beacon.cpp Show annotated file Show diff for this revision Revisions of this file
fault.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1b37d98840d3 -r ef6be8ac6569 HK.cpp
--- a/HK.cpp	Wed Dec 17 05:25:04 2014 +0000
+++ b/HK.cpp	Wed Dec 17 06:06:59 2014 +0000
@@ -1,273 +1,79 @@
 #include "HK.h"
  
- MAX17048 master(A4,A5,100000);//object for battery gauge class--CHECK SDA,SCL LINES,FREQUENCY
- void FUNC_BATTERYGAUGE_INIT();
+DigitalOut SelectLine3 (D4); // MSB of Select Lines
+DigitalOut SelectLine2 (D3);
+DigitalOut SelectLine1 (D2);
+DigitalOut SelectLine0 (D1); // LSB of Select Lines
  
-//GPIO pins used=> D2-D12, A0-A1
-
-DigitalOut SelectLinesA[]={D2,D3,D4,D5};//to mux1=>voltage mux
-DigitalOut SelectLinesB[]={PTB18,D7,PTB19};//to mux2=>current mux(differential mux)   Is this 3 or 4?
-DigitalOut SelectLinesC[]={PTC0,PTC4,PTC6,PTC7};//to mux3=>temp mux
+AnalogIn CurrentInput(A1); // Input from Current Multiplexer
+AnalogIn VoltageInput(A2); // Input from Voltage Multiplexer
+AnalogIn TemperatureInput(A3); // input from Temperature Multiplexer
 
-//--------------------------------------------MSB is SelectLines[0],LSB is SelectLines[3]-------------------------------- 
-
-AnalogIn CurrentInput(A0); // Input from Current Mux
-AnalogIn VoltageInput(A1); // Input from Voltage Multiplexer
-AnalogIn TemperatureInput(A2); /*Input from Temperature Multiplexer,thermistor Multiplexer- same multiplexer for both(lines 1-4 for thermistor,line 0 for temperature sensor)*/
- 
-
-
- 
-int quantiz(float start,float step,float x)     // accepts min and measured values and step->quantises on a scale 0-15..(4 bit quantisation)
+SensorData Sensor; 
+int quantiz(float start,float step,float x)
 {
     int y=(x-start)/step;
     if(y<=0)y=0;
     if(y>=15)y=15;
     return y;
 }
- 
-void init_beacon(ShortBeacy* x,SensorDataQuantised y)  
-{
-    (*x).Voltage[0]=y.Vcell_soc>>4;//quantised value
-    (*x).Temp[0]=y.PanelTemperature[0];//quantised value
-    (*x).Temp[1]=y.PanelTemperature[1];//quantised value
-    (*x).AngularSpeed[0]=y.AngularSpeed[0];
-    (*x).AngularSpeed[1]=y.AngularSpeed[1];
-    
-    (*x).SubsystemStatus[0]=145;//dummy values----------to be changed-------------------
-    (*x).ErrorFlag[0]=3;//dummy values----------to be changed-------------------
+ShortBeacy Shortbeacon; 
+void init_beacon(ShortBeacy x){
+   ;
 }
-   SensorData SensorUQ; 
-    SensorDataQuantised SensorQuantised;
-    ShortBeacy Shortbeacon;
+ 
 
-void FUNC_HK_MAIN()             
+void FUNC_HK_MAIN()
 {
-    //define structure variables    
- 
-    
-    
+    printf("\nEntered function  HK MAIN\n");
     
-    //initialise all selectlines to zeroes->1st line of muxes selected
-    SelectLinesA[0]=SelectLinesA[1]=SelectLinesA[2]=SelectLinesA[3]=0;
-    SelectLinesB[0]=SelectLinesB[1]=SelectLinesB[2]=0;
-    SelectLinesC[0]=SelectLinesC[1]=SelectLinesC[2]=SelectLinesC[3]=0;
+     Shortbeacon.Voltage[0]=1;
+   Shortbeacon.AngularSpeed[0]=2;
+    Shortbeacon.AngularSpeed[1]=3;
+    Shortbeacon.SubsystemStatus[0]=145;
+    Shortbeacon.Temp[0]=1;
+    Shortbeacon.Temp[1]=2;
+    Shortbeacon.Temp[2]=3;
+    Shortbeacon.ErrorFlag[0]=3;
     
     int LoopIterator;
-    int SelectLineIterator;
-    
-    float resistance_thermistor,voltage_thermistor;//for thermistor
+ 
+    SelectLine0=0;
+    SelectLine1=0;
+    SelectLine2=0;
+    SelectLine3=0;
  
-  //measurement from voltage sensor=> 16 sensors in place
- for(LoopIterator=0; LoopIterator<16; LoopIterator++) 
-{       
-        //following lines read the sensor values and stores them in 'SensorData' structure's variable 'Sensor'
-        SensorUQ.Voltage[LoopIterator]=(VoltageInput.read()*3.3*5.545454);//resistors in voltage divider=>15Mohm,3.3Mohm
-               
-        if(LoopIterator%2==0)
-            SensorQuantised.Voltage[LoopIterator/2]=quantiz(vstart,vstep,SensorUQ.Voltage[LoopIterator]);
-                           
-        else
-            SensorQuantised.Voltage[(LoopIterator)/2]=SensorQuantised.Voltage[(LoopIterator)/2]<<4+quantiz(vstart,vstep,SensorUQ.Voltage[LoopIterator]);
-            
-    
-    
-    // The following lines are used to iterate the select lines from 0 to 15
-    //following is an algorithm similar to counting binary numbers of 4 bit
-       for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--)
-        {
-            if(SelectLinesA[SelectLineIterator]==0)
-            {
-                SelectLinesA[SelectLineIterator]=1;
-                break;
-            }
-            else SelectLinesA[SelectLineIterator]=0;
-    
+    for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
+        
+        if(LoopIterator%2==0) {
+            Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
+            Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
+            Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
+        } else {
+            Sensor.Current[(LoopIterator-1)/2]=(Sensor.Current[(LoopIterator-1)/2]<<4)+quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
+            Sensor.Voltage[(LoopIterator-1)/2]=(Sensor.Voltage[(LoopIterator-1)/2]<<4)+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
+            Sensor.Temperature[(LoopIterator-1)/2]=(Sensor.Temperature[(LoopIterator-1)/2]<<4)+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
         }
-    
-    
-        wait_us(10.0); //  A delay of 10 microseconds between each sensor output. Can be changed.
+// The following lines are used to iterate the select lines from 0 to 15
+        SelectLine0=!(SelectLine0);
  
- }
- 
- 
- 
- 
+        if(LoopIterator%2==1)
+            SelectLine1=!(SelectLine1);
  
- //measurement from current sensor=>  8 sensors in place 
-
-    for(LoopIterator=0; LoopIterator<8; LoopIterator++) 
-{       
-        //following lines read the sensor values and stores them in 'SensorData' structure variable 'Sensor'
-        SensorUQ.Current[LoopIterator]=(CurrentInput.read()*3.3/(50*rsens));
-        if(LoopIterator%2==0)
-            SensorQuantised.Current[LoopIterator/2]=quantiz(cstart,cstep,SensorUQ.Current[LoopIterator]);
-        else
-            SensorQuantised.Current[(LoopIterator)/2]=SensorQuantised.Current[(LoopIterator)/2]<<4+quantiz(cstart,cstep,SensorUQ.Current[LoopIterator]);
-
+        if(LoopIterator%4==3)
+            SelectLine2=!(SelectLine2);
+ 
+        if(LoopIterator%8==7)
+            SelectLine3=!(SelectLine3);
         
-        // The following lines are used to iterate the select lines from 0 to 7
-        //following is an algorithm similar to counting binary numbers of 3 bits
-        for(SelectLineIterator=2;SelectLineIterator>=0;SelectLineIterator--)
-        {
-            if(SelectLinesB[SelectLineIterator]==0)
-            {
-                SelectLinesB[SelectLineIterator]=1;
-                break;
-            }
-            else SelectLinesB[SelectLineIterator]=0;
-    
-        }
-    
-    
         wait_us(10.0); //  A delay of 10 microseconds between each sensor output. Can be changed.
  
-}
-    
-    
-//measurement of temperature
-//temperature measurement=> 4 thermistors, 1 temperature sensor
-//mux line 1=>temp sensor, mux lines 2 to 5 =>thermistors
-
-    for(LoopIterator=0; LoopIterator<5; LoopIterator++) 
-{       
-        //following lines read the sensor values and stores them in 'SensorData' structure variable 'Sensor'
-        SensorUQ.Temperature[LoopIterator]=(-90.7*3.3*TemperatureInput.read()+190.1543);
-        voltage_thermistor=TemperatureInput.read()*3.3;//voltage across thermistor
-        resistance_thermistor=24000*voltage_thermistor/(3.3-voltage_thermistor);//resistance of thermistor
-        //PanelTemperature will be updated depending on voltage_thermistor value later in the lines to follow
-        
-        if(LoopIterator%2==0)
-     {                
-            if(LoopIterator<1)                      //->corresponding to temperature sensor
-                SensorQuantised.Temperature[(LoopIterator)/2]=quantiz(tstart,tstep,SensorUQ.Temperature[LoopIterator]);
-         
-            else                                    //->corresponding to thermistor
-            {    
-                if(voltage_thermistor<1.378) //Temperature>12 degC
-                    SensorUQ.PanelTemperature[(LoopIterator-1)]=(3694/log(24.032242*resistance_thermistor));
-                    
-                else   
-                    SensorUQ.PanelTemperature[(LoopIterator-1)]=(3365.4792/log(7.60404*resistance_thermistor));
-                    
-                    
-                SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=quantiz(tstart_thermistor,tstep_thermistor,SensorUQ.PanelTemperature[(LoopIterator-1)]);
-                    
-            }
-            
-     } 
+    }
+   
+       printf("\nVoltage  is %u\n",Shortbeacon.Voltage[0]);
+       printf("\nCurrent  is %u\n",Shortbeacon.Temp[0]);
+       
     
-    else
-     {           
-            if(LoopIterator<1)
-                SensorQuantised.Temperature[(LoopIterator)/2]=SensorQuantised.Temperature[(LoopIterator)/2]<<4+quantiz(tstart,tstep,SensorUQ.Temperature[LoopIterator]); 
-            
-            else
-             {  
-                if(voltage_thermistor<1.378) //Temperature>12 degC 
-                     SensorUQ.PanelTemperature[LoopIterator-1]=(3694/log(24.032242*resistance_thermistor));
-                                    
-                  
-                else
-                     SensorUQ.PanelTemperature[LoopIterator-1]=(3365.4792/log(7.60404*resistance_thermistor));
-                    
-                SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=SensorQuantised.PanelTemperature[(LoopIterator-1)/2]<<4+quantiz(tstart_thermistor,tstep_thermistor,SensorUQ.PanelTemperature[LoopIterator-1]);
-                  
-            }
-            
-      }
-      
-
-    
-    
-// The following lines are used to iterate the select lines from 0 to 4
-    
-       //following is an algorithm similar to counting binary numbers of 4 bit
-       for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--)
-        {
-            if(SelectLinesC[SelectLineIterator]==0)
-            {
-                SelectLinesC[SelectLineIterator]=1;
-                break;
-            }
-            else SelectLinesC[SelectLineIterator]=0;
-    
-        }
-    
-    
-        wait_us(10.0); //  A delay of 10 microseconds between each sensor output. Can be changed.
         
+ printf("\nExited function HK MAIN\n");
 }
-
-
-
-    //update battery gauge parameters->
-    float batteryparameters[4];//to populate battery parameters of struct variable Sensor
-    FUNC_BATTERYGAUGE_MAIN(batteryparameters);//passing array to function 
-    
-    SensorUQ.Vcell=batteryparameters[0];
-    SensorUQ.soc=batteryparameters[1];
-    SensorUQ.crate=batteryparameters[2];
-    SensorUQ.alerts=batteryparameters[3];
-    
-    SensorQuantised.Vcell_soc=quantiz(Vcell_start,Vcell_step,SensorUQ.Vcell);
-    SensorQuantised.Vcell_soc=SensorQuantised.Vcell_soc<<4+quantiz(soc_start,soc_step,SensorUQ.soc);
-    SensorQuantised.alerts=SensorUQ.alerts;
-    SensorQuantised.crate=quantiz(crate_start,crate_step,SensorUQ.crate);   
-
-    
-    //update magnetometer data->
-    //populate values in structure variable 'Sensor' from data to be given by Green
-     SensorQuantised.AngularSpeed[0]=quantiz(AngularSpeed_start,AngularSpeed_step,SensorUQ.AngularSpeed[1]);
-     SensorQuantised.AngularSpeed[0]=SensorQuantised.AngularSpeed[0]<<4+quantiz(AngularSpeed_start,AngularSpeed_step,SensorUQ.AngularSpeed[0]);
-     SensorQuantised.AngularSpeed[1]=quantiz(AngularSpeed_start,AngularSpeed_step,SensorUQ.AngularSpeed[2]);
-     
-     //update gyro data->
-    //populate values in structure variable 'Sensor' from data to be given by Green
-     SensorQuantised.Bnewvalue[0]=quantiz(Bnewvalue_start,Bnewvalue_step,SensorUQ.Bnewvalue[1]);
-     SensorQuantised.Bnewvalue[0]=SensorQuantised.Bnewvalue[0]<<4+quantiz(Bnewvalue_start,Bnewvalue_step,SensorUQ.Bnewvalue[0]);
-     SensorQuantised.Bnewvalue[1]=quantiz(Bnewvalue_start,Bnewvalue_step,SensorUQ.Bnewvalue[2]);
-
-     
-     
-     
-      //update beacon structure
-    init_beacon(&Shortbeacon,SensorQuantised);//Shortbeacon is passed 
-    
-    
-}
-
-
-void FUNC_BATTERYGAUGE_MAIN(float array[])
-{
-    float vcell=master.vcell();
-    float soc=master.soc();
-    float crate=master.crate();
-    
-    printf("\nVcell=%f",vcell);
-    printf("\nSOC=%f",soc);
-    printf("\nC_rate=%f",crate);
-    
-    array[0]=vcell;
-    array[1]=soc;
-    array[2]=crate;
-    if (master.alerting()== true)       //alert is on
-    {   
-        array[3]=master.alertFlags();
-        master.clearAlert();//clear alert
-        master.clearAlertFlags();//clear all alert flags
-    }
-    
-    
-}
-
-void FUNC_BATTERYGAUGE_INIT()
-{
-    master.disable_sleep();
-    master.disable_hibernate();
-    master.socChangeAlertEnabled(true);//enabling alert on soc changing by 1%
-    master.emptyAlertThreshold(1);//giving minimum value to disable it to disabling it----------------------
-    master.vAlertMinMaxThreshold();//set min, max value of Valrt register
-    master.vResetThresholdSet();//set threshold voltage for reset
-    master.vResetAlertEnabled(true);//enable alert on reset for V < Vreset
-}
\ No newline at end of file
diff -r 1b37d98840d3 -r ef6be8ac6569 HK.h
--- a/HK.h	Wed Dec 17 05:25:04 2014 +0000
+++ b/HK.h	Wed Dec 17 06:06:59 2014 +0000
@@ -1,469 +1,36 @@
-//to be saved as HK.h
-
 #include "mbed.h"
 #define tstart -40
 #define tstep 8
-#define tstep_thermistor 8//verify!!
-#define tstart_thermistor -40
 #define vstart 3.3
 #define vstep 0.84667
 #define cstart 0.0691
 #define cstep 0.09133
 #define rsens 0.095
-#define Vcell_start 0
-#define Vcell_step 0.56//assuming vcell ranges from 0-8.4
-#define soc_start 0 //========
-#define soc_step 6.6667//assuming soc ranges from 0-100
-#define crate_start 0//------------
-#define crate_step 6.6667//assuming crate ranges from 0-100
-#define Bnewvalue_start -100//in microTesla...max possible field is .0001 T 
-#define Bnewvalue_step 13.333
-#define AngularSpeed_start -10//max possible ang. velocity in space is 10 deg/sec
-#define AngularSpeed_step 1.3333 
 
-typedef struct SensorData
-{
-    float Voltage[16];
-    float Current[8];
-    float Temperature[1];
-    float PanelTemperature[4];
-    float Vcell;
-    float soc;
-    char alerts;
-    //(alerts[0]=1)-> reset indicator=>dont care
-    //(alerts[1]=1)-> Vcell>ValrtMax(5.1V)->will always be on->dont care
-    //(alerts[2]=1)-> Vcell<ValrtMin(5.1V)->indicates deep discharge
-    //(alerts[3]=1)-> Vcell<Vreset(2.5V)
-    //(alerts[5]=1)-> Soc CROSSES the threshold value
-    //(alerts[6]=1)-> alert on (alerts[3]) enabled when Vcell<Vreset(here we set it to be 2.5V)
-    float crate;
-    float BatteryTemperature;   //to be populated
-    char faultpoll;             //polled faults
-    char faultir;               //interrupted faults
-    char power_mode;            //power modes
-    
-    float AngularSpeed[3];      //in order x,y,z
-    float Bnewvalue[3];         //in order Bx,By,Bz
-   
-    
-} SensorData;
+
 
  
-typedef struct SensorDataQuantised {
-    char Voltage[8];
-    char Current[4];
-    char Temperature[1];
-    char PanelTemperature[2];//read by the 4 thermistors on solar panels
-    char Vcell_soc;//MSBs correspond to Vcell, LSBs to Soc
-    char alerts;//UNQUANTISED
-    //(alerts[0]=1)-> reset indicator=>dont care
-    //(alerts[1]=1)-> Vcell>ValrtMax(5.1V)->will always be high->dont care
-    //(alerts[2]=1)-> Vcell<ValrtMin(5.1V)->indicates deep discharge
-    //(alerts[3]=1)-> Vcell<Vreset(2.5V)
-    //(alerts[5]=1)-> Soc CROSSES the threshold value
-    //(alerts[6]=1)-> alert on (alerts[3]) enabled when Vcell<Vreset(here we set it to be 2.5V)
-    char crate;
-    char BatteryTemperature;    //to be populated   
-    char faultpoll;             //polled faults
-    char faultir;               //interrupted faults
-    char power_mode;            //power modes
+struct SensorData {
+    char Voltage[10];
+    char Current[10];
+    char Temperature[10];
+    char faultpoll;
+    char faultir;
+    char power_mode;
+    //float Battery[2];
+};
+
+ 
+typedef struct ShortBeacon {
+    char Voltage[1];
     char AngularSpeed[2];
-    char Bnewvalue[2];
-    
-    //float magnetometer,gyro=>to be addes
-} SensorDataQuantised;
- 
- 
-typedef struct ShortBeacon 
-{
-    char Voltage[1];                            //battery voltage from gauge, needs  to be quantised
-    char AngularSpeed[2];                       //all the 3 data
-    char SubsystemStatus[1];                    //power modes
-    char Temp[2];                               //temp of solar panel
-    //Temp[0]'s LSB=> PanelTemperature[0], Temp[0]'s MSB=> PanelTemperature[1], Temp[1]'s LSB=> PanelTemperature[2], Temp[1]'s MSB=> PanelTemperature[3]
-    char ErrorFlag[1];                          //fault
-}ShortBeacy; 
- 
- 
+    char SubsystemStatus[1]; 
+    char Temp[3];  
+    char ErrorFlag[1];
+}ShortBeacy;
+
  
 void FUNC_HK_MAIN();
  
 int quantiz(float start,float step,float x);
-void init_beacon(ShortBeacy* x,SensorDataQuantised y);
-
-
-//--------------------------------following is header details for battery gauge-------------------------------------------
-
-
-
-#define MAX17048_H
- 
-class MAX17048
-{
-public:
-    /** The default compensation value for the MAX17048
-     */
-    static const char RCOMP0= 0x97;
- 
-    /** Represents the different alert flags for the MAX17048
-     */
-    enum AlertFlags {
-        ALERT_RI = (1 << 0),  /**< Reset indicator */
-        ALERT_VH = (1 << 1),  /**< Voltage high alert */
-        ALERT_VL = (1 << 2),  /**< Voltage low alert */
-        ALERT_VR = (1 << 3),  /**< Voltage reset alert */
-        ALERT_HD = (1 << 4),  /**< SOC low alert */
-        ALERT_SC = (1 << 5)   /**< SOC change alert */
-    };
- 
-    //parametrised constructor
-    MAX17048(PinName sda, PinName scl, int hz = 400000): m_I2C(sda, scl)//should it be same as the uC clock freq
-    {
-        //Set the I2C bus frequency
-        m_I2C.frequency(hz);
-    }
- 
-    // Probe for the MAX17048 and indicate if it's present on the bus
-    bool open()
-     {
-        //Probe for the MAX17048 using a Zero Length Transfer
-        if (!m_I2C.write(m_ADDR, NULL, 0)) {
-            //Return success
-            return true;
-        } else {
-            //Return failure
-            return false;
-        }
-    }
- 
- 
-    // Command the MAX17048 to perform a power-on reset
-    void reset()
-    {
-        //Write the POR command
-        write(REG_CMD, 0x5400);
-    }
-    
-    // Command the MAX17048 to perform a QuickStart
-     void quickStart()
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_MODE);
- 
-        //Set the QuickStart bit
-        value |= (1 << 14);
- 
-        //Write the value back out
-        write(REG_MODE, value);
-    }
-    
-   //disable sleep
-   void disable_sleep()
-    {
-        unsigned short value = read(REG_MODE);
-        value &= ~(1 << 13);
-        write(REG_MODE, value);
-    }
-  
-    //disable the hibernate  of the MAX17048
-    void disable_hibernate()
-    {
-        write(REG_HIBRT, 0x0000);
-    }
-  
-    // Determine whether or not the SOC 1% change alert is enabled on the MAX17048
-    bool socChangeAlertEnabled()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_CONFIG);
- 
-        //Return the status of the ALSC bit
-        if (value & (1 << 6))
-            return true;
-        else
-            return false;
-    }
-    
-    // Enable or disable the SOC 1% change alert on the MAX17048
-    void socChangeAlertEnabled(bool enabled)
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_CONFIG);
- 
-        //Set or clear the ALSC bit
-        if (enabled)
-            value |= (1 << 6);
-        else
-            value &= ~(1 << 6);
- 
-        //Write the value back out
-        write(REG_CONFIG, value);
-} 
-
-    // Determine whether or not the MAX17048 is asserting the ALRT pin
-    bool alerting()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_CONFIG);
- 
-        //Return the status of the ALRT bit
-        if (value & (1 << 5))
-            return true;
-        else
-            return false;
-    }
-    
-    // Command the MAX17048 to de-assert the ALRT pin
-    void clearAlert()
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_CONFIG);
- 
-        //Clear the ALRT bit
-        value &= ~(1 << 5);
- 
-        //Write the value back out
-        write(REG_CONFIG, value);
-    }
-     // return The current SOC empty alert threshold in %.
-    char emptyAlertThreshold()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_CONFIG);
- 
-        //Extract the threshold
-        return 32 - (value & 0x001F);
-    }
- 
-    //Set the SOC empty alert threshold of the MAX17048
-    void emptyAlertThreshold(char threshold)
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_CONFIG);
- 
-        //Update the register value
-        value &= 0xFFE0;
-        value |= 32 - threshold;
- 
-        //Write the 16-bit register
-        write(REG_CONFIG, value);
-    }
-    //return The current low voltage alert threshold in volts.
-    float vAlertMinThreshold()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_VALRT);
- 
-        //Extract the alert threshold
-        return (value >> 8) * 0.02;//least count is 20mV
-    }
-    // Set the low and high voltage alert threshold of the MAX17048
-    void vAlertMinMaxThreshold()
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_VALRT);
- 
-        //Mask off the old value
-    
-                value = 0xFFFF;
-     
-        //Write the 16-bit register
-        write(REG_VALRT, value);
-    }
- 
-    //return The current high voltage alert threshold in volts.
-    float vAlertMaxThreshold()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_VALRT);
- 
-        //Extract the active threshold
-        return (value & 0x00FF) * 0.02;
-    }
-    
-    //return The current reset voltage threshold in volts.
-     float vResetThreshold()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_VRESET_ID);
- 
-        //Extract the threshold
-        return (value >> 9) * 0.04;
-    }
-    
-    // Set the reset voltage threshold of the MAX17048
-    void vResetThresholdSet()
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_VRESET_ID);
- 
-        //Mask off the old //value
-        value &= 0x00FF;//Dis=0
- 
-        value |= 0x7C00;//corresponding to 2.5 V
-    
- 
-        //Write the 16-bit register
-        write(REG_VRESET_ID, value);
-    }
-    
-    // Get the factory programmed 8-bit ID of the MAX17048
-     char id()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_VRESET_ID);
- 
-        //Return only the ID bits
-        return value;
-    }
-    
-    // Determine whether or not the voltage reset alert is enabled on the MAX17048
-    bool vResetAlertEnabled()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_STATUS);
- 
-        //Return the status of the EnVR bit
-        if (value & (1 << 14))
-            return true;
-        else
-            return false;
-    }
-    
-    // Enable or disable the voltage reset alert on the MAX17048
-     void vResetAlertEnabled(bool enabled)
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_STATUS);
-    
-        //Set or clear the EnVR bit
-        if (enabled)
-            value |= (1 << 14);
-        else
-            value &= ~(1 << 14);
- 
-        //Write the value back out
-        write(REG_STATUS, value);
-    }
- 
-    //Get the current alert flags on the MAX17048
-    //refer datasheet-status registers section to decode it.
-    char alertFlags()
-    {
-        //Read the 16-bit register value
-        unsigned short value = read(REG_STATUS);
- 
-        //Return only the flag bits
-        return (value >> 8) & 0x3F;
-    }
-    
-    // Clear all the alert flags on the MAX17048
-    void clearAlertFlags()
-    {
-        //Read the current 16-bit register value
-        unsigned short value = read(REG_STATUS);
- 
-        //Clear the specified flag bits
-        value &= ~( 0x3F<< 8);
- 
-        //Write the value back out
-        write(REG_STATUS, value);
-    }
-    
-    // Get the current cell voltage measurement of the MAX17048
-    float vcell()
-    {
-        //Read the 16-bit raw Vcell value
-        unsigned short value = read(REG_VCELL);
- 
-        //Return Vcell in volts
-        return value * 0.000078125;
-    }
-    
-    // Get the current state of charge measurement of the MAX17048 as a float
-    float soc()
-    {
-        //Read the 16-bit raw SOC value
-        unsigned short value = read(REG_SOC);
- 
-        //Return SOC in percent
-        return value * 0.00390625;
-    }
-    
-    // Get the current state of charge measurement of the MAX17048 as an int
-    int soc_int()
-    {
-        //Read the 16-bit raw SOC value
-        unsigned short value = read(REG_SOC);
- 
-        //Return only the top byte
-        return value >> 8;
-    }
- 
-    // Get the current C rate measurement of the MAX17048
-    float crate()
-    {
-        //Read the 16-bit raw C/Rate value
-        short value = read(REG_CRATE);
- 
-        //Return C/Rate in %/hr
-        return value * 0.208;
-    }
-
-
-    //I2C register addresses
-    enum Register {
-        REG_VCELL       = 0x02,
-        REG_SOC         = 0x04,
-        REG_MODE        = 0x06,
-        REG_VERSION     = 0x08,
-        REG_HIBRT       = 0x0A,
-        REG_CONFIG      = 0x0C,
-        REG_VALRT       = 0x14,
-        REG_CRATE       = 0x16,
-        REG_VRESET_ID   = 0x18,
-        REG_STATUS      = 0x1A,
-        REG_TABLE       = 0x40,
-        REG_CMD         = 0xFE
-    };
- 
-    //Member constants
-    static const int m_ADDR=(0x36 << 1);
- 
-    //Member variables
-    I2C m_I2C;
- 
-    //Internal functions
-    unsigned short read(char reg)
-    {
-        //Create a temporary buffer
-        char buff[2];
- 
-        //Select the register
-        m_I2C.write(m_ADDR, &reg, 1, true);
- 
-        //Read the 16-bit register
-        m_I2C.read(m_ADDR, buff, 2);
- 
-        //Return the combined 16-bit value
-        return (buff[0] << 8) | buff[1];
-    }
- 
-    
-    void write(char reg, unsigned short data)
-    {
-        //Create a temporary buffer
-        char buff[3];
- 
-        //Load the register address and 16-bit data
-        buff[0] = reg;
-        buff[1] = data >> 8;
-        buff[2] = data;
- 
-        //Write the data
-        m_I2C.write(m_ADDR, buff, 3);
-    }
-};
- 
-
- void FUNC_BATTERYGAUGE_MAIN(float[]);
+            
diff -r 1b37d98840d3 -r ef6be8ac6569 beacon.cpp
--- a/beacon.cpp	Wed Dec 17 05:25:04 2014 +0000
+++ b/beacon.cpp	Wed Dec 17 06:06:59 2014 +0000
@@ -19,7 +19,7 @@
 #include "HK.h"
 Serial chavan(USBTX, USBRX);           // tx, rx
 SPI spi(PTD6,PTD7,PTD5);               // mosi, miso, sclk
-DigitalOut cs_bar(D5);                 //slave select or chip select
+DigitalOut cs_bar(PTC11);                 //slave select or chip select
 //InterruptIn button(p9);
 //#define TIMES 16      
 //Timer t;
diff -r 1b37d98840d3 -r ef6be8ac6569 fault.cpp
--- a/fault.cpp	Wed Dec 17 05:25:04 2014 +0000
+++ b/fault.cpp	Wed Dec 17 06:06:59 2014 +0000
@@ -42,7 +42,7 @@
 BusOut clear_ir(FAULT_CLEAR5,FAULT_CLEAR6,FAULT_CLEAR7,FAULT_CLEAR8,FAULT_CLEAR9);
 
 
-extern SensorDataQuantised SensorQuantised;
+extern SensorData Sensor;
 extern int beacon_sc;  //to switch beacon between low and high power mode
 extern int acs_pflag;  //to activate/deactivate control algo  
 char out_poll;
@@ -94,9 +94,9 @@
         
         out_poll = clear_poll;
         out_ir = clear_ir;
-        SensorQuantised.faultpoll = fault_poll ;
-        SensorQuantised.faultir=fault_ir ;
-        printf(" %d , %d \n %d , %d\n",SensorQuantised.faultpoll, SensorQuantised.faultir , out_poll , out_ir) ;
+        Sensor.faultpoll = fault_poll ;
+        Sensor.faultir=fault_ir ;
+        printf(" %d , %d \n %d , %d\n",Sensor.faultpoll, Sensor.faultir , out_poll , out_ir) ;
         
 }
 
diff -r 1b37d98840d3 -r ef6be8ac6569 main.cpp
--- a/main.cpp	Wed Dec 17 05:25:04 2014 +0000
+++ b/main.cpp	Wed Dec 17 06:06:59 2014 +0000
@@ -40,7 +40,7 @@
 
 typedef struct
 {
-    char data[21];          // To avoid dynamic memory allocation
+    char data[18];          // To avoid dynamic memory allocation
     int length;
 }i2c_data;
 
@@ -56,19 +56,19 @@
 //TASK 2 : HK
 //--------------------------------------------------------------------------------------------------------------------------------------------------
 
-char hk_data[21];
-extern SensorDataQuantised SensorQuantised;
+char hk_data[18];
+extern SensorData Sensor;
 void t_hk_acq(void const *args)
 {
     
     while(1)
     {
         Thread::signal_wait(0x2);
-        SensorQuantised.power_mode='0';
+        Sensor.power_mode='0';
         printf("\nTHIS IS HK    %f\n",t1.read());
         t.start();
         FAULTS();
-        POWER(SensorQuantised.power_mode);                                                   //The power mode algorithm is yet to be obtained
+        POWER(Sensor.power_mode);                                                   //The power mode algorithm is yet to be obtained
         FUNC_HK_MAIN();                                                             //Collecting HK data
         //thread_2.signal_set(0x4);
         //FUNC_I2C_SLAVE_MAIN(24);    
@@ -204,7 +204,7 @@
     }
 }*/
 
-extern SensorDataQuantised SensorQuantised;
+extern SensorData Sensor;
 
 
 /*void T_FAULT(void const *args)
@@ -303,7 +303,7 @@
             printf("\ndone\n\r");
 
 }
-char data_send[21],data_receive[21];
+char data_send[18],data_receive[18];
 void T_I2C_BAE()
 {
     //char data_send,data_receive;
@@ -316,10 +316,10 @@
         if(i2c_status == 0 && reset !=1)
         {
             
-            FUNC_I2C_WRITE2CDMS(data_receive,21);
+            FUNC_I2C_WRITE2CDMS(data_receive,18);
             i2c_data * i2c_data_r = i2c_data_receive.alloc();
             strcpy(i2c_data_r->data,data_receive);
-            i2c_data_r->length = 21;
+            i2c_data_r->length = 18;
             i2c_data_receive.put(i2c_data_r);
             printf("\n Data received from CDMS is %s \n\r",data_receive);
             i2c_data_receive.free(i2c_data_r);                              // This has to be done from a differen thread
@@ -332,7 +332,7 @@
             {
                 i2c_data *i2c_data_s = (i2c_data*)evt.value.p;
                 strcpy(data_send,i2c_data_s -> data);
-                FUNC_I2C_WRITE2CDMS(data_send,21);
+                FUNC_I2C_WRITE2CDMS(data_send,18);
                 printf("\nData sent to CDMS is %s\n\r",data_send);
                 i2c_data_send.free(i2c_data_s);
                 i2c_status = 0;
@@ -360,20 +360,21 @@
 
 
 
-char fdata[8] = {SensorQuantised.Vcell_soc,SensorQuantised.alerts,SensorQuantised.crate,SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir, SensorQuantised.power_mode};
 
 void ir2master()
 {
         
-        //char data[21];
+        //char data[18];
         //strcpy(data,"sakthi ");
         //strcat(data,"priya");
-        strcpy(hk_data,SensorQuantised.Voltage);
-        strcat(hk_data,SensorQuantised.Temperature);                                                 //Sending to CDMS via I2C
-        strcat(hk_data,SensorQuantised.Current); 
-        strcat(hk_data,SensorQuantised.PanelTemperature);
-        strcat(hk_data,SensorQuantised.AngularSpeed);
-        strcat(hk_data,SensorQuantised.Bnewvalue);
+        strcpy(hk_data,Sensor.Voltage);
+        strcat(hk_data,Sensor.Temperature);                                                 //Sending to CDMS via I2C
+        strcat(hk_data,Sensor.Current); 
+        //strcat(hk_data,SensorQuantised.PanelTemperature);
+        //strcat(hk_data,SensorQuantised.AngularSpeed);
+        //strcat(hk_data,SensorQuantised.Bnewvalue);
+        char fdata[8] = {Sensor.faultpoll,Sensor.faultir,Sensor.power_mode};
+
         /*strcat(hk_data,sfaultpoll);
         strcat(hk_data,sfaultir);
         strcat(hk_data,spower_mode);*/
@@ -385,7 +386,7 @@
         i2c_status=1;
         i2c_data * i2c_data_s = i2c_data_send.alloc();
         strcpy(i2c_data_s->data,hk_data);
-        i2c_data_s->length = 21;
+        i2c_data_s->length = 18;
         i2c_data_send.put(i2c_data_s); 
         data_ready=1;
         //temp = i2c_status;