Waking up a 328P via the IRQ pin of NRF24L01

Discussion about wireless devices

Waking up a 328P via the IRQ pin of NRF24L01

Postby rrupad » Mon Aug 14, 2017 5:56 am

My scenario is as below.

Establishing a two way communication between two arduino boards. One is a central-panel and the other is a node with a sensor (runs on battery). The central panel activates the sensor node it needs and demands the data from that node. The node needs to wake up, acquire the data from the sensor, transmit it to the control panel and goto sleep (thus conserving battery power). 

The central panel sends a message to the node, the NRF24l01 board asserts an interrupt on the IRQ pin, that should wake up the Arduino. The IRQ pin of the NRF24l01 is connected to PD2 pin of the arduino (INT0 or PCINTx). 

Communication between the boards work - however when I introduce the sleep logic - the node receives the first message, sends the sensor reading and then goes to sleep - never to wakeup again. One more thing I notice is that even the NRF stops asserting the IRQ pin. I tried with Powerup of the board, CE as HI - upon wakeup but to no avail...
The sleep mode is set to POWER_DOWN mode and is supposed to wakeup with Level interrupt. When I connect a button to INT0 pin and press the button to generate the interrupt, it works without any problem (the Node wakes up) on every button press.

The issue is the same with PCINT as well - push button interrupt works whereas NRF24L01 IRQ does not work.

I have tested all the SLEEP modes - and no luck. sleep_cpu() puts the Arduino to sleep and does not wakeup.

I have scoured through the internet to find any implementations of the kind similar to my xcenario. But almost all of them are of self-wakeup type nodes that wake up on predetermined time (either using the timer interrupts or WDT timers).

My question! Have you been successful in waking up of Arduino using the NRF24l01 IRQ pin?? Is there something that needs to be considered to make it work? 
Also please find below the code fragments of the node (Uses PCINT18).
Thanks a lot in advance for any input/direction/tips..
Ravi Upadhyaya
Code: Select all
ISR(PCINT2_vect)
{
 if(PIND & (PIND2))
  SMCR &= ~(1 << SE);     // Disable sleep
 PORTD ^= (1 << PORTD5);      // Interrupt fired indicator
}

void initPCINT()
{
 DDRD &= ~(1 << PIND2);      // D2 as PCINT18
 PORTD |= (1 << PORTD2);      // Enable pull up
 PCICR |= (1 << PCIE2);      // Enable Interrupts (16-23) - we want 18
 PCMSK2 |= (1 << PCINT18);
}

void gotoSleep()
{
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 sei();
 SMCR |= (1 << SE);      // Enable sleep mode
 PORTD &= ~(1 << PORTD4);     // Sleep Indicator
 sleep_cpu();
 SMCR &= ~(1 << SE);      // Sleep disable
 PORTD |= (1 << PORTD4);      // Wakeup indicator
}

int main(void)
{
 uint8_t   ui8Count = 0;
 uint8_t   ui8Pipe;
 uint8_t   ui8Mode = TX;
 uint8_t   ui8NodeID = 1;
 uint8_t   ui8RecvStatus, ui8SendStatus;
 uint16_t  ui16TotalCount = 0, ui16RecvCount = 0;
 uint8_t   aui8Data[5];
 char   achBuffer[NRF_PAYLOAD_WIDTH];
 DDRD |= (1 << PORTD4) | (1 << PORTD5) | (1 << PORTD6);
 initSerial(); writeStringSerial("--------- SERIAL OK ---------\r\n");
 initSPI();
 configureNRF();
 writeRegister(STATUS, 0x7E);          // Write status register, clear of all the interrupts
 printReg(STATUS, readRegister(STATUS), HEX);
 _delay_us(USDELAY);
 writeRegister(EN_RXADDR, 0x21);    // Enable Receive on pipes 0 and 5
 writeRegister(EN_AA,  0x21);    // Write auto acknowledge RX register - Enable Auto Ack for pipe-5
 writeAddress(TX_ADDR, aui8AddrNode0_P5, 1);   // Reg 0x10, Addr : {0xe7, 0xe7, 0xe7, 0xe7, 0xe4}
 writeAddress(RX_ADDR_P0, aui8AddrNode0_P5, 1);   // RX Addr of TX5 set to TX address of TX5 device - for ack receipt
 writeAddress(RX_ADDR_P5, aui8AddrNode0_P5, 1);   // Pipe-5 for receiving data from Node 0 (Master)
 initINT0();
 ui8Mode = RX;

 while(1)
 {
  ui8Pipe = recvMsg(achBuffer);    // Recv Status is Pipe No where data is available
  if(ui8Pipe == ui8NodeID)
   ui8SendStatus = sendMsg("<<<<<<<<<-<<<<<<<<<-<<<<<<<<<<"); // Send this msg to the central panel
  gotoSleep();
 }
}

[img]src="C:\Users\ravi_.DESKTOP-78OPO19\Pictures\PushButtonPCINT.PNG"[/img]
rrupad
 
Posts: 20
Joined: Thu Sep 25, 2014 9:24 am

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby brennen » Tue Aug 15, 2017 3:25 pm

Just a couple of general things:

1) Is the L01 is staying powered on when the 328P is asleep (measure voltage)?
2) Are you telling the L01 to power down when the 328P goes to sleep?
3) Is the CE line that goes to the L01 staying high while the 328P is asleep? If that pin goes low, then the L01 will stop receiving anything.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby rrupad » Wed Aug 16, 2017 2:50 am

Thanks Brennen.

1) The L01 is staying powered when 328p goes to sleep. I am supplying the power from the 328p board (GND and 5V).
2) The L01 is not powered down at all - when the 328p goes to sleep. I wanted to get the communication between the boards to happen before starting to optimize on power consumption.
3) I have tried with keeping CE line continuously high when the 328p goes to sleep. The L01 IRQ did not assert ...

Regards,
Ravi Upadhyaya
rrupad
 
Posts: 20
Joined: Thu Sep 25, 2014 9:24 am

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby brennen » Wed Aug 16, 2017 12:29 pm

So when the RX unit goes to sleep, the TX unit is still *definitely* sending packets, correct? As in, the TX L01 is getting TX_DS interrupts, which assert its IRQ pin, but the RX side's L01 gets no RX_DR interrupts, and the IRQ pin is not asserted?

Also, to be thorough, when the RX unit is awake, the L01 does assert the IRQ pin when it gets an RX_DR interrupt, correct? Keeping in mind that the IRQ pin from the L01 is active low, so you'd need to set your interrupt/wakeup polarity on the 328P to match.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby rrupad » Wed Aug 16, 2017 4:49 pm

Hi Brennen:

So when the RX unit goes to sleep, the TX unit is still *definitely* sending packets, correct? >>> Yes - the TX unit is sending packets to the receiver when RX goes to sleep

RX side's L01 gets no RX_DR interrupts, and the IRQ pin is not asserted? >>> Yes, IRQ is asserted only once on the RX L01, the 328p goes to sleep and does not wakeup thereafter

when the RX unit is awake, the L01 does assert the IRQ pin when it gets an RX_DR interrupt, correct? >>Yes again.. When the 328p is awake, no problem in receiving packets on the RX L01 and the IRQ pin is asserted.

Keeping in mind that the IRQ pin from the L01 is active low, so you'd need to set your interrupt/wakeup polarity on the 328P to match. >>> Polarity?? I need some help here - I am not sure how this is done.

I did take Logic Analyzer traces of the scenario - but I do not know how a screenshot can be attached to this post. Let me try and reproduce the traces as I see on the logic analyzer.

Code: Select all
L01 IRQ ----------------+ < 124 ms   >+------------------------------------//---- No more IRQ assertions on RX
                        |             |
                        +-------------+

INT0    ----------------+ +-+ +-+ +-+ +-------------------------------------//----
                        | | | | | | | |
                        +-+ +-+ +-+ +-+

                        +------------------+
                        |                  |
WKUP/SLP----------------+ <- 156 ms------->+----------------------------------//---- 328p  Sleeps forever



The duration of WKUP/SLP trace that is HI is the period, the 328p is awake - in the reproduction above, it is awake for 156 ms.
INT0 ISR responds to a low level INT0 interrupt. From the figure, the INT0 level interrupt fires successively throughout the period where the IRQ from L01 is asserted.

Thanks Brennen.
rrupad
 
Posts: 20
Joined: Thu Sep 25, 2014 9:24 am

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby brennen » Thu Aug 17, 2017 1:28 pm

So you're definitely clearing the RX_DR interrupt on the L01? Are you able to receive multiple packets while the 328P is awake? This would at least indicate that you're clearing the RX_DR interrupt correctly. You'd also want to make sure the RX FIFO is not full before you go to sleep, though I can't remember what the L01 does when it receives a new packet but the RX FIFO is full (either push out the oldest one in the RX FIFO to make space, or reject the new packet).
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby rrupad » Thu Aug 17, 2017 3:09 pm

Yes, Brennen. I am able to receive payload when I bypass the sleep logic and the 328 is wide awake. I also flush off the RX buffers once I receive the payload and check the FIFO status to ensure that the receive buffers are empty.
rrupad
 
Posts: 20
Joined: Thu Sep 25, 2014 9:24 am

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby brennen » Fri Aug 18, 2017 1:24 pm

I'm kinda stumped at this point. The only thing that I can think of is that if you are allowing any of the SPI pins to float, the L01 may think you're clocking in data, and maybe it just happens to get a power down command? The same with the CE pin floating, which could cause RX to turn off if it floats low (this particular one honestly seems to be the most likely of all of the scenarios to me).
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby rrupad » Fri Aug 18, 2017 3:05 pm

I checked the SPI pins to see if there is a chance of any pin floating.. All the pins have been DDRd appropriately - still, I will check the status of each of the SPI pins and the CE pin when 328p goes to sleep.. Hopefully, that check may throw up any leads.

By the way, has anybody you know of, or have you come across code that has had success in waking up a 328p using L01?

Ravi Upadhyaya
rrupad
 
Posts: 20
Joined: Thu Sep 25, 2014 9:24 am

Re: Waking up a 328P via the IRQ pin of NRF24L01

Postby brennen » Mon Aug 21, 2017 1:09 pm

I can't say I've run across anyone specifically doing that, but that's certainly not to say that nobody ever has.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm


Return to Wireless

Who is online

Users browsing this forum: No registered users and 1 guest