WDT continues to run while in deep sleep mode.

My project utilizes the deep sleep or systemOff() function to minimize battery consumption. I'm at the final stages of development and I've run into some strange behavior. There are two occasions where we want the device to go to sleep. It is important to note that the sleep function called is the same in both circumstances:

Inactivity timer expires: After 30 seconds of no user activity the device should go to sleep. This works fine. A timer is used and my sleep function is called where important data is first saved to the last page in FLASH memory and then the device goes to sleep. When the device wakes up, it reads the saved data and runs with the saved parameters. No problem.

Critical battery alert: Here's where the problem lies. I have an analog pin connected to the battery with a lower voltage threshold programmed to set a "critical battery flag" if the voltage drops below it. If the critical battery flag is set the program runs the same sleep function as before and the device seems to go to sleep, accept that the WDT seems to be running. The device repeatedly resets, sees the battery is still low and goes to sleep only to wake right back up. I can increase the time it stays asleep by increasing the WDT time. Furthermore, once battery voltage is restored, the device wakes up as if the FLASH was empty/erased. If it was indeed shutting down successfully after the critical battery flag then it should have stored the data.

I found a post with a similar issue here. I'm not quite sure how to get PWR_MGMT_FPU_SLEEP_PREPARE to call from the main function, though, and nrf_pwr_mgmt_run() isn't working either. Any insight on how the WTD might wake up the system from deep sleep in one instance but not the other?

void sleep_system(void){

  uint32_t new_data [3] = {combination, ble_flags, battery_vthresh};  //  Backup important data.
  
  flash_erase(p_flash_adr_base);

  flash_write(p_flash_adr_base, new_data);

  //pwr_mgmt_fpu_sleep_prepare();
  //PWR_MGMT_FPU_SLEEP_PREPARE();
  nrf_pwr_mgmt_run();

  nrf_delay_ms(100);  //  Make sure backup is complete before running systemOff() as it will reset the MCU and erase RAM memory.

  systemOff();

}




uint32_t flash_read(uint32_t * adr){

  NRF_LOG_INFO("Reading from FLASH memory...");

  NRF_LOG_INFO("Data: %x at address: %x", *adr, adr);

  return *adr;

}




void flash_erase(uint32_t * adr){

  uint32_t err_code;
  uint32_t evt = 0;

  NRF_LOG_INFO("Erasing last page in FLASH memory...");
  NRF_LOG_INFO("Page #: %x", flash_page);


  err_code = sd_flash_page_erase(flash_page);

  APP_ERROR_CHECK(err_code);

  while(!evt){

    sd_evt_get(&evt);

  }
  if(evt == NRF_EVT_FLASH_OPERATION_ERROR){

    NRF_LOG_INFO("Error erasing FLASH.");
    return;

  }

  if(evt == NRF_EVT_FLASH_OPERATION_SUCCESS){

    NRF_LOG_INFO("FLASH page erased.");
    return;

  }
}




void flash_write(uint32_t * adr, uint32_t * new_data){

  uint32_t err_code;
  uint32_t evt = 0;

  NRF_LOG_INFO("Writing to FLASH memory...");

  err_code = sd_flash_write(adr, new_data, sizeof(new_data));
  APP_ERROR_CHECK(err_code);

  while(!evt){

    sd_evt_get(&evt);

  }
  if(evt == NRF_EVT_FLASH_OPERATION_ERROR){

    NRF_LOG_INFO("Error writing to FLASH.");
    return;

  }

  if(evt == NRF_EVT_FLASH_OPERATION_SUCCESS){

    NRF_LOG_INFO("Success writing to FLASH.");
    return;

  }
}




Parents
  • I found this this explanation in the "Product Specification" of the nRF528xx:

    6.9.2 Port event

    PORT is an event that can be generated from multiple input pins using the GPIO DETECT signal. The event will be generated on the rising edge of the DETECT signal. See GPIO — General purpose input/output on page 141 for more information about the DETECT signal.

    The GPIO DETECT signal will not wake the system up again if the system is put into System ON IDLE while the DETECT signal is high. Clear all DETECT sources before entering sleep. If the LATCH register is used as a source, a new rising edge will be generated on DETECT if any bit in LATCH is still high after clearing all or part of the register. This could occur if one of the PINx.DETECT signals is still high, for example. See Pin configuration on page 142 for more information.

    Setting the system to System OFF while DETECT is high will cause a wakeup from System OFF reset.

Reply
  • I found this this explanation in the "Product Specification" of the nRF528xx:

    6.9.2 Port event

    PORT is an event that can be generated from multiple input pins using the GPIO DETECT signal. The event will be generated on the rising edge of the DETECT signal. See GPIO — General purpose input/output on page 141 for more information about the DETECT signal.

    The GPIO DETECT signal will not wake the system up again if the system is put into System ON IDLE while the DETECT signal is high. Clear all DETECT sources before entering sleep. If the LATCH register is used as a source, a new rising edge will be generated on DETECT if any bit in LATCH is still high after clearing all or part of the register. This could occur if one of the PINx.DETECT signals is still high, for example. See Pin configuration on page 142 for more information.

    Setting the system to System OFF while DETECT is high will cause a wakeup from System OFF reset.

Children
No Data
Related