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:
- 8:63d28d6b728a
- Parent:
- 7:61d9e4606908
- Child:
- 9:3b666827c58c
--- a/L432KC-log_read.cpp Tue Jan 26 04:43:57 2021 +0000
+++ b/L432KC-log_read.cpp Tue Jan 26 08:35:37 2021 +0000
@@ -35,33 +35,14 @@
FILE *fp;
int open_flg = 0;
int write_flg = 0;
-int close_flg = 0;
+int w = 0;
nRF24L01P my_nrf24l01p(A6, A5, A4, D3, D6, D9); // mosi, miso, sck, csn, ce, irq
-//A6, A5, A4
-
-void timer(){
-
-
- if(rcv_flg == 1) {
-
- printf("%c", rxData2[rxDataIdx]);
- rxDataIdx++;
-
-
- if (rxDataIdx >= TRANSFER_SIZE){
- write_flg = 1;
- rxDataIdx=0;
- rcv_flg = 0;
- i++;
- }
-
-
- }
-
+void timer(){ //1秒ごとにカウントする。
+ i++;
+}
-}
void recieve(){
if(UDGS01.readable()){
@@ -135,7 +116,7 @@
}
}
- interrput.attach(&timer, 0.001);//1 msec 10Khz
+ interrput.attach(&timer, 1);//1 msec 10Khz
UDGS01.attach(recieve,Serial::RxIrq);//牛からのデータ受信したら割り込み発生してrecieveを呼び出す
@@ -149,17 +130,24 @@
if(rcv_flg == 0){
memcpy(rxData2, rxData1, TRANSFER_SIZE);
wait_ms(1);
+ rcv_flg = 1;
}
-
-
+
+ if(rcv_flg == 1){
+ for(; rxDataIdx >= TRANSFER_SIZE; rxDataIdx++)
+ {
+ printf("%c", rxData2[rxDataIdx]);
+ }
+ rcv_flg = 0;
+ write_flg = 1;
+ rxDataIdx=0;
+ }
if(open_flg == 1){
fp = fopen("/sd1/recieve_log.txt", "a");
if (fp == NULL)
{
printf("open error!!\r\n");
-// while(1);
-
}else{
open_flg = 2; //open_flg を1以外の数字にして動かなくしてるだけで、2であることに意味はない
}
@@ -169,18 +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" );
+ i = 0;
+ w = 0;
+ open_flg = 1;
fclose(fp);
wait_ms(1);
+ }
write_flg = 0;
- open_flg = 1;
+
}
- rcv_flg = 1;
-// wait(1);
- }
+
+ }//my_nrf24l01p.readableの{
if (snd_flg==1) {//送信用 送信側もログをSDカードに書き込むようにする。
snd_flg=0;
@@ -199,12 +194,20 @@
if(write_flg == 2){
fwrite(txData2, sizeof(char), TRANSFER_SIZE, fp);
wait_ms(1);
+ w++;
+ if(i >= 60 || w >= 16){
+ printf("------SD writed------\r\n");
+ fprintf(fp, "------writed------\r\n" );
+
+ i = 0;
+ w = 0;
+ open_flg = 1;
fclose(fp);
wait_ms(1);
+ }
write_flg = 0;
- open_flg = 1;
}
my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData2 , TRANSFER_SIZE );