lkdsnf;

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_PL_Working by Siva ram

Files at this revision

API Documentation at this revision

Comitter:
Piasiv1206
Date:
Wed Mar 30 13:03:24 2016 +0000
Parent:
137:6fcbbaf19284
Commit message:
jkhdsoi

Changed in this revision

crc.h Show annotated file Show diff for this revision Revisions of this file
i2c.h 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 6fcbbaf19284 -r 71ed56f2ec50 crc.h
--- a/crc.h	Sat Mar 12 10:42:22 2016 +0000
+++ b/crc.h	Wed Mar 30 13:03:24 2016 +0000
@@ -74,4 +74,39 @@
     }
     
     return remainder;
-}
\ No newline at end of file
+}
+
+uint16_t crc16_gen1( char message[], unsigned int nBytes){
+    crctype16 remainder = 0xffff;
+    int byte;
+    char bit;
+    
+    for( byte = 0 ; byte < nBytes ; byte++ ){
+        /*
+        Bring the data byte by byte
+        each time only one byte is brought
+        0 xor x = x
+        */
+        remainder = remainder ^ ( message[byte] << 8 );
+        
+        for( bit = 8 ; bit > 0 ; bit--){
+            /*
+            for each bit, xor the remainder with polynomial
+            if the MSB is 1
+            */
+            if(remainder & TOPBIT16){
+                remainder = (remainder << 1) ^ POLYNOMIAL16;
+                /*
+                each time the remainder is xor-ed with polynomial, the MSB is made zero
+                hence the first digit of the remainder is ignored in the loop
+                */
+            }
+            else{
+                remainder = (remainder << 1);
+            }
+        }
+    }
+    
+    return remainder;
+}
+
diff -r 6fcbbaf19284 -r 71ed56f2ec50 i2c.h
--- a/i2c.h	Sat Mar 12 10:42:22 2016 +0000
+++ b/i2c.h	Wed Mar 30 13:03:24 2016 +0000
@@ -12,7 +12,7 @@
 bool read_ack = true;
 
 
-char PL_I2C_DATA[134];//Payload i2c array
+
 uint8_t PL_TM_SIZE;//size of data to bev read from i2c
 
 void FCTN_I2C_WRITE_PL(char *data2,uint8_t tc_len2)
@@ -93,6 +93,8 @@
 }
 
 
+const int addr1 = (0x20<<1|0);
+const int addr2 = (0x20<<1|1);
 
 
 
@@ -103,9 +105,7 @@
 
 void isr_pyldtm()
 {
-    
-    master.read(addr_pl|1,PL_I2C_DATA,13);
     gLEDR=!gLEDR;
-    
+    master.read(addr1,PL_I2C_DATA,134);
     rcv_isr = 1;
 }
\ No newline at end of file
diff -r 6fcbbaf19284 -r 71ed56f2ec50 main.cpp
--- a/main.cpp	Sat Mar 12 10:42:22 2016 +0000
+++ b/main.cpp	Wed Mar 30 13:03:24 2016 +0000
@@ -2,6 +2,7 @@
 
 #include "mbed.h"
 
+char PL_I2C_DATA[150];//Payload i2c array
 uint8_t rcv_isr = 0; // flag for interrupt
 
 #define DEBUG 1
@@ -42,7 +43,7 @@
     uint16_t CRC_VALUE = 0 ;
     
     pia1[0]    = 123  ;
-    pia1[1]    = 0xff ;
+    pia1[1]    = 0x00 ;
     pia1[2]    = 0x81 ;
     pia1[3]    = 0xD0 ;
     pia1[4]    = 0x00 ;
@@ -50,7 +51,7 @@
     pia1[6]    = 0x00 ;
     pia1[7]    = 0x00 ;
     pia1[8]    = 0x00 ;
-    CRC_VALUE  = 0 ;
+    CRC_VALUE  = crc16_gen1(pia1,9); 
     pia1[9]    = (char)((CRC_VALUE >> 8) & 0xff);
     pia1[10]   = (char)((CRC_VALUE >> 0) & 0xff);
     
@@ -139,21 +140,25 @@
     break;}
     }*/
     INIT_TC_TEMP();
+    master.frequency(400000);
     int i =0 ;
     char test[1] ;
     test[0] = 7;
     while(1)
     {
+        wait(5);
         //test[0] = gPC.getc();
         gPC.printf("Wriring to I2C\n\r");
         
-        wait(10);
+        
         
         master.write(addr_pl|0x00,pia1,11);
         
+        wait (2);
+        
         if(rcv_isr == 1)
         {
-            for(i = 0; i < 13 ; i++)
+            for(i = 0; i < 134 ; i++)
             {
                 gPC.printf("%d\r\n",PL_I2C_DATA[i]);
                 PL_I2C_DATA[i] = 0 ;