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:
9:c21b80aaf250
Parent:
8:3e027705ce23
Child:
10:8a217441c38e
--- a/NRF2401P.cpp	Sun Jul 05 23:33:37 2015 +0000
+++ b/NRF2401P.cpp	Sat Jul 11 09:38:59 2015 +0000
@@ -438,7 +438,7 @@
 }
 
 /**
-* Sets the address, uses addess width set (either 3,4 or 5)
+* Sets the address, uses address width set (either 3,4 or 5)
 * Enables pipe for receiving;
 */
 char NRF2401P::setRxAddress( char *address, char pipe )
@@ -583,7 +583,7 @@
     dynamic = true;
     writeReg(FEATURE, 0x07);  // Enable Dyn payload, Payload with Ack and w_tx_noack command
     writeReg(EN_AA, 0x3f); // EN_AA regi for P1 and P0
-    writeReg(DYNPD, 0x1F);
+    writeReg(DYNPD, 0x3F);    // KJN - should be 0x3F for all pipes
 }
 
 /**
@@ -669,4 +669,39 @@
     if ((status>>0)&0x01) strcat(msg," TX_FLL,");
 
     return msg;
+}
+
+void NRF2401P::printDetails()
+{
+    char data;
+    char status = checkStatus();
+    printf("STATUS\t\t = 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,
+           (status & (1<<MASK_MAX_RT))?1:0,
+           (status >> RX_P_NO) & 7,
+           (status & (1<<TX_FULL))?1:0 );
+
+    printf("RX_PW_P0-5\t = ");
+    readReg(RX_PW_P0, &data); printf("0x%02x ", data);
+    readReg(RX_PW_P1, &data); printf("0x%02x ", data);
+    readReg(RX_PW_P2, &data); printf("0x%02x ", data);
+    readReg(RX_PW_P3, &data); printf("0x%02x ", data);
+    readReg(RX_PW_P4, &data); printf("0x%02x ", data);
+    readReg(RX_PW_P5, &data); printf("0x%02x ", data);
+    printf("\r\n");
+    readReg(EN_AA, &data);          
+    printf("EN_AA\t\t = 0x%02x\r\n", data);
+    readReg(EN_RXADDR, &data);          
+    printf("EN_RXADDR\t = 0x%02x\r\n", data);
+    readReg(RF_CH, &data);
+    printf("RF_CH\t\t = 0x%02x\r\n", data);
+    readReg(RF_SETUP, &data);
+    printf("RF_SETUP\t = 0x%02x\r\n", data);
+    readReg(CONFIG, &data);
+    printf("CONFIG\t\t = 0x%02x\r\n", data);
+    readReg(DYNPD, &data);
+    printf("DYNPD\t\t = 0x%02x\r\n", data);
+    readReg(FEATURE, &data);
+    printf("FEATURE\t\t = 0x%02x\r\n", data);
 }
\ No newline at end of file