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

ble_proximity app and gpiote interrupt code to wake from and send microcontroller to system_off, not working harmoniously

Hi,

I am trying to merge working code that places the microcontroller in system_off when a switch connected to pin 16 is opened. It then wakes up the micro controller when switch is closed. The same pin is used to achieve this using GPIOTE. The challenge occurs when I merge this with the  ble_proximity app.  I can never get the chip to go to sleep when I remove the physical ground connector on PIN 16 and open the switch. However it worked perfectly when not merged with ble_proximity 

I am effectively using method two neatly described here

https://devzone.nordicsemi.com/f/nordic-q-a/19536/how-to-read-status-of-gpio-pin-12-whether-it-is-high-or-low

I have found some useful information in the discussion below.

https://devzone.nordicsemi.com/f/nordic-q-a/37328/gpio-interrupt-with-ble-peripheral-code

It reveals that the conflict in the 

Fullscreen
1
buttons_leds_init(&erase_bonds);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


function needs to be dealt with which I believe I have done.

So changes I have made are to file pca10040.h
//#define BUTTONS_NUMBER 4 - change to 3 
#define BUTTONS_NUMBER 3

so only the first three buttons are initialised effectively liberating pin 16

My code is as per below and there must be something incorrect with the configuration of pin 16 as the in_pin_handler is never called.

#define SWITCH_PIN   BUTTON_4
#define PIN_OUT      LED_4
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* @brief Interrupt handler for wakeup pin
*/
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
ret_code_t err_code;
NRF_LOG_INFO("ON WAKEUP SWITCH PIN state is: %d..", nrf_gpio_pin_read(pin));
if (pin == SWITCH_PIN)
{
//Turn off LED to indicate the nRF5x is in System-off mode
NRF_LOG_INFO("Turn off LED to indicate the nRF5x is in System-off mode");
nrf_drv_gpiote_out_set(PIN_OUT);
//Disable power-down button to prevent System-off wakeup
NRF_LOG_INFO("Disable power-down button to prevent System-off wakeup");
nrf_drv_gpiote_in_uninit(SWITCH_PIN);
nrf_drv_gpiote_in_event_disable(SWITCH_PIN);
//Configure wake-up button
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Any help greatly appreciated as to where I am getting this wrong.

Best,
DW