#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#define LED 17
#define Btn 13
void input_pin_handle(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_gpio_pin_toggle(LED);
}
void gpio_init()
{
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(LED); // Initialize the led
nrf_gpio_pin_set(LED); // turn off led
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true); //Falling edge interrpt detection
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(Btn, &in_config, input_pin_handle); // initialize the interrput pin
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(Btn,true); // Enable the interrput events
}
int main(void)
{
gpio_init();
while (true)
{
// Do nothing.
}
}
01-25
858
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-01