Ma Xiaobing / Mbed 2 deprecated nRF24L01Preceive

Dependencies:   BufferedSerial mbed nRF24L01P

Fork of nRF24L01P_Hello_World by YX ZHANG

Files at this revision

API Documentation at this revision

Comitter:
aurorapso2
Date:
Fri Oct 13 12:12:58 2017 +0000
Parent:
4:3bbadb5f1a00
Commit message:
nnn

Changed in this revision

BufferedSerial.lib 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
nRF24L01P.lib Show diff for this revision Revisions of this file
nRF24L01Psend.lib Show annotated file Show diff for this revision Revisions of this file
--- a/BufferedSerial.lib	Wed Oct 11 12:49:30 2017 +0000
+++ b/BufferedSerial.lib	Fri Oct 13 12:12:58 2017 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/sam_grove/code/BufferedSerial/#fac59792042d
+https://os.mbed.com/users/aurorapso2/code/BufferedSerial/#ea2d400f9308
--- a/main.cpp	Wed Oct 11 12:49:30 2017 +0000
+++ b/main.cpp	Fri Oct 13 12:12:58 2017 +0000
@@ -3,8 +3,8 @@
 #include"nRF24L01P.h"
 
 Serial pc(PA_9, PA_10, 9600);//PA_9 PA_10 作为串口1连接串口转usb模块连接电脑
+Serial JY901(PB_10,PB_11,9600);
 //BufferedSerial mod(PB_10, PB_11, 32);//PB_10, PB_11作为第二个串口与jy-901的串口端连接,进行通信
-Serial JY901(PB_10, PB_11, 9600);
 //                 mosi, miso, sck, csn, ce, irq
 nRF24L01P my_nrf24l01p(PA_7, PA_6, PA_5, PA_3, PA_4, PA_2);
 //DigitalOut myled1(PC_13);
@@ -34,54 +34,38 @@
     pc.printf( "Type keys to test transfers:\r\n  (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
 
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
-    my_nrf24l01p.setReceiveMode();//!!!!change this to change mode
+    my_nrf24l01p.setReceiveMode();//!!!!change this to change mode //setReceiveMode
     my_nrf24l01p.enable();
 
-    while (1) {
-        if(JY901.readable()){
-            char charbuffer[256];
-            int uu = 0;
-            while(JY901.readable()){
-                charbuffer[uu++] = JY901.getc();}
-            pc.printf(charbuffer);
-            //txData[txDataCnt++] = mod.getc();
-
-            /*if ( txDataCnt >= sizeof( txData ) ) {
-                //my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
-                pc.printf(txData);
-                txDataCnt = 0;
-            }*/
-        }
-        // If we've received anything over the host serial link...
-        /*if ( pc.readable() ) {
-
-            // ...add it to the transmit buffer
-            txData[txDataCnt++] = pc.getc();
-
-            // If the transmit buffer is full
-            if ( txDataCnt >= sizeof( txData ) ) {
-
-                // Send the transmitbuffer via the nRF24L01+
-                my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
-
-                txDataCnt = 0;
-            }
-
-            // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
-           // myled1 = !myled1;
-        }*/
-
-        // If we've received anything in the nRF24L01+...
+    while (1) {      
         if ( my_nrf24l01p.readable() ) {
-            // ...read the data into the receive buffer
             rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
-            // Display the receive buffer contents via the host serial link
             for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
-
                 pc.putc( rxData[i] );
             }
-            //myled2 = !myled2;
+        }
+        while(pc.readable()){
+            txData[txDataCnt++] = pc.getc();
+            if(txDataCnt>=sizeof(txData)){
+                my_nrf24l01p.write(NRF24L01P_PIPE_P1,txData,txDataCnt);
+                my_nrf24l01p.setReceiveMode();
+                txDataCnt = 0;
+            }       
         }
-        
+       
     }
+     /*while(1){
+            txData[txDataCnt++] = JY901.getc();
+            if(txDataCnt>=sizeof(txData)){
+                my_nrf24l01p.write(NRF24L01P_PIPE_P0,txData,txDataCnt);
+                my_nrf24l01p.setReceiveMode();
+                txDataCnt = 0;
+            }       
+           if ( my_nrf24l01p.readable() ) {
+                rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P1, rxData, sizeof( rxData ) );
+                for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
+                    pc.putc( rxData[i] );
+                }
+            }
+    }*/
 }
--- a/nRF24L01P.lib	Wed Oct 11 12:49:30 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Owen/code/nRF24L01P/#8ae48233b4e4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24L01Psend.lib	Fri Oct 13 12:12:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Owen/code/nRF24L01P/#8ae48233b4e4