KenYEAH! 2k15 / Mbed 2 deprecated NRF2401P

Dependencies:   mbed

Fork of NRF2401P by Malcolm McCulloch

Files at this revision

API Documentation at this revision

Comitter:
epgmdm
Date:
Thu Jun 11 17:00:18 2015 +0000
Parent:
0:8fd0531ae0be
Child:
2:ca0a3c0bba70
Commit message:
Added a few extras

Changed in this revision

NRF2401P.cpp Show annotated file Show diff for this revision Revisions of this file
NRF2401P.h Show annotated file Show diff for this revision Revisions of this file
--- a/NRF2401P.cpp	Thu Jun 11 11:19:57 2015 +0000
+++ b/NRF2401P.cpp	Thu Jun 11 17:00:18 2015 +0000
@@ -42,7 +42,7 @@
     csn = 1;
     ce = 0;
     dynamic = false;
-    debug=false;
+    debug=1|false;
 
 };
 
@@ -52,8 +52,8 @@
 void NRF2401P::log (char *msg)
 {
     if(debug) {
-        pc->printf("%s \t %s\n\r",statusString(), msg);
-        wait(0.1);
+        printf("<%s \t %s>\n\r",statusString(), msg);
+        wait(0.01);
     };
 }
 
@@ -82,12 +82,13 @@
     setRadio(0,3);
     setChannel(channel);
     setRxMode();
-    setPwrUp();
+
     setAddressWidth(3);
-    setRxAddress(addr,1);
+    setRxAddress(addr,0);
     setDynamicPayload();
-    writeReg(0x02,0x03); // EN_RXADDR for P1 and P0
-    writeReg(0x01,0x3f); // EN_AA regi for P1 and P0
+    writeReg(0x02,0x03); // EN_RXADDR for P1
+    writeReg(0x01,0x03); // EN_AA regi for P1
+    setPwrUp();
 
     ce=1;
     wait (0.1f);
@@ -130,6 +131,10 @@
     setDynamicPayload();
     setAddressWidth(3);
     setTxAddress(addr);
+    writeReg(0x04,0x2f);  // ARD 750 uS  ARC 15
+    writeReg(0x02,0x03); // EN_RXADDR for P1 and P0
+    setPwrUp();
+
     ce=1;
     wait (0.0016f); // wait for pll to settle
 }
@@ -194,6 +199,7 @@
 */
 char NRF2401P::transmitData( char *data, char width )
 {
+    clearStatus();
     ce = 1;
     csn = 0;
     char address = 0XA0;
@@ -213,7 +219,7 @@
 /**
 * sets acknowledge data width bytes of data. width <32
 */
-char NRF2401P::acknowledgeData( char *data, char width, char pipe=1 )
+char NRF2401P::acknowledgeData( char *data, char width, char pipe )
 {
     ce = 1;
     csn = 0;
@@ -417,10 +423,31 @@
     buff[ 4 ] = ( address >> 32 ) & 0xFF;
     return setRxAddress( buff, pipe );
 }
+/**
+*checks the status flag
+*/
+char NRF2401P::checkStatus()
+{
+    readReg(0x07,&status);
+    return status;
+}
+/**
+* checks if Ack data available.
+*/
+bool NRF2401P::isAckData()
+{
+    char fifo;
+    readReg(0x17,&fifo);
+    bool isData = !(fifo&0x01);
+    return isData;
+}
 
+/**
+* checks if RX data available.
+*/
 bool NRF2401P::isRxData()
 {
-    readReg(0x07,&status);
+    checkStatus();
     bool isData = (status>>6)&0x01;
     return isData;
 }
@@ -444,7 +471,7 @@
         status = readReg(0x12,&width); // width of p1
 
     }
-   // width=18;
+    // width=18;
     return width;
 }
 /**
@@ -486,7 +513,9 @@
 char NRF2401P::setDynamicPayload()
 {
     dynamic = true;
-    writeReg (0x1D,0x04);
+
+    writeReg (0x1D,0x06);
+    writeReg(0x01,0x3f); // EN_AA regi for P1 and P0
     return(writeReg(0x1C, 0x1F));
 }
 /**
--- a/NRF2401P.h	Thu Jun 11 11:19:57 2015 +0000
+++ b/NRF2401P.h	Thu Jun 11 17:00:18 2015 +0000
@@ -38,11 +38,13 @@
     NRF2401P (PinName mosi, PinName miso, PinName sclk, PinName _csn, PinName _ce);
 
     char acknowledgeData( char *data, char width, char pipe);
+    char checkStatus();
     bool clearStatus();
     bool flushRx();
     bool flushTx();
     char getRxData(char * buffer);
     char getRxWidth();
+    bool isAckData();
     bool isRxData();
     void log (char *msg);
     void quickRxSetup(int channel,long long addr);