hi,
I'm working on the Ble_app_uart example where i need to enable, TWI, PWM, and Ble, as a transceiver. with s12 SD and nrf52832.
Issue
I need to detect the button sequence, for example, single press, double press, long press, etc. I use timer1 and button interrupt function to detect the sequence. but when i enable the flag in the timer_interrupt function the function does not hold for a specific period and enables the flag.
How code works
Press button on devkit- > call interrupt function + enable time -> to jump to while loop without the wait for the timer overflow.
Below the code,
One more thing I use PWM on timer 1 and use TWi as well.
I use this kind of button sequence code on enhance_tx example on timer0 it works great but here it does not stay in timer so that i couldn't count the button press
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
void input_pin_handle(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) /// button handler
{
button_int_flag = 1;
nrfx_timer_clear(&TIMER_LED);
/// start timer and wait for overflow ///
uint32_t time_ms = 1000; //Time(in miliseconds) between consecutive compare events. (change timer as per requirement for button press)
uint32_t time_ticks;
time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
nrf_drv_timer_extended_compare(&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_LED);
button_press_tick++;
}
void gpio_init() //gpios enable
{
ret_code_t err_code; // hold error value
err_code = nrf_drv_gpiote_init(); // Initialize the GPIOTE
APP_ERROR_CHECK(err_code); // check for the errors
nrf_gpio_cfg_output(pin_number_03); // Initialize the Led
nrf_gpio_pin_set(pin_number_03); // turn off the led
nrf_gpio_cfg_output(pin_number_04); // Initialize the Led
nrf_gpio_pin_set(pin_number_04); // turn off the led
nrf_gpio_cfg_output(pin_number_28); // Initialize the Led
nrf_gpio_pin_set(pin_number_28); // turn off the led
nrf_gpio_cfg_output(pin_number_29); // Initialize the Led
nrf_gpio_pin_set(pin_number_29); // turn off the led
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true); // Falling edge interrupt detection
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(pin_number_30, &in_config, input_pin_handle); // Initialize the interrupt pin
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(pin_number_30, true); // Enable the interrupt events
}
//Timer handler
void timer_led_event_handler(nrf_timer_event_t event_type, void *p_context) /// timer handler function
{
timer_flg = 1;
timer_count++;
}
int main() {
gpio_init();
//timer1 configure
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);
while () {
// if else // do something
}
}