Programing/ Nordic(BLE)
pin change interrupt
흰군
2015. 5. 25. 19:44
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include "nrf.h" #include "boards.h" #define LED 22 #define BUTTON 16 void GPIOTE_IRQHandler(void) { // Event causing the interrupt must be cleared. if ((NRF_GPIOTE->EVENTS_IN[0] == 1) && (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk)) { NRF_GPIOTE->EVENTS_IN[0] = 0; nrf_gpio_pin_toggle(LED); } } static void gpio_init(void) { nrf_gpio_cfg_output(LED); nrf_gpio_cfg_input(BUTTON, NRF_GPIO_PIN_PULLUP); nrf_gpio_pin_clear(LED); // Enable interrupt: NVIC_EnableIRQ(GPIOTE_IRQn); NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos) | (BUTTON << GPIOTE_CONFIG_PSEL_Pos) | (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos); NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos; } int main(void) { gpio_init(); while (true) { // Do nothing. } } | cs |