Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed nRF24L01P SDFileSystem
Diff: L432KC-log_read.cpp
- Revision:
- 9:3b666827c58c
- Parent:
- 8:63d28d6b728a
--- a/L432KC-log_read.cpp Tue Jan 26 08:35:37 2021 +0000
+++ b/L432KC-log_read.cpp Tue Mar 30 07:42:31 2021 +0000
@@ -10,7 +10,7 @@
//DigitalIn IRQ(D9);
//SPI nRF_spi(A6, A5, A1);// mosi, miso, sck
RawSerial pc(PA_2, PA_15); //432KCはpcとつながってるのはUART2らしい。UART使いたいならUART1。
-RawSerial UDGS01(D1, D0); // UD-GS01とのシリアル通信用にUARTピンを新たに定義。
+RawSerial UDGS01(D1, D0); // ログ読み取り対象とのシリアル通信用にUARTピンを新たに定義。
Ticker interrput;
SDFileSystem sd1(PB_5_ALT0, PB_4_ALT0, PB_3_ALT0, A0, "sd1"); // mosi, miso, sclk, cs__このコードの場所はメインの上にしよう_SDFileSystemを新しくしたら、ヘッダ側(SDFileSystem.cppの122行辺り)で周波数を定義してたので,(10MHzぐらいに設定)周波数は削除した書き方に
@@ -43,7 +43,6 @@
i++;
}
-
void recieve(){
if(UDGS01.readable()){
@@ -103,7 +102,7 @@
if (fp == NULL)
{
printf("open error!!\r\n");
-// while(1);
+
}
else{
@@ -117,7 +116,7 @@
}
interrput.attach(&timer, 1);//1 msec 10Khz
- UDGS01.attach(recieve,Serial::RxIrq);//牛からのデータ受信したら割り込み発生してrecieveを呼び出す
+ UDGS01.attach(recieve,Serial::RxIrq);//ログ読み取り対象からのデータ受信したら割り込み発生してrecieveを呼び出す
@@ -131,7 +130,7 @@
memcpy(rxData2, rxData1, TRANSFER_SIZE);
wait_ms(1);
rcv_flg = 1;
- }
+ }
if(rcv_flg == 1){
for(; rxDataIdx >= TRANSFER_SIZE; rxDataIdx++)
@@ -158,23 +157,25 @@
fwrite(rxData2, sizeof(char), TRANSFER_SIZE, fp);
wait_ms(1);
w++;
-
- if(i >= 60 || w >= 16){ //60秒経過するか、512バイト書き込むとSDカードを閉じるようにする
- printf("------SD writed------\r\n");
- fprintf(fp, "------writed------\r\n" );
+
+ if(w >= 16){ //512バイト書き込むとSDカードを閉じるようにする
+ if(i >= 60)i = 0; //wが増える限りはiが300以上行く前にここで0になる
+ w = 0;
+ open_flg = 1;
+ fclose(fp);
+ wait_ms(1);
- i = 0;
- w = 0;
- open_flg = 1;
- fclose(fp);
- wait_ms(1);
+ }
+ write_flg = 0;
}
-
- write_flg = 0;
-
+
+ if(i >= 300){ //ログが出ないことでwが止まってiがリセットされず、300秒経過したらファイル閉じる
+ i = 0;
+ w = 0;
+ open_flg = 1;
+ fclose(fp);
}
-
}//my_nrf24l01p.readableの{
if (snd_flg==1) {//送信用 送信側もログをSDカードに書き込むようにする。
@@ -196,20 +197,24 @@
wait_ms(1);
w++;
- if(i >= 60 || w >= 16){
- printf("------SD writed------\r\n");
- fprintf(fp, "------writed------\r\n" );
-
- i = 0;
+ if(w >= 16){
+ if(i >= 60)i = 0;
+ w = 0;
+ open_flg = 1;
+ fclose(fp);
+ wait_ms(1);
+ }
+
+ write_flg = 0;
+ }
+
+ if(i >= 300){
w = 0;
open_flg = 1;
fclose(fp);
wait_ms(1);
}
- write_flg = 0;
- }
-
my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData2 , TRANSFER_SIZE );
printf("1\r\n");
wait_ms(1);