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

nRF51822 s130 sd, external interrupt on cscs example

Hello, i am using SDK12.2.0 and SD s130 on a nRF51822 (AC) and i am trying to add an external interrupt on a pin in the cscs ble_peripheral example. The code i am using (and added to example) is this:

#include "app_gpiote.h"
#include "nrf_drv_gpiote.h"
#define SENSORPIN 17
uint32_t pulseCounter = 0;

static void in_pin_handler(void){
pulseCounter++;
}  

static void gpio_init(void){
ret_code_t err_code;

err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
in_config.pull = NRF_GPIO_PIN_PULLUP;

err_code = nrf_drv_gpiote_in_init(SENSORPIN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_event_enable(SENSORPIN, true);}

Then in the begining of main() i have added this to watch for any resets and initialize the interrupt:

 SEGGER_RTT_WriteString(0, "Entering main\r\n"); 
 gpio_init();

As soon as gpio_init() is called the MCU resets (Multiple "Entering main" messages). As you can see the interrupt handler is extremely short, so what am i doing wrong here? I'm trying to solve this on my own for quite some time now.

Thanks

  • Hi, It could be that one of the functions in gpio_init() returns an error and sends your code into an error handler function that resets your device. Have you tried debugging like this?

    My bet is that you are using the BSP support package with app_button. That library uses GPIOTE as well and initializes the GPIOTE driver before you call gpio_init(). Since you are only allowed to initialize the GPIOTE driver with nrf_drv_gpiote_init() once, it returns an error sending your application into an endless circle of resets.

Related