Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Power failure comparator, nRF52811

Hello,

nRFSD5 v16.0, softdevice v.7.0.1, nRF52811

I want to detect power failure/low battery voltage using POF feature of nRF52811 chip. Here is the code I'm using:

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "nrf_gpio.h"
#include "nrfx_uart.h"
#include "nrfx_comp.h"
#include "nrfx_systick.h"
#include "nrf_log.h"

#include "cue_driver.h"

static void sys_evt_dispatch(uint32_t sys_evt) { 
    if (sys_evt == NRF_EVT_POWER_FAILURE_WARNING) { 
        //testData = 0; 
        NRF_LOG_INFO("Power failure...");
    } 
}

void pof_init(){
    uint32_t err_code;

    err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled << POWER_POFCON_POF_Pos);
    APP_ERROR_CHECK(err_code);

    err_code = sd_power_pof_threshold_set(POWER_POFCON_THRESHOLD_V27);
    APP_ERROR_CHECK(err_code);

    // Subscribe for Sys events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

When I compile, get following error:

undefined reference to `softdevice_sys_evt_handler_set'

I searched online but cannot find the cause of error. I found an example here but that is for SDK11. How can I do the same for SDK16.0? 

Parents
  • Hi

    Here are diff files of what you would need to implement in your project in order to add the POF warning in an application using the SoftDevice:

    main.c:

    #include "nrf_drv_power.h"
    
    //...
    
    static void pow_warn_evt_handler(void)
    {
        NRF_LOG_ERROR("POF warning!");
        bsp_board_led_on(BSP_BOARD_LED_3);
    }
    
    
    /**@brief Function for initializing POF driver.
     */
    static void pof_warn_init(void)
    {
        ret_code_t err_code;
    
        static const nrf_drv_power_pofwarn_config_t pof_config =
        {
            .handler    = pow_warn_evt_handler,
            .thr        = NRF_POWER_POFTHR_V20,
        };
    
        static nrfx_power_config_t power_config;
        memset(&power_config, 0, sizeof(power_config));
        err_code = nrf_drv_power_init(&power_config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_power_pof_init(&pof_config);
        APP_ERROR_CHECK(err_code);
    }
    
    //Call the pof_warn_init(); function in your main loop to init

    In sdk_config.h, set NRFX_POWER_ENABLED to 1 and POWER_ENABLED to 1.

    Alternatively, you can check out the documentation for the nrf_drv_power_pof_init function in the Infocenter here.

    Best regards,

    Simon

  • Thank you Simonr, that will greatly help. I'll test it assap.

Reply Children
No Data
Related