sleep_mode() power down breaks RF Communication

Discussion in 'Microcontrollers, Programming and IoT' started by Uma Maheswary, Dec 14, 2016.

  1. Uma Maheswary

    Uma Maheswary

    Joined:
    Dec 14, 2016
    Messages:
    2
    Likes Received:
    0
    Hi
    I could run the LWmesh peer to peer application for my atmega256rfr2 devices.http://www.atmel.com/tools/lightweight_mesh.aspx.Now I modified the code for reducing power consumption in rf devices.The modified code for sending device is as follows
    Code:
    volatile int lastPIRsensorState=1;
    volatile int PIRsensorState=0;
    void Hibernate(){
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    ADCSRA&=~(1<<7);
    sleep_enable();
    EICRA|=(1<<ISC00);
    EIMSK|=(1<<INT0);
    sei();
    sleep_disable();
    EIMSK&=~(1<<INT0);
    cli();
    }
    ISR(INT0_vect){
    PIRsensorState=!lastPIRsensorState;
    }
    static void appDataConf(NWK_DataReq_t *req){
    appDataReqBusy=false;
    (void)req;
    }
    static void appSendData(void){
    
    if (appDataReqBusy)
        return;
    
     
      appDataReqBuffer[0]=PIRsensorState;
      appDataReq.dstAddr = 1-APP_ADDR;
      appDataReq.dstEndpoint = APP_ENDPOINT;
      appDataReq.srcEndpoint = APP_ENDPOINT;
      appDataReq.options = NWK_OPT_ENABLE_SECURITY;
      appDataReq.data = appDataReqBuffer;
      appDataReq.size = 1;
      appDataReq.confirm = appDataConf;
      NWK_DataReq(&appDataReq);
      appDataReqBusy = true;
    }
    static void appTimerHandler(SYS_Timer_t *timer)
    {
      appSendData();
      (void)timer;
    }
    static void appInit(void)
    {
      NWK_SetAddr(APP_ADDR);
      NWK_SetPanId(APP_PANID);
      PHY_SetChannel(APP_CHANNEL);
    #ifdef PHY_AT86RF212
      PHY_SetBand(APP_BAND);
      PHY_SetModulation(APP_MODULATION);
    #endif
      PHY_SetRxState(true);
    
     
    
      HAL_BoardInit();
    
      appTimer.interval = APP_FLUSH_TIMER_INTERVAL;
      appTimer.mode = SYS_TIMER_INTERVAL_MODE;
      appTimer.handler = appTimerHandler;
    }
    
    /*************************************************************************//**
    *****************************************************************************/
    static void APP_TaskHandler(void)
    {
      switch (appState)
      {
        case APP_STATE_INITIAL:
        {
          appInit();
          appSendData();
          appState = APP_STATE_IDLE;
        } break;
    
        case APP_STATE_IDLE:
          break;
    
    
        default:
          break;
      }
    }
    
    /*************************************************************************//**
    *****************************************************************************/
    int main(void)
    {
      SYS_Init();
      PORTD=1<<PD0
      HAL_UartInit(9600);
      while (1)
      {
        SYS_TaskHandler();
        HAL_UartTaskHandler();
        APP_TaskHandler();
       lastPIRsensorState=PIRsensorState;
       Hibernate();
      }
    }
    The device communication works well when the Hibernate() function is not called.But when this function is called it enters into a deep sleep and communicate seldom .dis sleep mode affect rf communication?What is the mistake in my code please help.
     
    Uma Maheswary, Dec 14, 2016
    #1
    1. Advertisements

  2. Uma Maheswary

    pgib8

    Joined:
    Jul 26, 2015
    Messages:
    99
    Likes Received:
    22
    i'm not going to dissect your code, but is it possible that when your mcu is in sleep, it's not grabbing data from the rf chip, so that the rf chip fills up? is the rf supposed to keep working while the mcu is in sleep?
     
    pgib8, Dec 22, 2016
    #2
    1. Advertisements

  3. Uma Maheswary

    Uma Maheswary

    Joined:
    Dec 14, 2016
    Messages:
    2
    Likes Received:
    0
    yes.I need the rf should keep working while the mcu is in sleep
     
    Uma Maheswary, Dec 23, 2016
    #3
  4. Uma Maheswary

    pgib8

    Joined:
    Jul 26, 2015
    Messages:
    99
    Likes Received:
    22
    if the RF chip signals your MCU every time it received a packet, then your MCU reads out this data and so forth. If the MCU is sleeping, maybe it's possible this doesn't occur and the queue fills up. when the MCU wakes up again, the RF chip is full and won't send the signal that it received new packets. just a thought.
     
    pgib8, Jan 4, 2017
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.