PowerDown Nrf24l01

Hello,

I am currently working with Nrf24l01 where there is a master and slave. The circuit is connected correctly and the data is also transmitting successfully. The operation is as follows whenever there is a interrupt on the interrupt pin of the slave the data will be transmitted (this part is running successfully).Following is the sketch for it

For Master:

// MultiTxAckPayload - the master or the transmitter
//   works with two Arduinos as slaves
//     each slave should the SimpleRxAckPayload program
//       one with the adress {'R','x','A','A','A'}
//         and the other with {'R','x','A','A','B'}

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN   9
#define CSN_PIN 10

const byte numSlaves = 2;
const byte slaveAddress[numSlaves][5] = {
        // each slave needs a different address
                            {'R','x','A','A','A'},
                            {'R','x','A','A','B'}
                        };

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

//~ char dataToSend[10] = "Message 0";
char dataToSend[10] = "ToSlvN  0";
char pirDataReceived[5];
bool newData = false;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second

//===============

void setup() {

    Serial.begin(9600);
    Serial.println(F("Source File = /mnt/SGT/SGT-Prog/Arduino/ForumDemos/nRF24Tutorial/MultiTxAckPayload.ino "));
    Serial.println("SimpleTxAckPayload Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );

    radio.enableAckPayload();

    radio.setRetries(15,15); // delay, count
        // radio.openWritingPipe(slaveAddress); -- moved to loop()
}

//=============

void loop() {

    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
    }
        // showData(); -- moved into send()
}

//================

void send() {

        // call each slave in turn
    for (byte n = 0; n < numSlaves; n++){

            // open the writing pipe with the address of a slave
        radio.openWritingPipe(slaveAddress[n]);

            // include the slave number in the message
        dataToSend[5] = n + '0';

        bool rslt;
        rslt = radio.write( &dataToSend, sizeof(dataToSend) );
            // Always use sizeof() as it gives the size as the number of bytes.
            // For example if dataToSend was an int sizeof() would correctly return 2

        Serial.print("  ========  For Slave ");
        Serial.print(n);
        Serial.println("  ========");
        Serial.print("  Data Sent ");
        Serial.print(dataToSend);
        if (rslt) {
            if ( radio.isAckPayloadAvailable() ) {
                radio.read(&pirDataReceived, sizeof(pirDataReceived));
                newData = true;
            }
            else {
                Serial.println("  Acknowledge but no data ");
            }
           call();
        }
        else {
            Serial.println("  Tx failed");
        }
        showData();
        Serial.print("\n");
    }

    prevMillis = millis();
 }


//=================

void showData() {
    if (newData == true) {
        Serial.println("  Acknowledge data ");
        Serial.println(pirDataReceived);
        call();
        newData = false;
    }
}

//================

void call()
{

  if(strcmp(pirDataReceived,"ON 1")==0)
  {
    Serial.println("Led 1On");
  }
  else if(strcmp(pirDataReceived,"ON 2")==0)
  {
    Serial.println("Led 2On");
  }
  else if(strcmp(pirDataReceived,"ON 0")==0)
  {
    Serial.println("Led Off");
  }
}

and slave is

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>



#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};



int buttonInput = 2;
int pir1;

char pirData[5]="ON 0";
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 250; // send once per second

char dataReceived[10]; // this must match dataToSend in the TX

bool newData = false;


void setup() {
 
  
  attachInterrupt(0, digitalInterrupt, FALLING); 
  
  
}

void loop() {  


  
}

void digitalInterrupt(){

  //needed for the digital input interrupt
pir1 = digitalRead(buttonInput);
    getData();
}



void getData() {

 RF24 radio(CE_PIN, CSN_PIN);
 
 //   Serial.println("Get data");
     radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(15,15);
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.enableAckPayload();
    radio.startListening();
    radio.writeAckPayload(1, &pirData, sizeof(pirData)); // pre-load data
 
    
     
// radio.powerDown ();
}

the above sketch works fine

I want to power down the NRF24l01 module once it has trasmitted data in SLAVE so i tried to use the radio.powerDown(); as it shown in the slave sketch (last line) but the problem i am facing is it gets powerDown and doesn't transmit data when the interrupt is given. the sketch for it is

include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>



#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};



int buttonInput = 2;
int pir1;

char pirData[5]="ON 0";
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 250; // send once per second

char dataReceived[10]; // this must match dataToSend in the TX

bool newData = false;


void setup() {
 
  
  attachInterrupt(0, digitalInterrupt, FALLING); 
  
  
}

void loop() {  


  
}

void digitalInterrupt(){

  //needed for the digital input interrupt
pir1 = digitalRead(buttonInput);
    getData();
}



void getData() {

 RF24 radio(CE_PIN, CSN_PIN);
 
 //   Serial.println("Get data");
     radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(15,15);
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.enableAckPayload();
    radio.startListening();
    radio.writeAckPayload(1, &pirData, sizeof(pirData)); // pre-load data
 
    
     
 radio.powerDown ();
}

I want to transmit data when there is interrupt and put slave nrf24l01 module in powerdown mode again wakeup the module whenever there is interrupt .

JairajDange:
I want to power down the NRF24l01 module once it has trasmitted data in SLAVE
[...]
I want to transmit data when there is interrupt and put slave nrf24l01 module in powerdown mode again wakeup the module whenever there is interrupt .

I think you are using the wrong example from my tutorial.

For the master-slave system that you have implemented the slave must be listening all the time to receive the message when the master sends it.

You probably need a system like in my first example but with the master and slave concepts reversed. The master (if that is still the right word) should be listening all the time and then the slaves can send whenever they are ready. However there is a risk that two slaves will send at the same time causing the data to be garbled so you will need to build some code into your slaves to deal with that - perhaps try again after a random time in the region of 20 to 100 millisecs. Using multiple auto-retries might actually make things worse. Think of two small children trying to shout each other down.

I have not used the powerDown() feature so I suggest you try the revised arrangement without it first and when things are working then introduce the powerDown.

...R
Simple nRF24L01+ Tutorial