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

Problem in starting advertisement in gpiote interrupt

Hi,
I'm trying to start advertising in gpiote interrupt. I have modified ble_hrs_demo code. I'm suing nrf51-dk with SDK9 and S110. Here are my code snippets(they are not in order here):

static void gpiote_init()
{
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_HITOLO(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(CLK_PIN, &in_config, clk_pin_handler);
APP_ERROR_CHECK(err_code);
}

static void timers_init(void)
{
uint32_t err_code;

// Initialize timer module.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

// Create timers.
err_code = app_timer_create(&m_tpms_timer_id,
                            APP_TIMER_MODE_SINGLE_SHOT,
                            sensor_meas_timeout_handler);
APP_ERROR_CHECK(err_code);

 }

static void application_timers_start(void)
{
uint32_t err_code;

// Start application timers.
err_code = app_timer_start(m_tpms_timer_id, SENSOR_MEAS_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);

}

static void sensor_meas_timeout_handler(void *p_context)
{
nrf_gpio_pin_toggle(BSP_LED_1);
UNUSED_PARAMETER(p_context);
nrf_drv_gpiote_in_event_enable(CLK_PIN, true);
nrf_gpio_pin_clear(SENSOR_WAKE);
nrf_delay_ms(1);
nrf_gpio_pin_set(SENSOR_WAKE);
}

static void clk_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_gpio_pin_toggle(BSP_LED_0);
data |= nrf_gpio_pin_read(DATA_PIN) << (7-count++);
if(count == 8)
{
	data_array[data_count++] = data;
	data = 0x00;
	count = 0;
	if(data_count == DATA_LENGTH+2)
	{
		data_count = 2;
//			nrf_drv_gpiote_in_event_disable(CLK_PIN);
		data_array[0] = DATA_LENGTH;
		data_array[1] = 0x16;
		uint32_t err_code;
		err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
		APP_ERROR_CHECK(err_code);
		
		err_code = sd_ble_gap_adv_data_set(NULL, 0, data_array, sizeof(data_array));
		APP_ERROR_CHECK(err_code);
		application_timers_start();
	}
}
}

The code works fine till I start advertising. I am using the default advertising_init() function from ble_hrs_demo. While debugging, the program ends at Hardfault Handler through function sd_ble_gap_start at line 344 in ble_advertising.c. What could be the reason? Also I want to disable the gpiote on the pin in the interrupt itself, is it possible?
Thanks in advance for help :)

Parents
  • It looks like the problem is with gpiote interrupt. If I try to call any external function, the program either restarts or goes into hardfault handler. I've tried disabling gpiote, starting timer, stopping timer. All the codes resulted in the reset of device. Whereas if i change a flag in interrupt handler and read the flag in main loop, and do the changes there, the code works fine.

Reply
  • It looks like the problem is with gpiote interrupt. If I try to call any external function, the program either restarts or goes into hardfault handler. I've tried disabling gpiote, starting timer, stopping timer. All the codes resulted in the reset of device. Whereas if i change a flag in interrupt handler and read the flag in main loop, and do the changes there, the code works fine.

Children
No Data
Related