Key/Button interrupt stop function after several seconds

5 posts / 0 new
Last post
Ken Chong
Offline
Last seen:2 years 8 months ago
加入:2016-10-15 05:40
Key/Button interrupt stop function after several seconds

Dear Sir,
I have the DA14681 DEV KIT PRO and I try to run demo on it. It's work well, however after i register an interrupt on the K1 pin (port 1 , pin 6) to turn on D2(orange LED, port 1, pin 5) when trigger by below code on demo ble_multi_link / pxp_reporter. it's work normally for around 10~20 seconds, but after that the D12(blue LED) start blinking and stop blinking finally , D2 turn off and the interrupt of K1 will not work anymore. Please suggest what should I do to keep the interrupt working. Thanks.

static void system_init( void *pvParameters )
{ ...
hw_gpio_reserve_and_configure_pin(HW_GPIO_PORT_1, HW_GPIO_PIN_5, HW_GPIO_MODE_OUTPUT,
HW_GPIO_FUNC_GPIO,HW_WKUP_PIN_STATE_LOW);
hw_gpio_reserve_and_configure_pin(HW_GPIO_PORT_1, HW_GPIO_PIN_6, HW_GPIO_MODE_INPUT,
HW_GPIO_FUNC_GPIO,HW_WKUP_PIN_STATE_LOW);

//add interrupt
hw_wkup_init(NULL);
hw_wkup_set_counter_threshold(1);
hw_wkup_register_interrupt(wkup_intr_cb, 1);
hw_wkup_configure_pin(HW_GPIO_PORT_1, HW_GPIO_PIN_6, true, HW_WKUP_PIN_STATE_LOW);
hw_wkup_set_debounce_time(50);
...
}
static int counter=0;
static void wkup_intr_cb(void)
{
/*
* Interrupt handler should always reset interrupt state, otherwise it will be called again.
*/
hw_wkup_reset_interrupt();
printf("Wake up interrupt triggered %d\r\n",counter++);
hw_gpio_set_active(HW_GPIO_PORT_1,HW_GPIO_PIN_5);
}

Keywords:
Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
加入:2015-06-08 11:34
Hi Ken Chong,

Hi Ken Chong,

You are configuring the pins of your device in the system_init() function, that means that when the device falls to sleep and wakes up, your pins are going to be unconfigured so you wont be able to set them active. Put the this statement for both of your pins in the periph_init() function hw_gpio_configure_pin(HW_GPIO_PORT_1, HW_GPIO_PIN_5, HW_GPIO_MODE_OUTPUT,
HW_GPIO_FUNC_GPIO,false); and remove it from the System_init() function.

As far as i call tell from your code the interrupts are still active and occur when you press the button (just pasted your code in the multilink demo), you should be able to see that with the string that you are outputting on the terminal. The reason for the LED not being active when you press the button (if that is what you mean) is because the device falls to sleep (when the blue light starts blinking), so you dont have to chance to see the LED active more than the next sleep occurance (assuming that you ve implemented the above), you will have to use a variable and keep the state of the LED and reconfigure the pins in the periph_init() accoring to this variable.

Thanks MT_dialog

Ken Chong
Offline
Last seen:2 years 8 months ago
加入:2016-10-15 05:40
Dear MT_dialog,

Dear MT_dialog,
Thanks, it's working, by the way , I found that I can only trigger the interrupt after the ble advertising finish. Otherwise it will hang after trigger around 20 times.

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
加入:2015-06-08 11:34
Hi Ken Chong,

Hi Ken Chong,

Thats because you are printing through UART in ISR context, it takes time, so the BLE module isn't able to keep the advertising interval that is set, since it looses wake up interrupts (it wakes up with a delay), so it stucks in the ble_lp_isr() interrupt (there is a condition there that instructs the sw to assert a warning in case that happens in order to inform the user). If you would like to print you should not do that from ISR context but you can have either a different task that is notified when an interrupt occurs or a flag and print from the main task.

Thanks MT_dialog

Ken Chong
Offline
Last seen:2 years 8 months ago
加入:2016-10-15 05:40
Noted with thanks.

Noted with thanks.