This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 SDK16 - Cannot enter System OFF

Hi everyone,

I am facing a kind of a strange problem. I want the system to enters system OFF mode when a certain pins goes to LOW. For that reason I have include code section below inside the main for(;;) loop.

When the WC_CHG pin goes to LOW I want the system to enter the system OFF mode. The strange thing is that while advertising and the WC_CHG pin goes to LOW the system normaly enters system OFF mode but when the peripheral is get connected with the central the system won't enter system OFF mode anymore. I noticed that when I add the NRF_LOG_INFO("Print here"); line the code works fine and I cannot understand how does it related with my problem. It is like the NRF_LOG_INFO() makes the loop runs normally..  Also I tried to add some delay but it doesn't work. Any advice?

 nrf_gpio_cfg_input(WC_CHG, NRF_GPIO_PIN_PULLUP);

for (;;) {

    int charging = nrf_gpio_pin_read(WC_CHG);
    if (!charging) {
      UN_state = BLE_STATE_CHARGING;
      charging_state(UN_state);
      //nrf_delay_ms(100); // na - some delay to run the function above before go to system OFF
      sleep_mode_enter();
    }
    // Enter system On sleep mode
    idle_state_handle(); // na - The Power Management library is safer to use than the inline functions __SEV, __WFE, __WFI especially when SoftDevice is used.
    NRF_LOG_INFO("Print here");
    
    
  }

Also I have a second problem. Before the system goes to system OFF mode the two NRF_LOG_INFO are not printed.

NRF_LOG_INFO("Stop advertising and go to sleep.");
NRF_LOG_INFO("Wait for TAP interrupt or STEP detection");

I tried to add some delay before sleep_mode_enter(); but did not work.. Any advice?

case BLE_ADV_EVT_IDLE:
    NRF_LOG_INFO("Stop Advertising event received %d", BLE_ADV_EVT_IDLE);
    NRF_LOG_INFO("Previous State %d", UN_state); // na

    if (UN_state == BLE_STATE_ADVERTISING) {
      NRF_LOG_INFO("Stop advertising and go to sleep.");        
      NRF_LOG_INFO("Wait for TAP interrupt or STEP detection"); 
      UN_state = BLE_STATE_SLEEP;
      nrf_delay_ms(100);
      sleep_mode_enter();
    } else if (UN_state == BLE_STATE_OFFLINE) {
      NRF_LOG_INFO("State %d", UN_state);
      ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST); // na - Restart advertising
    }
    break;

  default:
    break;

Thanks in advance

Nick

Parents
  • Hi,

    The strange thing is that while advertising and the WC_CHG pin goes to LOW the system normaly enters system OFF mode but when the peripheral is get connected with the central the system won't enter system OFF mode anymore. I noticed that when I add the NRF_LOG_INFO("Print here"); line the code works fine and I cannot understand how does it related with my problem.
    1.  Set a breakpoint at line 10 and see if the program enters the if statement, if it doesn't then it's because the conditional statement isn't true.
    2. Are you using deferred processing or in-place processing? 

    regards

    Jared

  • Hi Jared and thank you for your responce.

    Well, I was using deferred processing and it seems that this is the source for all the problems. I don't know why and how but as soon as I used in place processing everthing seems to work fine..

    I was using the NRF_LOG_PROCESS to process the NRF_LOGS

    static void idle_state_handle(void) {
      if (!NRF_LOG_PROCESS()) { 
        nrf_pwr_mgmt_run(); 
      }
    }
    

    Sould I also use the NRF_LOG_PROCESS somewhere else inside my code? Can you think any reason that could be responsible for these problems in order to avoid it in the future?

    I prefere to use the deferred processing as I've read that is safer.

    Thanks in advance

    Nick

  • You can try calling idle_state_handle(void) at the top in the for loop in main(), that way the log will be processed before you go to system off. 

Reply Children
No Data
Related