with i2c

Dependencies:   mbed-rtos mbed

Fork of BAE_b4hw_test by sakthi priya amirtharaj

Revision:
2:edd107ea4740
Parent:
0:ebdf4f859dca
Child:
3:20647ff68b3c
diff -r deb3c0fafa3a -r edd107ea4740 ACS.cpp
--- a/ACS.cpp	Sat Dec 20 05:56:04 2014 +0000
+++ b/ACS.cpp	Fri Dec 26 06:12:09 2014 +0000
@@ -6,13 +6,13 @@
                         //PWM output comes from pins p6
 Serial pc1(USBTX, USBRX);
 SPI spi_acs (PIN16, PIN17, PIN15); // mosi, miso, sclk  PTE18,19,17
-DigitalOut SSN_MAG (PIN61); // ssn for magnetometer PTB11
-DigitalIn DRDY (PIN47); // drdy for magnetometer PTA17
-DigitalOut ssn_gyr (PIN62);         //Slave Select pin of gyroscope  PTB16
-InterruptIn dr(PIN81);       //Interrupt pin for gyro PTC5
-PwmOut PWM1(A3);        //Functions used to generate PWM signal 
-PwmOut PWM2(A4); 
-PwmOut PWM3(A5);                   //PWM output comes from pins p6
+DigitalOut SSN_MAG (PTC16); // ssn for magnetometer PTB11
+DigitalInOut DRDY (PTE3); // drdy for magnetometer PTA17
+DigitalOut ssn_gyr (PTE2);         //Slave Select pin of gyroscope  PTB16
+InterruptIn dr(PTC6);       //Interrupt pin for gyro PTC5
+PwmOut PWM1(D2);        //Functions used to generate PWM signal 
+PwmOut PWM2(D3); 
+PwmOut PWM3(D4);                   //PWM output comes from pins p6
 Ticker tr;              //Ticker function to give values for limited amount of time for gyro
 Timeout tr_mag;
 uint8_t trflag_mag;
@@ -31,6 +31,7 @@
      float timep = 0.02 ;  
      float Mx=M[0];            //Time period is set to 0.02s  
                              //Moment in x, y, z directions
+     
       
      
         ix = Mx * 0.3 ;      //Moment and Current always have the linear relationship
@@ -63,7 +64,7 @@
          }
          else if(ix==0)
          {
-             DCx = 0;
+             DCx = 50;
             PWM1.period(timep);
             PWM1 = DCx/100 ;            
          }
@@ -71,6 +72,8 @@
          {
             // printf("!!!!!!!!!!Error!!!!!!!!!");
          } 
+         
+    printf("\n moment :%f\n",DCx);
     float DCy = 0;         //Duty cycle of Moment in x, y, z directions
      float iy = 0;          //Current sent in x, y, z TR's
        
@@ -174,7 +177,11 @@
 
 void FUNC_ACS_MAG_INIT()
  {
-   
+  //DRDY.output();
+  DRDY = 0;
+  int a ;
+  a=DRDY;
+  printf("\n DRDY is %d\n",a);
   SSN_MAG=1;                                    //pin is disabled
   spi_acs.format(8,0);                         //   8bits,Mode 0
   spi_acs.frequency(100000);                   //clock frequency
@@ -198,7 +205,12 @@
 
 float* FUNC_ACS_MAG_EXEC()
 {
-   printf("\nEntered magnetometer function\n");
+   //printf("\nEntered magnetometer function\n");
+   //DRDY.output();
+   DRDY.write(0);
+   int a;
+   a = DRDY;
+   printf("\n DRDY is %d\n",a);
    SSN_MAG=0;                                //enabling slave to measure the values
    wait_ms(10);
    spi_acs.write(0x82);                     //initiates measurement
@@ -209,7 +221,7 @@
 
    trflag_mag=1;        
    tr_mag.attach(&trsub_mag,1);   //runs in background,makes trflag_mag=0 after 1s
- 
+   DRDY.input();
    while(trflag_mag)              /*initially flag is 1,so loop is executed,if DRDY is high,then data is retrieved and programme ends,else 
                                  loop runs for at the max 1s and if still DRDY is zero,the flag becomes 0 and loop is not executed and 
                                programme is terminated*/
@@ -217,6 +229,7 @@
     wait_ms(5);
     if(DRDY==1)
     {
+        printf("\nwth\n");
         SSN_MAG=0;
         spi_acs.write(0xc9);                  //command  byte for retrieving data
  
@@ -247,7 +260,8 @@
 
         }
         SSN_MAG=1;
-        
+        /* for test only to removed */
+        Bnewvalue[0]=Bnewvalue[1]=Bnewvalue[2]=100;
         return Bnewvalue;          //return here? doubt..
         break;
     }
@@ -431,7 +445,7 @@
 {
     uint8_t response;               
     ssn_gyr=1;                  //Deselecting the chip 
-    spi_acs.format(8,3);                // Spi format is 8 bits, and clock mode 3 
+    spi_acs.format(8,0);                // Spi format is 8 bits, and clock mode 3 
     spi_acs.frequency(1000000);     //frequency to be set as 1MHz
     drFlag=0;                   //Intially defining data-ready flag to be 0 
     dr.mode(PullDown);