/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. *
- The information contained herein is property of Nordic Semiconductor ASA.
- Terms and conditions of usage are described in detail in NORDIC
- SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- Licensees are granted free, non-transferable use of the information. NO
- WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- the file.
*/
/** @file
- @defgroup pin_change_int_example_main main.c
- @{
- @ingroup pin_change_int_example
- @brief Pin Change Interrupt Example Application main file.
- This file contains the source code for a sample application using interrupts triggered by GPIO pins.
- @image html example_board_setup_a.jpg "Use board setup A for this example." */
#include <stdbool.h> #include "nrf.h" #include "nrf_gpio.h"
/**
-
@brief Function for configuring: pin 0 for input, pin 8 for output,
-
and configures GPIOTE to give an interrupt on pin change. */ static void gpio_init(void) { nrf_gpio_cfg_input(3, GPIO_PIN_CNF_PULL_Pullup); nrf_gpio_cfg_output(0); nrf_gpio_cfg_output(1);
nrf_gpio_pin_write(0, 0); nrf_gpio_pin_write(1, 0); // Enable interrupt: NVIC_EnableIRQ(GPIOTE_IRQn); NRF_GPIOTE->CONFIG[1] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos) | (3 << GPIOTE_CONFIG_PSEL_Pos)
| (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos); NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos; }
/** @brief Function for handling the GPIOTE interrupt which is triggered on pin 0 change. */ void GPIOTE_IRQHandler(void) { // Event causing the interrupt must be cleared. if ((NRF_GPIOTE->EVENTS_IN[1] == 1) && (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk)) { NRF_GPIOTE->EVENTS_IN[1] = 0; } nrf_gpio_pin_toggle(0); nrf_gpio_pin_toggle(1); }
/**
- @brief Function for application main entry. */ int main(void) { gpio_init(); while (true) { // Do nothing. } }
/** @} */