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

GPIOTE Interrupt

I'm learning about GPIOTE and PPI and looking at an example I come to the following code but now it act incorrectly. So as you can see I'm enabling the interrupt for GPIOTE channel 0:

NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Msk;

But when the IRQHandler is called this is what I get: image description

I expected CC[1] to be 0 but instead it is the value when the signal go HITOLOW!

Here is the signal I'm capturing: image description

CC[0] is cursor #3 (LOWTOHIGH) and CC[1] is cursor #4 (HIGHTOLOW). Timer starts to count at #2!

void GPIOTE_IRQHandler(void)
{
    
		curr_cc1 = NRF_TIMER1->CC[1];	
		curr_cc0 = NRF_TIMER1->CC[0];  

    // Clear the event causing the interrupt.
    NRF_GPIOTE->EVENTS_IN[0] = 0;  
		NRF_GPIOTE->EVENTS_IN[1] = 0;
	
		NRF_TIMER1->TASKS_STOP = 1;
}

/** @brief Function for initializing the GPIO Tasks/Events peripheral.
*/
static void gpiote_init(void)
{
    NVIC_EnableIRQ(GPIOTE_IRQn);

    nrf_gpio_cfg_sense_input(ECHO, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);

    // Enable interrupt on input 1 event.
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Msk;

    // Configure GPIOTE channel 0 to generate event on input pin low-to-high transition.
    nrf_gpiote_event_config(0, ECHO, NRF_GPIOTE_POLARITY_LOTOHI);
	
		// Configure GPIOTE channel 1 to generate event on input pin high-to-low transition.
    // Note that we can connect multiple GPIOTE events to a single input pin.
    nrf_gpiote_event_config(1, ECHO, NRF_GPIOTE_POLARITY_HITOLO);
	
}

/** @brief Function for initializing the PPI peripheral.
*/
static void ppi_init(void)
{
    // Configure PPI channel 0 to capture Timer 1 value into  the CC[0] register.
    // This is achieved when GPIOTE detects Low-to-High transition on pin INPUT_PIN_NUMBER.
    NRF_PPI->CH[0].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[0];
    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TIMER1->TASKS_CAPTURE[0];

    // Configure PPI channel 1 to capture Timer 1 value into CC[1] register.
    // This is achieved when GPIOTE detects High-to-Low transition on pin INPUT_PIN_NUMBER.
    NRF_PPI->CH[1].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[1];
    NRF_PPI->CH[1].TEP = (uint32_t)&NRF_TIMER1->TASKS_CAPTURE[1];

    // Enable only PPI channels 0 and 1.
    NRF_PPI->CHEN = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos)
                  | (PPI_CHEN_CH1_Enabled << PPI_CHEN_CH1_Pos);
}
Parents
  • I'm trying to capture the signal that you see in channel 2 of logic analyser screenshot. So I set up a gpiote task to lowtohigh event the save the timer1 count on cc[0] and another gpiote task to hightolow event that save the value on cc[1].

    On the gpiote init I enable an interrupt for the lowtohigh event and debugging the code with a breakpoint on the gpioteirqhandler I would expect to got 0 on the cc[1] instead of the hightolow value.

Reply
  • I'm trying to capture the signal that you see in channel 2 of logic analyser screenshot. So I set up a gpiote task to lowtohigh event the save the timer1 count on cc[0] and another gpiote task to hightolow event that save the value on cc[1].

    On the gpiote init I enable an interrupt for the lowtohigh event and debugging the code with a breakpoint on the gpioteirqhandler I would expect to got 0 on the cc[1] instead of the hightolow value.

Children
No Data
Related