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

Is there an example on how to handle power failure events with s210 (ANT)

Unfortunately, I'm not seeing NRF_EVT_POWER_FAILURE_WARNING events on my s210 based system. As I've seen in other questions on the forum, I've implemented the calls below with no luck. Attempts to use sd_evt_get() were also fruitless. Any ideas? Thank you!

err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, softdevice_assert_callback);
APP_ERROR_CHECK(err_code);

err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW);
APP_ERROR_CHECK(err_code);

err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);
APP_ERROR_CHECK(err_code);

err_code = sd_power_pof_enable(true);
APP_ERROR_CHECK(err_code);

err_code = sd_power_pof_threshold_set(NRF_POWER_THRESHOLD_V27); /**< 2.5 Volts power failure threshold. */ 
APP_ERROR_CHECK(err_code);


for (;;)
{
            
	err_code = sd_power_pof_enable(false);
	APP_ERROR_CHECK(err_code);

	err_code = sd_app_evt_wait();
	APP_ERROR_CHECK(err_code);

	err_code = sd_power_pof_enable(true);
	APP_ERROR_CHECK(err_code);

	// Extract and process all pending ANT events as
	//long as there are any left.
	do
	{
		// Fetch the event.
		err_code = sd_ant_event_get(&ant_channel, &event_id, event_message_buffer);
		if (err_code == NRF_SUCCESS)
		{
			// Handle event.
			switch (event_id)
			{
			case NRF_EVT_POWER_FAILURE_WARNING:
				set_led(); //never gets called
				break;
			default:
				break;
			}
		}
	} while (err_code == NRF_SUCCESS);
}
Parents
  • I was able to resolve my issue by retrieving the message from within SD_EVT_IRQHandler(). See excerpt below:

    void SD_EVT_IRQHandler(void)
    {
        uint32_t err_code;
        uint32_t sd_event_id;
    
    	do
    	{
    		// Fetch the event.
    		err_code = sd_evt_get( &sd_event_id);
    		if (err_code == NRF_SUCCESS)
    		{
    			// Handle event.
    			switch (sd_event_id)
    			{
    			case NRF_EVT_POWER_FAILURE_WARNING:
    				saveTheWorld();
    				break;
    			default:
    				break;
    			}
    		}
    	} while (err_code == NRF_SUCCESS);
    }
    
Reply
  • I was able to resolve my issue by retrieving the message from within SD_EVT_IRQHandler(). See excerpt below:

    void SD_EVT_IRQHandler(void)
    {
        uint32_t err_code;
        uint32_t sd_event_id;
    
    	do
    	{
    		// Fetch the event.
    		err_code = sd_evt_get( &sd_event_id);
    		if (err_code == NRF_SUCCESS)
    		{
    			// Handle event.
    			switch (sd_event_id)
    			{
    			case NRF_EVT_POWER_FAILURE_WARNING:
    				saveTheWorld();
    				break;
    			default:
    				break;
    			}
    		}
    	} while (err_code == NRF_SUCCESS);
    }
    
Children
No Data
Related