<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to configure the interrupt handler for the POF.  POFWARN example code.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/109970/how-to-configure-the-interrupt-handler-for-the-pof-pofwarn-example-code</link><description>Hi, 
 I am using nrf52832 board and I want to add the code for power fail comparator POF. I want to put my device into deep sleep mode if the battery voltage is reduced below 2.4 volts. Can you please share me the POF example code to generate the POFWARN</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Apr 2024 12:45:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/109970/how-to-configure-the-interrupt-handler-for-the-pof-pofwarn-example-code" /><item><title>RE: How to configure the interrupt handler for the POF.  POFWARN example code.</title><link>https://devzone.nordicsemi.com/thread/478776?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 12:45:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cef464c4-77b8-4841-adea-9d07dacbe125</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Naveed,&lt;/p&gt;
[quote user="Naveed"]Should I directly call&amp;nbsp;&lt;span&gt;sd_power_system_off()?&lt;/span&gt;[/quote]
&lt;p&gt;You should configure the GPIOs properly for your product before entering system off mode.&lt;/p&gt;
[quote user="Naveed"]I want my device to turn ON only when the input is more than the threshold set that is 2.3V. If it is below the threshold it should enter into sleep mode.[/quote]
&lt;p&gt;I see. First of all, I suggest you have a form of hysteresis, to avid a loop where the device enters system off mode, wakes up and enters it again (so a lower threshold for entering systme of mode than from waking up). Regarding wakeup, you can use the LPCOMP peripheral as a wakeup source from system off, and that seems to fit whell what you descrive here. So that means you need to configure the LPCOMP before enteering system off mode (you can refer to the LPCOMP sample in the SDK for how to configure it).&lt;/p&gt;
[quote user="Naveed"]When I run the code in the release mode without debugger, I am still getting the&lt;strong&gt; RED LED&lt;/strong&gt; blinking continuously with a certain period &lt;strong&gt;in sleep mode&lt;/strong&gt;.&amp;nbsp;As it blinks continuously it still consumes the current in the sleep mode.&amp;nbsp;[/quote]
&lt;p&gt;I don&amp;#39;t know much about your hardware or firmware, but clearly the device is not in sysrtem off at this point. If it only happens when not debugging, perhaps you can debug with GPIOs? Could it be that the device is unexpectedly waking up from system off when it should not? Is the blinking caused by a reset loop or doesthe device just wake up and then you have some firmware that makes it blink?&lt;/p&gt;
[quote user="Naveed"]Please let me know how to set the GPIOs to sensible values before entering into sleep mode. So that LED should stop blinking and it will not drain the battery.[/quote]
&lt;p&gt;There will be no LED blinking in system off mode (the GPIOs cannot change state in system off mode). As you see LEDs blink, the device is clearly not in system off the whole time. Regarding which state to put the GPIOs in that is entierly application specific. Which state makes sense on your design? Make sure that you set the pins to whatever is sensible for you before entering system off mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure the interrupt handler for the POF.  POFWARN example code.</title><link>https://devzone.nordicsemi.com/thread/478728?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 10:59:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf6d32f8-17db-4393-9a1e-88a8acd2395c</guid><dc:creator>Naveed</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have referred few tickets in the nordic forum to put the device into sleep mode correct me that we have to follow the below steps.&lt;/p&gt;
&lt;p&gt;void sleep_mode_enter(void)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uint32_t err_code;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; err_code = bsp_indication_set(BSP_INDICATE_IDLE);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; err_code = bsp_btn_ble_sleep_mode_prepare();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; err_code = sd_power_system_off();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; APP_ERROR_CHECK(err_code);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;OR, &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Should I directly call&amp;nbsp;&lt;span&gt;sd_power_system_off()? &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;I want my device to turn ON only when the input is more than the threshold set that is 2.3V. If it is below the threshold it should enter into sleep mode.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When I run the code in the release mode without debugger, I am still getting the&lt;strong&gt; RED LED&lt;/strong&gt; blinking continuously with a certain period &lt;strong&gt;in sleep mode&lt;/strong&gt;.&amp;nbsp;As it blinks continuously it still consumes the current in the sleep mode.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; all the application functions shall stop and LED&amp;#39;s will be OFF.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Actual output:&lt;/strong&gt; RED LED is blinking continuously which still consumes power.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In your previous reply,&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;[&lt;span&gt;POFWARN will just trigger an event (and block any writes to flash). If you want to enter system OFF mode, you need to do that yourself by calling&amp;nbsp;sd_power_system_off(). Wakeup from system-off would be in form of a reset, but you should make sure that the system is in a safe state before entering system off mode (depending on your product).&lt;span style="background-color:#ffff00;"&gt; And in most designs it would make sense to set GPIOs to sensible values etc (for instance so that you don&amp;#39;t drain the battery further by having a LED active or similar).&lt;/span&gt;&lt;/span&gt;]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please let me know how to set the GPIOs to sensible values before entering into sleep mode. So that LED should stop blinking and it will not drain the battery.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naveed&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure the interrupt handler for the POF.  POFWARN example code.</title><link>https://devzone.nordicsemi.com/thread/478679?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 08:46:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2277c486-07b7-4e17-bcbc-2672577044e5</guid><dc:creator>Naveed</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for your reply. It was very helpful, and it worked for me.&lt;/p&gt;
&lt;p&gt;I want to put my device into sleep mode. when the event&amp;nbsp;NRF_EVT_POWER_FAILURE_WARNING hits. I am calling&amp;nbsp;&lt;em&gt;&lt;strong&gt;sd_power_system_off() &lt;/strong&gt;&lt;/em&gt;function to put the device in the sleep mode.&lt;/p&gt;
&lt;p&gt;when the device enters into sleep mode, I can see the blue and red led are continuously blinking non-stop. In the code I have configured the LED&amp;#39;s using&amp;nbsp;&lt;strong&gt;LEDS_CONFIGURE(LEDS_MASK).&amp;nbsp;&lt;/strong&gt;But as expected when the device enters in the sleep mode it should stop executing.&amp;nbsp;Do I need to disable all the device configuration (gpio&amp;#39;s, LEDs, and timers, etc) before calling&lt;strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;sd_power_system_off()?&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When I am testing the code in the debug mode it is working fine. But when I have flashed the code into the board, I can see the Leds blinking continuously.&lt;/p&gt;
&lt;p&gt;Please let me know how to resolve this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;Thanks&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure the interrupt handler for the POF.  POFWARN example code.</title><link>https://devzone.nordicsemi.com/thread/477723?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2024 08:06:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0438c689-19ca-44fd-81cd-2003672e088f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]&lt;p&gt;1. I have also referred the ticket:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/2218/pofwarn-example"&gt;(2) POFWARN Example ? - Nordic Q&amp;amp;A - Nordic DevZone - Nordic DevZone (nordicsemi.com)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But I am getting error for the function&amp;nbsp;softdevice_sys_evt_handler_set(sys_evt_dispatch) What are the header files need to be included to resolve this error.&lt;/p&gt;[/quote]
&lt;p&gt;That post is very old and several tings has changed since then. To get SOC events in recent SDK versions you use&amp;nbsp;NRF_SDH_SOC_OBSERVER (in the same way as&amp;nbsp;NRF_SDH_BLE_OBSERVER si used to register a handler for BLE events). You can serach for&amp;nbsp;NRF_SDH_SOC_OBSERVER in the SDK to see examples of how it is used. (I see from your second post that you found that).&lt;/p&gt;
[quote user=""]&lt;p&gt;2. Can we also use this function to enable the POF? nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V24)&lt;/p&gt;
&lt;p&gt;How to configure the handler for the POFWARN event?&lt;/p&gt;[/quote]
&lt;p&gt;Yes, with this functino you can enable (or disable) POF and set the threshold, as both of these are configurd in the POFCON register that this function assesses. Note that this function can only be used without a SoftDevice (see later in this reply for details).&lt;/p&gt;
[quote user=""]&lt;p&gt;3. When the &lt;span&gt;POFWARN&amp;nbsp;&lt;/span&gt;event is generated, I want to put my device into deep sleep mode. Do I need to directly call the function sd_power_system_off() when the event hits?&lt;/p&gt;
&lt;p&gt;or Do I need to disable all the device configuration before calling&amp;nbsp;&lt;span&gt;sd_power_system_off()?&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;POFWARN will just trigger an event (and block any writes to flash). If you want to enter system OFF mode, you need to do that yourself by calling&amp;nbsp;sd_power_system_off(). Wakeup from system-off would be in form of a reset, but you should make sure that the system is in a safe state before entering system off mode (depending on your product). And in most designs it would make sense to set GPIOs to sensible values etc (for instance so that you don&amp;#39;t drain the battery further by having a LED active or similar).&lt;/p&gt;
[quote user="Naveed"]To add-on to the issue, I am getting &lt;em&gt;&lt;strong&gt;SOFTDEVICE: INVALID MEMORY ACCESS error &lt;/strong&gt;&lt;/em&gt;while&amp;nbsp;running the code. Please let me know what I have missed in the configuration of POF. Is my configuration correct?[/quote]
&lt;p&gt;The power registers are not directly accessible when a SoftDevice is enabled, and that is why you get the invalid memory access error (see &lt;a href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/sd_resource_reqs/hw_block_interrupt_vector.html"&gt;Hardware peripherals&lt;/a&gt;). When using a SoftDevice (after it has been enabled), you must use the&amp;nbsp;sd_power_pof* functions.&lt;/p&gt;
[quote user="Naveed"]What should be the priority set to the POF handler in the function,&lt;strong&gt;&amp;nbsp;NRF_SDH_SOC_OBSERVER(m_soc_observer,0, pof_evt_dispatch,NULL)..? &lt;/strong&gt;I have set it to &amp;#39;0&amp;#39; do I need to change it?[/quote]
&lt;p&gt;This is not interrupt priority, just the priority/order of the SoC handler subsribers. So it probably does not matter, but if it does, it depends on which handler you want to run first (in case you have multiple). The lowst number (0) is the highest priority.&lt;/p&gt;
[quote user="Naveed"]I want to put the device into deep sleep mode when the voltage falls below the 2.3V(changed from 2.4V). Is my code correct?&amp;nbsp;[/quote]
&lt;p&gt;The problem is that you need to switch to SoftDevice APIs, and as long as you do that, I expect it should work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure the interrupt handler for the POF.  POFWARN example code.</title><link>https://devzone.nordicsemi.com/thread/477445?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2024 05:50:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2beaafd-5b7f-4937-a694-c23277c7dfc7</guid><dc:creator>Naveed</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I have configured the power fail comparator as shared below.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1712554751991v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;To add-on to the issue, I am getting &lt;em&gt;&lt;strong&gt;SOFTDEVICE: INVALID MEMORY ACCESS error &lt;/strong&gt;&lt;/em&gt;while&amp;nbsp;running the code. Please let me know what I have missed in the configuration of POF. Is my configuration correct?&lt;/p&gt;
&lt;p&gt;When the code runs to the function&amp;nbsp;&amp;nbsp;&lt;strong&gt;nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V23), I am getting&amp;nbsp;&lt;em&gt;SOFTDEVICE: INVALID MEMORY ACCESS error.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What should be the priority set to the POF handler in the function,&lt;strong&gt;&amp;nbsp;NRF_SDH_SOC_OBSERVER(m_soc_observer,0, pof_evt_dispatch,NULL)..? &lt;/strong&gt;I have set it to &amp;#39;0&amp;#39; do I need to change it?&lt;/p&gt;
&lt;p&gt;I want to put the device into deep sleep mode when the voltage falls below the 2.3V(changed from 2.4V). Is my code correct?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please let me know how to resolve this.&lt;strong&gt;&lt;em&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Details:&lt;/p&gt;
&lt;p&gt;Hardware board: nRF52832&lt;/p&gt;
&lt;p&gt;SDK:&amp;nbsp;nRF5_SDK_15.3.0_59ac345&lt;/p&gt;
&lt;p&gt;IDE: Segger Embedded Studio&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Naveed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>