This is a work in progress for an NRF2401P

Dependents:   NRF_receiver sender locker4 Weather_Station_Ofiicial ... more

About

This is a simple library to drive the nRF24l01+.

Hardware

This uses the commonly available breakout. The connections are shown below /media/uploads/epgmdm/nrf24l01pinout.png

Software

Use case: For a simple transmitter

tx code snipet

#include "NRF2401P.h"
int main() {
*
*  long long addr1=0xAB00CD; // setup address - any 5 byte number - same as RX
*  int channel =0x12;  // [0-126] setup channel, must be same as RX
*  bool txOK;
*  char msg[32];
*  char ackData[32];
*  char len;
*
*  // Setup 
*  NRF2401P nrf1(PTD6,PTD7, PTD5,PTD4, PTC12); //mosi, miso, sclk, csn, ce)
*  nrf1.quickTxSetup(channel, addr1); // sets nrf24l01+ as transmitter
*
*  // transmit
*  strcpy (msg, "Hello"); 
*  txOK= nrf1.transmitData(msg,strlen(msg));
*
*  // read ack data if available
*  if (nrf1.isAckData()) { 
*      len= nrf1.getRxData(ackData); // len is number of bytes in ackData
*   }
*}

Use case: For a simple receiver

rx code snipet

#include "NRF2401P.h"
*int main(){
*        
*  long long addr1=0xAB00CD; // setup address - any 5 byte number - same as TX
*  int channel =0x12;  // [0-126] setup channel, must be same as TX
*  bool txOK;
*  char msg[32];
*  char ackData[32];
*  char len;
*
*  // Setup 
*  NRF2401P nrf1(PTD6,PTD7, PTD5,PTD4, PTC12); //mosi, miso, sclk, csn, ce)
*  nrf1.quickRxSetup(channel, addr1); // sets nrf24l01+ as  receiver, using pipe 1
*
*  // set ack data
*  sprintf(ackData,"Ack data");
*  nrf1.acknowledgeData(ackData, strlen(ackData),1); // ack for pipe 1
*    
*  // receive
*  while (! nrf1.isRxData()); // note this blocks until RX data
*  len= nrf1.getRxData(msg); // gets the message, len is length of msg
*
*}
Revision:
14:976a876819ae
Parent:
13:5cbc726f2bbb
Child:
16:a9b83d2b6915
--- a/NRF2401P.cpp	Sat Jul 11 21:20:56 2015 +0000
+++ b/NRF2401P.cpp	Sat Jul 11 22:17:36 2015 +0000
@@ -283,7 +283,6 @@
 **/
 void NRF2401P::writeReg( char address, char data )
 {
-    char status = 0;
     char reg;
     csn = 0;
     address &= 0x1F;
@@ -556,26 +555,24 @@
     return isData;
 }
 
-/**
-* returns the width of the dynamic payload
-*/
 char NRF2401P::getRxWidth()
 {
     char width;
     if (dynamic) {
         csn = 0;
-        status = spi->write( 0x60 );
+        status = spi->write( R_RX_PL_WID );
         width = spi->write(0x00);
         csn = 1;
 
-        if (width>32) {
+        if (width>32) {             // as per product spec
             flushRx();
+            wait(0.002f);           // little delay (KJN)
             width=0;
         }
     } else {
         readReg(RX_PW_P1, &width); // width of p1
     }
-    // width=18;
+    
     return width;
 }
 
@@ -734,7 +731,7 @@
 }
 
 void NRF2401P::printDetails() {
-    char status = checkStatus();
+    status = checkStatus();
     printf("STATUS = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n", status,
            (status & (1<<MASK_RX_DR))?1:0,
            (status & (1<<MASK_TX_DS))?1:0,