This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

why GPIOTE chanel can not change to 1 or 2 、3 in pin_change_int_example?

/* 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. } }

/** @} */

  • If you want to use a different channel, you need to make sure to change all references to the channel number. As your snippet is now, you have apparently correctly configured the GPIOTE peripheral, and changed the event clearing of the IRQ handler, but you haven't actually enabled the interrupt for the other channel or changed the interrupt enable check in the handler. This is done by changing the INTENSET line to this:

    
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN1_Set << GPIOTE_INTENSET_IN1_Pos;
    
    

    instead of IN0, and the check in the IRQ handler to this:

    
        if ((NRF_GPIOTE->EVENTS_IN[1] == 1) && 
            (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN1_Msk))
        {
    
    

    Doing this, things seem to work as expected.

Related