PYLD_CDMS

Dependencies:   mbed

Fork of PLYD_CDMSee by Siva ram

Files at this revision

API Documentation at this revision

Comitter:
Piasiv1206
Date:
Sun Dec 13 12:59:49 2015 +0000
Parent:
4:ec3f71ef8732
Commit message:
PYLD I2C

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
pinconfig.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Nov 07 09:52:57 2015 +0000
+++ b/main.cpp	Sun Dec 13 12:59:49 2015 +0000
@@ -12,20 +12,24 @@
 const int addr1 = (0x20<<1|0);
 const int addr2 = (0x20<<1|1);
 //Timer Siv ;
+int FLAG = 1 ;
 I2C master (D14,D15);
 InterruptIn PYLD_I2C_Int(PTA13);
 //gitalIn test(PTA13);
 SPISlave device(PTD6, PTD7, PTD5,PTD4 ); // mosi, miso, sclk, ssel --> using SPI1
 InterruptIn PYLD_SPI_Interrupt(PTD2);
 DigitalOut flash(LED4);
-int payloadBins = 3096;
+int payloadBins = 1024;
 float Stability_delay = 0.005228 ;// 0.005228
+#define CRC16                   0x8010
+
+uint16_t CRC_16_Calc(const char *data, uint16_t size);
 
 Serial pc(USBTX, USBRX); // tx, rx  --> serial feedback for debug
 
 void payloadProcess() {
   
-   
+   flash = !flash;
     //wait(Stability_delay); // wait after interrupt for stability
     unsigned short scienceRawPacket[payloadBins];
     
@@ -49,6 +53,10 @@
 int dt3,pia = 0;
 bool f = 1;
 char rdata[140],ta2;
+int loop=1;
+char *writedata = new char;
+char data = 1,data1 = 2, data2 = 3,  test[136] ; 
+char pia1[13] , siv[13] ;
 void readds()
 {   
 
@@ -59,7 +67,7 @@
      
              //while(!f)
              //{    
-               f=  master.read(addr1,rdata,135);
+               f=  master.read(addr1,siv,13);
              //}
     // master.start();
         //for(int i = 0;i<26;i++)
@@ -85,9 +93,95 @@
                
 }   
  
-int loop=1;
-char *writedata = new char;
-char data = 1,data1 = 2, data2 = 3,  test[136] ; 
+
+
+void INIT_TC_TEMP (void)
+{
+    
+    uint16_t CRC_VALUE = 0 ;
+    
+    pia1[0]    = 123  ;
+    pia1[1]    = 0x3F ;
+    pia1[2]    = 0x81 ;
+    pia1[3]    = 0xD0 ;
+    pia1[4]    = 0x00 ;
+    pia1[5]    = 0x00 ;
+    pia1[6]    = 0x00 ;
+    pia1[7]    = 0x00 ;
+    pia1[8]    = 0x00 ;
+    CRC_VALUE = CRC_16_Calc(pia1,9) ;
+    pia1[9]    = (char)((CRC_VALUE >> 8) & 0xff);
+    pia1[10]   = (char)((CRC_VALUE >> 0) & 0xff);
+    
+    
+}
+   
+int CHECK_TM (void)
+{
+        uint16_t CRC_Value = 0 , check = 0;
+        CRC_Value = CRC_Value | ((uint16_t) siv[11]) ;
+        CRC_Value = CRC_Value << 8;
+        CRC_Value = CRC_Value | ((uint16_t) siv[12]) ;
+        if (CRC_Value == CRC_16_Calc (siv,11))
+        {
+            check++;
+        }
+        else
+        {
+            return(10);
+        }
+        if ( siv[1] == 123 )
+        {
+            check++;
+        }
+        else
+        {
+            return (9);
+        }
+        if ( siv[3] == 192 )
+        {
+            check ++ ;
+        }
+        else
+        {
+            return (8);
+        }
+        
+        FLAG = 0 ;
+        return (check) ;
+}
+
+uint16_t CRC_16_Calc(const char *data, uint16_t size)
+{
+    uint16_t CRC_OUT = 0;
+    int bits_read = 0, bit_flag;
+
+
+
+    while(size > 0)
+    {
+        bit_flag = CRC_OUT >> 15;
+
+        /* Get next bit: */
+        CRC_OUT <<= 1;
+        CRC_OUT |= (*data >> (7 - bits_read)) & 1;
+
+        /* Increment bit counter: */
+        bits_read++;
+        if(bits_read > 7)
+        {
+            bits_read = 0;
+            data++;
+            size--;
+        }
+
+        /* Cycle check: */
+        if(bit_flag)
+            CRC_OUT ^= CRC16;
+
+    }
+    return CRC_OUT;
+}
 
  
 void FUNC_MASTER_WRITE(void)
@@ -106,7 +200,7 @@
      while(loop)
      {
          
-         bool check = (bool)master.write(addr,test,135);
+         bool check = (bool)master.write(addr,pia1,11);
         // bool check = (bool)master.write(addr,&test[3],1,false);
          // check = (bool)master.write(addr,&test[4],1);
          
@@ -185,6 +279,7 @@
     pc.printf("Example code demonstarting Payload - CDMS SPI & I2C communication!\r\n");
     PYLD_SPI_Interrupt.rise(&payloadProcess);
     PYLD_I2C_Int.rise(&readds);
+    INIT_TC_TEMP();
     
     while(1)
     {
@@ -192,11 +287,54 @@
     wait(1);
     //dt1 = rdata[0] ;
     //dt2 = rdata[1] ;
-    for(P = 0 ; P < 135 ; P++ )
+    for(P = 0 ; P < 13 ; P++ )
     {
-    pc.printf("Temperature %d \n\r",rdata[P]);
-    }
-    pc.printf(" I2C data register %d \n", I2C1 -> S);
+    pc.printf("Temperature %d \n\r",siv[P]);
+   }
+  // while ( FLAG == 1)
+  // {}
+        pc.printf(" Packect Recieved \n \r");
+        
+        if( CHECK_TM() == 3 )
+        {
+            pc.printf(" ACK Recieved \n \r");
+        }
+        else if ( CHECK_TM() == 10 )
+        {
+            pc.printf("Error Code 10 : CRC_FAIL \n \r" );
+        }
+        else if ( CHECK_TM() == 9 )
+        {
+            pc.printf("Error Code 9 : PSC FAIL \n \r" );
+        }
+        else if ( CHECK_TM() == 8 )
+        {
+            pc.printf("Error Code 8 : NACK ACK FAIL \n \r" );
+        }
+ wait (1) ;
+    
+     for(P = 0 ; P < 13 ; P++ )
+   {
+    pc.printf("Temperature %d \n\r",siv[P]);
+   }
+    
+    pc.printf(" Packect Recieved \n \r");
+    uint16_t CRC_Value = 0 ;
+        CRC_Value = CRC_Value | (siv[11]) ;
+        CRC_Value = CRC_Value << 8;
+        CRC_Value = CRC_Value | (siv[12]) ;
+        
+        if (CRC_Value == CRC_16_Calc (siv,11))
+        {
+            pc.printf("CRC_PASS Temperature of PYLD uC is : %d \n \r",siv[3]);
+        }
+        else 
+        {
+            pc.printf("Data CRC_Fail \n \r");
+        }
+    
+   
+    pc.printf(" I2C data register %d \n \r", I2C1 -> S);
    // pc.printf("Temperature %d \n\r",dt1);
    // pc.printf("Temperature2 %d \n\r",dt2);
     //pc.printf("Temperature3 %d \n\r",dt3);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pinconfig.h	Sun Dec 13 12:59:49 2015 +0000
@@ -0,0 +1,101 @@
+// 100 LQFP format pin assignment
+#define PIN1 PTE0
+#define PIN2 PTE1
+#define PIN3 PTE2
+#define PIN4 PTE3
+#define PIN5 PTE4
+#define PIN6 PTE5
+#define PIN7 PTE6
+//#define 8 
+//#define 9 
+//#define 10 
+//#define 11 
+//#define 12 
+//#define 13 
+#define PIN14 PTE16
+#define PIN15 PTE17
+#define PIN16 PTE18
+#define PIN17 PTE19
+#define PIN18 PTE20
+#define PIN19 PTE21
+#define PIN20 PTE22
+#define PIN21 PTE23
+//#define 22 
+//#define 23 
+//#define 24 
+//#define 25 
+#define PIN26 PTE29
+#define PIN27 PTE30
+#define PIN28 PTE31
+//#define 29 
+//#define 30 
+#define PIN31 PTE24
+#define PIN32 PTE25
+#define PIN33 PTE26
+#define PIN34 PTA0
+#define PIN35 PTA1
+#define PIN36 PTA2
+#define PIN37 PTA3
+#define PIN38 PTA4
+#define PIN39 PTA5
+#define PIN40 PTA6
+#define PIN41 PTA7
+#define PIN42 PTA12
+#define PIN43 PTA13
+#define PIN44 PTA14
+#define PIN45 PTA15
+#define PIN46 PTA16
+#define PIN47 PTA17
+//#define 48 
+//#define 49 
+#define PIN50 PTA18
+#define PIN51 PTA19
+#define PIN52 PTA20
+#define PIN53 PTB0
+#define PIN54 PTB1
+#define PIN55 PTB2
+#define PIN56 PTB3
+#define PIN57 PTB7
+#define PIN58 PTB8
+#define PIN59 PTB9
+#define PIN60 PTB10
+#define PIN61 PTB11
+#define PIN62 PTB16
+#define PIN63 PTB17
+#define PIN64 PTB18
+#define PIN65 PTB19
+#define PIN66 PTB20
+#define PIN67 PTB21
+#define PIN68 PTB22
+#define PIN69 PTB23
+#define PIN70 PTC0
+#define PIN71 PTC1
+#define PIN72 PTC2
+#define PIN73 PTC3
+//#define 74 
+//#define 75 
+#define PIN76 PTC20
+#define PIN77 PTC21
+#define PIN78 PTC22
+#define PIN79 PTC23
+#define PIN80 PTC4
+#define PIN81 PTC5
+#define PIN82 PTC6
+#define PIN83 PTC7
+#define PIN84 PTC8
+#define PIN85 PTC9
+#define PIN86 PTC10
+#define PIN87 PTC11
+#define PIN88 PTC12
+#define PIN89 PTC13
+#define PIN90 PTC16
+#define PIN91 PTC17
+#define PIN92 PTC18
+#define PIN93 PTD0
+#define PIN94 PTD1
+#define PIN95 PTD2
+#define PIN96 PTD3
+#define PIN97 PTD4
+#define PIN98 PTD5
+#define PIN99 PTD6
+#define PIN100 PTD7
\ No newline at end of file