I-O DATA DEV2 / Mbed 2 deprecated ud-gs4-R_400G_SD_Log_No2

Dependencies:   mbed SDFileSystem_

Revision:
15:12d0699ad423
Parent:
14:2707af31e02f
Child:
16:1caaa96ae3eb
--- a/main.cpp	Wed Sep 01 11:41:04 2021 +0000
+++ b/main.cpp	Thu Sep 02 09:24:44 2021 +0000
@@ -47,7 +47,7 @@
 
 RawSerial         pc(PA_9, PA_10,115200); //console UART
 //LowPowerTicker    interrupt;
-//Ticker    interrupt;
+Ticker    interrupt;
 SPI               STSPI(PB_15, PB_14, PB_13); //mosi,miso,clk
 DigitalOut        STSPICS(PB_12);
 
@@ -74,8 +74,15 @@
 char filename1[32]= {};
 char filename2[32]= {};
 int ret = 0;
+int timer_flag = 0;
 
 void timer(){
+    timer_flag = 1;
+    timecount++;
+    oldcount++;
+}
+
+void sub(){
     short tx=0,ty=0,tz=0;
     long scr=0;
     //static long ax,ay,az,as;
@@ -173,6 +180,8 @@
                 NVIC_SystemReset();
             }
         }
+        
+        timer_flag = 0;
 }
 
 int main()
@@ -195,20 +204,21 @@
         //NVIC_SystemReset();
     }
 
-    //interrupt.attach_us(&timer,200000);//200ms
-
     while(ret) {
       ret = initLIS3DH();
       ret = initLIS331();
       pc.printf(" init acc sensor %d\r\n",ret);
       wait_ms(100);
     }
+    interrupt.attach_us(&timer,20000);//20ms
     while(1)
     {
-        timer();
-        timecount++;
-        oldcount++;
-        wait_ms(20);
+        if(timer_flag){
+            sub();
+            //timecount++;
+            //oldcount++;
+        }
+        //wait_ms(20);
     }
     
 }