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

regarding the sleep mode

hi..........

i am using nrf42840 ...segger 15.2 version 

i am facing the problem in sleep mode 

i used the command to sleep

static void power_manage( void )
{
ret_code_t err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);

} but it doesn't going to sleep please help me 

see the code below

static void power_manage( void )
{
    ret_code_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
	
}





/**@brief Application main function.
 */
int main(void)
{
    bool erase_bonds;

    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    uint32_t i;
     

    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();
     // Enter main loop.
   for(;;)
    {
    while(1)
    ble_nus_data_send(&m_nus, "hello", 6, m_conn_handle);
       power_manage();
        idle_state_handle();
     }
     }


/**

Parents Reply Children
  • ok ..inplace of while(1) .... can i able to put the for condition  .i have executed this statement, only one time data executed 

    static void power_manage( void )
    {
        ret_code_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    	
    }
    
    
    
    
    
    /**@brief Application main function.
     */
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        uart_init();
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        uint32_t i;
         
    
        // Start execution.
        printf("\r\nUART started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        advertising_start();
         // Enter main loop.
       for(;;)
        {
        for(i=0;i<=5;i++)
        ble_nus_data_send(&m_nus, "hello", 6, m_conn_handle);
           power_manage();
            idle_state_handle();
         }
         }
    

  • You need to be in a connection before sending data over BLE. If your application goes to sleep, without having any wakeup-condition, it will remain in sleep.

  • ok fine .... if i want to send the data for 6 times and it should go to sleep ...for this case shall i use (for loop condition) pls see the code below 

        // Enter main loop.
       for(;;)
        {
        for(i=0;i<=5;i++)
        ble_nus_data_send(&m_nus, "hello", 6, m_conn_handle);
           power_manage();
            idle_state_handle();
         }
         }
    

  • you do not check the return code, so you are not guaranteed that the function will run successfully.

    A quick workaround can be while(ble_nus_data_send(&m_nus, "hello", 6, m_conn_handle) != NRF_SUCCESS); within the for loop. Also, I recommend that you use braces to see your scope. ie;

    for(int i=0;i<some_size;i++) {

      some_function();

    }

    Best regards,

    Håkon

Related