Hello community
I want to advertise when physical pin 0.24 is high, and stop advertising when pin 0.24 is low. For this, I based my code on the Beacon Transmitter Sample Application and looking at the Pin Change Interrupt Example.
Right now, I am trying to solve this using 2 interrupts. When pin 0.24 goes from low to high --> start transmission. When pin 0.24 goes from high to low --> stop transmission. But for some reason this code is not working as I expect it to work. When I run my code, the LED on my device is just blinking rapidly, which means that an interrupt is constantly happening I think (even though pin 0.24 remains untouched).
The most important lines of my code: (Here I configure and define my 2 handlers)
#define PIN_IN NRF_GPIO_PIN_MAP(0,24)
// BUTTON handler 1 to start advertising
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
ret_code_t err_code;
if(!is_advertising){
err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("Starting advertising");
is_advertising = true;
nrf_drv_gpiote_out_set(PIN_OUT); // LED blink
} else{
NRF_LOG_INFO("Already advertising");
}
}
// BUTTON handler 2 to stop advertising
void in_pin_handler2(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
ret_code_t err_code;
if(is_advertising){
err_code = sd_ble_gap_adv_stop(m_adv_handle);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("Stopping advertising");
is_advertising = false;
nrf_drv_gpiote_out_clear(PIN_OUT); //LED blink
}else{
NRF_LOG_INFO("Is not advertising");
}
}
static void gpio_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
APP_ERROR_CHECK(err_code);
//handler 1 (to start advertising)
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(PIN_IN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);
//handler 2 (to stop advertising)
nrf_drv_gpiote_in_config_t in_config2 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config2, in_pin_handler2);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
Does anyone know why this is not working as expected? Is it maybe not allowed to have 2 interrupts on one pin?
Thanks a lot