FINAL ACS TO BE USED FOR TESTING. COMMISSIONING, ACS MAIN, DATA ACQ ALL DONE.

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of ACS_FULL_Flowchart_BAE by Team Fox

Revision:
2:c823d84b4cb0
Parent:
1:446a959e36ce
Child:
3:07e15677a75c
--- a/EPS.cpp	Thu Dec 24 20:01:31 2015 +0000
+++ b/EPS.cpp	Fri Dec 25 15:25:44 2015 +0000
@@ -21,6 +21,12 @@
 DigitalOut EN_BTRY_HT(BATT_HEAT);
 //DigitalIn BTRY_HT_OUTPUT(BATT_HEAT_OUTPUT);
 AnalogIn Vbatt_ang(VBATT);
+SPI spi_bt(PIN99,PIN100,PIN98); //MOSI,MISO,SLK
+DigitalOut ssn1(PIN19); //Slave select1
+DigitalOut ssn2(PIN21);//Slave select2
+//DigitalOut PS(PTB0);
+//DigitalOut HS(PTB1);
+
 
 //*********************************************************flags********************************************************//
 extern char EPS_INIT_STATUS ;
@@ -39,7 +45,7 @@
     EPS_INIT_STATUS = 's' ;             //set EPS_INIT_STATUS flag
    // FLAG();
     FCTN_BATTERYGAUGE_INIT();
-    //FCTN_EPS_BTEMP_INIT();
+    //FCTN_BATTTEMP_INIT();
     EN3V3A = 1;                             //enable dc dc converter A  
     char value=alertFlags();
     unsigned short value_u= (short int )value;
@@ -87,6 +93,7 @@
 void HK_main()
 {
     
+    
 }
 
 //............................................BATTERY GAUGE......................................//
@@ -377,10 +384,10 @@
         unsigned short value = read_soc(REG_SOC, ack);
  
         //Return SOC in percent
-       // if(ack == 0)
+        if(ack == 0)
         return value * 0.00390625;
-        //else 
-        //return 200;
+        else 
+        return 200;
     }
     
    
@@ -406,4 +413,46 @@
             return true;
         else
             return false;
-    }
\ No newline at end of file
+    }
+    
+//.............................Battery board Temp sensor........................//
+void FCTN_BATTTEMP_INIT()
+{
+    ssn1=1;ssn2=1;
+    //PS=0;
+    //HS=0;
+    spi_bt.format(8,3);
+    spi_bt.frequency(1000000);
+} 
+
+void FCTN_BATT_TEMP_SENSOR_MAIN(float temp[2])
+{
+    uint8_t MSB, LSB;
+    int16_t bit_data;
+    float sensitivity=0.0078125;   //1 LSB = sensitivity degree celcius
+    wait_ms(320);
+    ssn1=0;
+
+    spi_bt.write(0x80);//Reading digital data from Sensor 1
+    LSB = spi_bt.write(0x00);//LSB first
+    wait_ms(0);
+    MSB = spi_bt.write(0x00);
+    wait_ms(10);
+    pc_eps.printf("%d %d\n",MSB,LSB);
+    bit_data= ((uint16_t)MSB<<8)|LSB;
+    wait_ms(10);
+    temp[0]=(float)bit_data*sensitivity;//Converting into decimal value 
+    ssn1=1;
+    wait_ms(10);
+    ssn2=0;//Reading data from sensor 2
+    spi_bt.write(0x80);
+    LSB = spi_bt.write(0x00);
+    wait_ms(10);
+    MSB = spi_bt.write(0x00);
+    wait_ms(10);
+    bit_data= ((int16_t)MSB<<8)|LSB;
+    wait_ms(10);
+    temp[1]=(float)bit_data*sensitivity;
+    ssn2=1;
+    
+}
\ No newline at end of file