Dear All,
I am experimenting with the nRF52840 DK and the ble_app_template.
Based on that project, I am trying to configure a pin interrupt on Button 1 (pin 0.11).
This is my configuration:
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
NRF_LOG_INFO("Interrupt triggered");
}
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(PIN_IN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
It is mostly inspired by the ...\examples\peripheral\pin_change_int.
In the same code, I reading out also to ADC values from AIN0 and AIN1.
Finally I am also configuring and using a watchdog.
My main looks like this:
int main(void)
{
bool erase_bonds;
// Initialize.
log_init();
timers_init();
power_management_init();
ble_stack_init();
gap_params_init();
gatt_init();
advertising_init();
services_init();
conn_params_init();
peer_manager_init();
gpio_init();
print_reset_reason();
// Start execution.
NRF_LOG_INFO("Template example started.");
application_timers_start();
wdt_init(WATCHDOG_TIMEOUT);
advertising_start(erase_bonds);
saadc_init();
static nrf_saadc_value_t adc_value_0;
static nrf_saadc_value_t adc_value_1;
// Enter main loop.
for (;;)
{
idle_state_handle();
// Sample SAADC on two channels
nrf_drv_saadc_sample_convert(0, &adc_value_0);
nrf_drv_saadc_sample_convert(1, &adc_value_1);
NRF_LOG_INFO("Sample channel 0: %d", ADC_RESULT_IN_MILLI_VOLTS(adc_value_0));
NRF_LOG_INFO("Sample channel 1: %d", ADC_RESULT_IN_MILLI_VOLTS(adc_value_1));
wtd_feed();
nrf_delay_ms(1000);
}
}What I see is that the program will start and it will hang at idle_state_handle. If I do not press the button for more than the watchdog timeout, the device resets due to the watchdog.
If I press the button the interrupt is fired (I see the debug message) as well as a pair of ADC measurements from the 2 channels.
What I understand is that the interrupt that I am configuring is messing with the device going to System On Idle state. What I noticed on the pin_change_int example is that there the while loop does nothing (is empty), but I think that because I need my application to be low power, I need to do something like the idle_state_handle, correct?
Can anyone make some suggestions on how to properly configure my application?