328P does not wake up from sleep mode

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has any-one been successful waking up a sleeping 328P via a NRF24L01 IRQ interrupt?? 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 requirement is to put the node to sleep and wake up based on an interrupt (INT0 or PCINTx) read the data, send the data to central panel. The central-panel sends a message to the node and the NRF24L01 IRQ pin generates a signal. The node 328P wakes up and sends back the sensor output to the central panel and goes to sleep.
The arduino boards are linked using  NRF24L01 boards.
IRQ pin of the NRF24L01 are connected to PD2 (INT0) - and the IRQ pin of the NRF24L01 goes LO every time the NRF24l01 receives message from the central panel.
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.
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 checked that the IRQ pin of NRF24L01 does go low when there is a receive on the board.

 

 

<code>
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)
 initPCINT();
 initSonar();
 int iLevel, iPercent;
 uint8_t aui8MaxLevel[5] = { 250, 250, 250, 250, 250 };
 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();
 }

 

Please find attached the screen shots of the Logic Analyzer traces for your reference.

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A note on the attachments:

 

NRF24L01_INT0_LEVEL.PNG

 

The INT0 Level interrupt is being applied. 

Trace1 : The signal generated by the IRQ pin of NRF24L01

Trace2 : The INT0 Level Interrupt generated 

Trace3 : Wakeup/Sleep trace.. Logic HI is the time the uC was awake

 

PushButtonPCINT.PNG

 

The PIN change interrupt is being applied. 

Trace1 : The signal generated by the IRQ pin of NRF24L01

Trace2 : The PCINT18 Interrupt generated 

Trace3 : Wakeup/Sleep trace.. Logic HI is the time the uC was awake

​Thanks in advance..

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As a test, try using idle sleep mode, and see if it works?

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jim. Tried out IDLE mode.. Does not work..

 

Ravi Upadhyaya