I2C working only once, sensor working well, commissioning updated to be tested, Wohoooo!!! :-D

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of Japan_BAE1 by Team Fox

Revision:
13:fb7facaf308b
Parent:
12:af1d7e18b868
--- a/main.cpp	Wed Apr 13 18:34:28 2016 +0000
+++ b/main.cpp	Wed Apr 13 21:48:21 2016 +0000
@@ -6,8 +6,8 @@
 #include "BCN.h"
 #include "TCTM.h"
 
-#define tm_len 134
-#define tc_len 135
+#define tm_len 135
+#define tc_len 11
 #define batt_heat_low 20
 
 //***************************************************** flags *************************************************************//
@@ -85,7 +85,7 @@
 int write_ack = 1;
 int read_ack = 1;
 char telecommand[tc_len];
-char* telemetry;
+extern uint8_t telemetry[135];
 
 bool pf1check = 0;
 bool pf2check = 0;
@@ -120,15 +120,20 @@
 InterruptIn  ir6(PIN80);//Beacon- Switch OC bar
 InterruptIn  ir7(PIN42);//Charger IC - Fault Bar
 
-DigitalOut TRXY_SW_EN(PIN71);  //TR XY Switch
-DigitalOut DRV_Z_SLP(PIN88);    //Sleep pin of driver z
+//DigitalOut TRXY_SW_EN(PIN71);  //TR XY Switch
+//DigitalOut DRV_Z_SLP(PIN88);    //Sleep pin of driver z
+//DigitalOut TRZ_SW(PIN40);  //TR Z Switch
+//DigitalOut CDMS_RESET(PIN7); // CDMS RESET
+//DigitalOut BCN_SW(PIN14);      //Beacon switch
+//DigitalOut DRV_XY_SLP(PIN82);
+
+
+DigitalOut TRXY_SW(PIN71);  //TR XY Switch
+DigitalOut DRV_Z_EN(PIN88);    //Sleep pin of driver z
 DigitalOut TRZ_SW(PIN40);  //TR Z Switch
 DigitalOut CDMS_RESET(PIN7); // CDMS RESET
 DigitalOut BCN_SW(PIN14);      //Beacon switch
-DigitalOut DRV_XY_SLP(PIN82);
-
-
-
+DigitalOut DRV_XY_EN(PIN82);
 
 /*****************************************************************Threads USed***********************************************************************************/
 
@@ -174,8 +179,8 @@
         if(iterP1 >= 3)
         {
             ATS2_SW_ENABLE = 1;  // turn off ats2 permanently
-            ACS_DATA_ACQ_ENABLE == 0;
-            ACS_STATE == 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY    
+            ACS_DATA_ACQ_ENABLE = 0;
+            ACS_STATE = 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY    
         }
         else    
         {
@@ -188,11 +193,11 @@
     {
         if(iterI1 >= 3)
         {
-            TRXY_SW_EN = 0;  // turn off TRXY permanently
+            TRXY_SW = 0;  // turn off TRXY permanently
         }
         else    
         {
-         TRXY_SW_EN = 1;   //switch on TRXY
+         TRXY_SW = 1;   //switch on TRXY
          iterI1++;
         }
     }    
@@ -201,7 +206,7 @@
         if(iterI2 >= 3)
         {
             TRZ_SW = 0;  // turn off TRZ permanently
-            ACS_STATE == 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY  
+            ACS_STATE = 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY  
         }
         else    
         {
@@ -227,7 +232,7 @@
     
     if(ACS_DATA_ACQ_ENABLE == 1)// check if ACS_DATA_ACQ_ENABLE = 1?
     {
-    FLAG();
+    //FLAG();
     FCTN_ATS_DATA_ACQ(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3
     pc.printf("gyro values\n\r"); //printing the angular velocity and magnetic field values
     for(int i=0; i<3; i++) 
@@ -433,12 +438,15 @@
                 //FCTN_APPEND_HKDATA();
                 // pc.printf("\n\r here");
                 write_ack=slave.write(BAE_chardata,74); 
+                if(write_ack==0)                
+                    irpt_2_mstr = 0;
             }
             else if(data_send_flag == 't')
             {
-                write_ack=slave.write(telemetry,tm_len);
+                write_ack=slave.write((char*)telemetry,tm_len);
                 data_send_flag = 'h';
-                irpt_2_mstr = 0;
+                if(write_ack==0)                
+                    irpt_2_mstr = 0;
             }       
         }
         else if( slave.receive()==3 ||  slave.receive()==2)             // slave read 
@@ -449,8 +457,8 @@
            pc.printf("\n\r Executing Telecommand \n"); 
            // FCTN_TC_DECODE((uint8_t*) telecommand);
            
-           uint8_t* temp = FCTN_BAE_TM_TC((uint8_t*) telecommand);
-           telemetry = (char*)temp;
+           FCTN_BAE_TM_TC((uint8_t*) telecommand);
+           //telemetry = (char*)temp;
           
            FCTN_TM();
             t_tc.stop();
@@ -493,16 +501,16 @@
 void ir2clear()
 {
     actual_data.faultIr_status |= 0x02;
-    TRXY_SW_EN = 0;   // Switch off TR XY
+    TRXY_SW = 0;   // Switch off TR XY
     if1check = 1;
 }
  
 void ir3clear()
 {
     actual_data.faultIr_status |= 0x04;
-    DRV_Z_SLP = 0;
+    DRV_Z_EN = 0;
     wait_us(1);
-    DRV_Z_SLP = 1;
+    DRV_Z_EN = 1;
  
 }
  
@@ -560,9 +568,9 @@
  
     if (pf3==0)
     {   actual_data.faultPoll_status |=0x04 ;
-        DRV_XY_SLP = 0;
+        DRV_XY_EN = 0;
         wait_us(1);
-        DRV_XY_SLP = 1;
+        DRV_XY_EN = 1;
     }
     else actual_data.faultPoll_status &= 0xFB;
  
@@ -614,12 +622,12 @@
     }
     if(schedcount%1==0)
     {
-       F_ACS();
+       //F_ACS();
     }
     
     if(schedcount%2==0)
     {
-        F_EPS();
+    //    F_EPS();
     }
     if(schedcount%3==0)
     { 
@@ -741,17 +749,23 @@
 {
     printf("\n\r Initialising BAE ");
     //..........intial status....//
-    ACS_STATE = '4';
+    ACS_STATE = 4;
     ACS_ATS_ENABLE = 1;
     ACS_DATA_ACQ_ENABLE = 1;
     EPS_BATTERY_HEAT_ENABLE = 1;
+    actual_data.power_mode=3;
     //............intializing pins................//
     ATS1_SW_ENABLE = 0;
     ATS2_SW_ENABLE = 1;
+
+    DRV_XY_EN = 1;
+    DRV_Z_EN = 1;
+    TRZ_SW = 1;
+    TRXY_SW = 1;
     
     //............................//
     FCTN_ACS_INIT();
-    FCTN_EPS_INIT();
+   // FCTN_EPS_INIT();
     FCTN_BCN_INIT();
 
     
@@ -761,7 +775,7 @@
 int main()
 {
     pc.printf("\n\r BAE Activated. Testing Version 1.1 \n");
-    
+    CDMS_RESET = 1;  
    /* if (BCN_FEN == 0)                       //dummy implementation
     {
         pc.printf("\n\r RF silence ");
@@ -773,8 +787,10 @@
     
     //ACS_INIT_STATUS = 0;
     //ACS_DATA_ACQ_STATUS = 0;
+        
+
     
-    FLAG();
+    //FLAG();
     FCTN_BAE_INIT();
     
     
@@ -789,18 +805,18 @@
     irpt_4m_mstr.enable_irq();
     irpt_4m_mstr.rise(&FCTN_I2C_ISR);
    // ir1.fall(&ir1clear);   //Battery Gauge - Alert Bar Signal
-    ir2.fall(&ir2clear);   //TRXY Driver TR switch Fault
-    ir3.fall(&ir3clear);   //TRZ Driver Fault Bar
-    ir4.fall(&ir4clear);   //TRZ Driver TR switch Fault
-    ir5.fall(&ir5clear);   //CDMS - Switch Fault
-    ir6.fall(&ir6clear);   //Beacon- Switch OC bar
-    ir7.fall(&ir7clear);   //Charger IC - Fault Bar
+    //ir2.fall(&ir2clear);   //TRXY Driver TR switch Fault
+    //ir3.fall(&ir3clear);   //TRZ Driver Fault Bar
+    //ir4.fall(&ir4clear);   //TRZ Driver TR switch Fault
+    //ir5.fall(&ir5clear);   //CDMS - Switch Fault
+    //ir6.fall(&ir6clear);   //Beacon- Switch OC bar
+    //ir7.fall(&ir7clear);   //Charger IC - Fault Bar
     RtosTimer t_sc_timer(T_SC,osTimerPeriodic);               // Initiating the scheduler thread
     t_sc_timer.start(10000);
     t_start.start();
     pc.printf("\n\rStarted scheduler %f\n\r",t_start.read()); 
     
-    ATS1_SW_ENABLE = 0;  // att sens2 switch is enabled
+
     //FCTN_BAE_INIT();
     while(1);                                                   //required to prevent main from terminating
 }