This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use the PORT event

HI ,all ! I have a question about PORT event function.

as the 4 channels of GPIOTE (channel0 to channel3 ) have been used for other usage.

i need to use a general IO to detect the falling edge signal, the signal is a 50Hz square wave.

How should i do ~~

  • You configure the pin for sensing, e.g. with

    nrf_gpio_cfg_sense_input(BUTTON_0, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);	
    

    The GPIO has an internal DETECT signal, one for all pins, which is set whenever the SENSE condition for at least one pin is true (here: if the pin BUTTON_0 is low). A change of the DETECT signal from low to high (i.e., from being cleared to being set) will trigger the PORT event in the GPIOTE, which can be be used as any other event (e.g. for triggering an GPIOTE IRQ etc.). The good thing about the SENSE/PORT mechanism is that this does not use up extra current (as the other GPIOTE tasks normally do). Plus, the SENSE/DETECT signal can wake the system from a SYSTEM OFF state.

  • Quax64, thank you very much for your reply

    I use the function you suggested " nrf_gpio_cfg_sense_input ", but the GPIO PORT event function still can't work normally, The program code is as follows:

    void ApplyIO_Init(){
    nrf_gpio_cfg_sense_input(PIN_ZERO_INT, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(PIN_SPEED,    NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Enabled << GPIOTE_INTENSET_PORT_Pos;
    
    //---------------------------------------------------------------------------------
    nrf_gpio_cfg_output(PIN_FAN);
    nrf_gpio_cfg_output(PIN_ION);
    nrf_gpio_cfg_output(PIN_BUZ);
    
    nrf_gpio_cfg_output(PIN_NTC_EN);
    nrf_gpio_cfg_output(PIN_LED1);
    nrf_gpio_cfg_output(PIN_LED2);
    nrf_gpio_cfg_output(PIN_LED3);
    
    //---------------------------------------------------------------------------------
    nrf_gpio_cfg_input(KEYB_D, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_input(PIN_NTC_AD, NRF_GPIO_PIN_NOPULL);
    

    }

    void GPIOTE_IRQHandler(void){
    u32 pin;
    if(NRF_GPIOTE->EVENTS_PORT){
    	NRF_GPIOTE->EVENTS_PORT = 0;
    	//---------------------------------
    //	pin = nrf_gpio_pin_read(PIN_SPEED);
    	PortISR();
    }
    

    }

    However, when 50Hz square-wave signal to the actual IO (name is "SPEED") , GPIOTE PORT event is not trigger

    Where is the problem?

  • Did you enable the interrupt in main()?

    NVIC_EnableIRQ(GPIOTE_IRQn);
    
  • There is an example for this in: /opt/nordic/nrf51822/Board/nrf6310/pin_change_int_example/main.c

  • the example is base on "GPIOTE->GONFIG", but in this project the 4 channel have all used for other usage

Related