UD-GS01治具の試作プログラムです

Dependencies:   mbed nRF24L01P SDFileSystem

Revision:
13:8357704ad091
Parent:
12:d935d1243611
Child:
14:894a7ca12e70
--- a/Goto_UD-GS01.cpp	Fri Dec 11 09:14:15 2020 +0000
+++ b/Goto_UD-GS01.cpp	Mon Dec 14 05:10:55 2020 +0000
@@ -28,9 +28,10 @@
 int      bufferidx=0;
 FILE     *fp;
 int      open_flg = 0;
+int      write_flg = 0;
 
 
-nRF24L01P my_nrf24l01p(PC_3, PC_2, PB_10, PC_4, D9,D8);    // mosi, miso, sck, csn, ce, irq
+nRF24L01P my_nrf24l01p(D11, D12, D13, D10, D9,D8);    // mosi, miso, sck, csn, ce, irq
 //nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10);    // mosi, miso, sck, csn, ce, irq
 
 void timer(){
@@ -41,14 +42,21 @@
         
         pc.printf("%s", &rxData2[rxDataIdx]);
         rxDataIdx++;
-        i++;
+        
         
-        if (rxDataIdx >= TRANSFER_SIZE) 
+        if (rxDataIdx >= TRANSFER_SIZE){ 
         rxDataIdx=0;
         rcv_flg = 0;
+        i++;
+       
+         }
         
                
       }
+      if(i>10){
+          i = 0;
+          write_flg = 1;
+          }
 
    //ここらへんにSDカードの書き込みを入れようかと!
 }
@@ -72,7 +80,6 @@
     }
     
 }
-
       
 int main() {
   
@@ -96,13 +103,31 @@
     my_nrf24l01p.enable();
     
     
-    SDFileSystem *sd = new SDFileSystem(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, cs, card detect, sw type, freq
+    SDFileSystem *sd = new SDFileSystem(PB_15, PB_14, PB_13, PC_4, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, cs, card detect, sw type, freq
     wait_ms(100);
    // my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*)rxData,1);//dummy
+   
+   if(open_flg == 0){
+        fp = fopen("/sd/testlog.txt", "a");             
+         
+         if (fp == NULL)
+        {
+            printf("open error!!\r\n");
+//            while(1);
+        }     
+         else{
+//            fwrite(rxData3, sizeof(char), TRANSFER_SIZE, fp);
+         fprintf(fp, "opened!!\r\n");
+         fclose(fp);
+         open_flg = 1;
+            wait(0.5);
+         }
+   }
 
     interrput.attach(&timer, 1);//100 usec 10Khz
     UDGS01.attach(recieve,Serial::RxIrq);//牛からのデータ受信したら割り込み発生してrecieveを呼び出す
 
+
  //   my_nrf24l01p.flush_rx_fifo();
  while(1){
        
@@ -112,35 +137,26 @@
             
              memcpy(rxData2, rxData1, TRANSFER_SIZE);
              wait(0.5);
-             memcpy(rxData3, rxData1, TRANSFER_SIZE);
-         phoenix :    
-         if(open_flg == 0){
-             fp = fopen("/sd/testlog", "a");
+
+//             memcpy(rxData3, rxData1, TRANSFER_SIZE);
              
-             if (fp == NULL)
-                {
-                printf("open error!!\r\n");
-                goto phoenix;
-                
-             }
-             open_flg = 1;
+         if(open_flg == 1){
+             fp = fopen("/sd/testlog.txt", "a");
+             open_flg = 2;
          }
          
-         if(open_flg == 1){
-            fwrite(rxData3, sizeof(char), TRANSFER_SIZE, fp);
-            wait(0.5);
+         if(write_flg == 1){
+          fwrite(rxData2, sizeof(char), TRANSFER_SIZE, fp);
+          wait(0.5);       
+          fclose(fp);
+          open_flg = 1;
          }
-         
-             rcv_flg = 1;
-             
-         if(i>100){
-             fclose(fp);
-             i = 0;
-             open_flg = 0;
-             wait(1);
-         }
-       wait(1);
-       }
+                       
+//             wait(1);
+
+       rcv_flg = 1;
+//       wait(1);
+      }
 
        if (snd_flg==1) {//最初のバッファ
                snd_flg=0;