# sd_power_system_off() interfere with GPIOTE port interrupts [closed]

I am using NRF52 SDK14.0 and SoftDevice S132 v5.0.0. I am using GPIOTE low level port interrupt to wake the system from SysOff mode. If SoftDevice is enabled and I put the system to SysOff by calling NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter; port interrupt (button press) wakes the system as expected. But if I am trying to use sd_power_system_off() function instead, the system goes to SysOff and is never woken again by the port interrupt. Could something inside sd_power_system_off() interfere with GPIOTE interrupt settings?

edit retag reopen delete

### Closed as "the question is answered, right answer was accepted" by Mindaugas Tinteris at 2017-09-18 08:31:04 +0100

Sort by » oldest newest most voted

By making #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 in FreeRTOSConfig.h now sd_power_system_off() works fine, but I am not sure if it's the right option.

more

Hi,

If you want to use sd_ function calls within the FreeRTOS context, then setting it to 5 is the correct option. See this figure here.

more

Hi,

When in System OFF mode, the device can be woken up through one of the following signals:

1. The DETECT signal, optionally generated by the GPIO peripheral
2. The ANADETECT signal, optionally generated by the LPCOMP module
3. The SENSE signal, optionally generated by the NFC module to “wake-on-field”
4. A reset

GPIOTE will not wake the processor up from SYSTEM OFF, the sense mechanism in the GPIO peripheral will. If you enable the sense mechanism, a DETECT signal will be generated if the correct sense is detected on one of the pins.

Try to configure the pin you want to use to wake the chip up like this:

nrf_gpio_cfg_sense_input(PIN NUMBER, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);


Also note that when the SoftDevice is enabled, the POWER register is restricted, and should not be accessed directly. When the SoftDevice is enabled, you should therefore only use the sd_power_system_off() function to go to sleep.

more

Please, read my post original carefully. I do use Sense functionality, and it is working fine unless I use sd_power_system_off(). I am aware of the issue that I should not access POWER register directly when using SoftDevice, that's why I am asking this question. I use this code to setup a pin:

nrf_drv_gpiote_in_config_t in_config_button = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
in_config_button.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(GPIO_BUTTON_MAIN, &in_config_button, ButtonInterruptHandler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(GPIO_BUTTON_MAIN, true);


I'll repeat myself. The system wakes up if going to SysOff by using POWER reg. This doesn't work only if I use sd_power_system_off().

( 2017-09-14 14:34:29 +0100 )editconvert to answer

I just tested the code you provided, and it worked fine to exit sleep mode with it. The sd_power_system_off() does not interfere with any GPIOTE interrupt settings.

What pin is GPIO_BUTTON_MAIN ? Could you debug/print the GPIO configuration register value of the pin you use, and see if it's correctly configured before you enter system off?

The NRF_P0->PIN_CNF[GPIO_BUTTON_MAIN] should be 0x0003000C if configured correctly.

( 2017-09-14 15:10:34 +0100 )editconvert to answer

GPIO_BUTTON_MAIN is 20. Yes I checked, NRF_P0->PIN_CNF[GPIO_BUTTON_MAIN] is indeed 0x0003000C. I'll add one important thing to the whole story: I call sd_power_system_off() from FreeRTOS idle task hook. Afte looking more carefully I discovered, that system goes to Hard Fault Handler after calling sd_power_system_off() and it seems to me that I can find the answer to this here. Now it's only unclear, how to change IDLE task interrupt priority level in FreeRTOS. Any hints would be appreciated.

( 2017-09-14 15:50:06 +0100 )editconvert to answer

## Recent blog posts

• ### Difference between nRF52840 Engineering A and B reference designs

Posted 2018-01-15 12:27:08 by Martin Børs-Lind
• ### [For Hire] Expert development services of custom Hardware devices | IoT solutions | Mobile Apps

Posted 2018-01-15 09:08:42 by Ilya Surinsky
• ### Rust bindings to nrf52 series

Posted 2018-01-12 23:23:07 by Coleman McFarland
• ### Show And Tell: Poly - Building an RC Airplane The Hard Way

Posted 2018-01-05 01:17:57 by Daniel Veilleux
• ### Bluetooth on a desktop computer (Windows, Mac, Linux)

Posted 2018-01-04 17:56:57 by kbaud

## Recent questions

• ### LPCOMP Interrupt Resets MCU (nRF51-DK)

Posted 2018-01-20 15:32:47 by Anthony
• ### ttl converter + NRF52832-QFAA-R7 (QFN48)

Posted 2018-01-20 11:03:39 by Vitaly

Posted 2018-01-20 09:30:15 by kont40