cancel
Showing results for 
Search instead for 
Did you mean: 

Edge Triggered Interrupt Functionality on EXTI15_10_IRQ

Rogers.Gary
Senior II
Posted on February 09, 2016 at 23:36

Hello:

What I am trying to do seems pretty straightforward, but the results I am getting don't agree with that.

I have 17.5KHz clock that bursts about 7 times/second. I have the interrupt set for rising edge. When that clock begins to toggle, the interrupt handler is picking it up.

On a second pin I have set up as an input, I want to read that pin when the interrupt occurs.

However, the results in the array don't agree with what I am seeing on the scope. The data from the device at Pin14 stays the same (reading an ADC) so I expect each buffer to be the same, but they are not.

Should an interrupt set up this way only occur on the rising clock edge? And what is not valid about reading another pin during that interrupt? That's when the data should be read. If it works the way I understand it, there should be the same values in the buffer with every clock burst of 19.

Thanks for any help on this.

void EXTI15_10_IRQHandler(void)

{

  static uint8_t i;

  

  if (EXTI_GetITStatus(EXTI_Line13) != RESET )

  {

    /* Clear interrupt flag */

    EXTI_ClearITPendingBit(EXTI_Line13);       

    bits[i++] =  GPIO_GetInputPinValue(GPIOB, GPIO_Pin_14) );   

    if(i == 20) //clock finished, process data

  }

}

void Configure_PB13(void)

{

    GPIO_InitTypeDef GPIO_InitStruct;

    EXTI_InitTypeDef EXTI_InitStruct;

    NVIC_InitTypeDef NVIC_InitStruct;

    

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

    

    /* Set pin 13 & 14 as input */

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;

    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

    GPIO_Init(GPIOB, &GPIO_InitStruct);

    

    /* using pin 13 */

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource13);

    

    /* PB13 connected to EXTI_Line13 */

    EXTI_InitStruct.EXTI_Line = EXTI_Line13;

    /* Enable interrupt */

    EXTI_InitStruct.EXTI_LineCmd = ENABLE;

    /* Interrupt mode */

    EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;

    /* Trigger on rising edge */

    EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;

    /* Add to EXTI */

    EXTI_Init(&EXTI_InitStruct);

 

    /* Set IRQ vector to NVIC */

    /* PB13 is connected to EXTI_Line13, using EXTI15_10_IRQn vector */

    NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;

    /* Set priority */

    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;

    /* Set sub priority */

    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x01;

    /* Enable interrupt */

    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;

    /* Add to NVIC */

    NVIC_Init(&NVIC_InitStruct);

}

#stm32 #exti
4 REPLIES 4
Posted on February 09, 2016 at 23:50

I'd probably make sure to initialize the static, and perhaps have it as a global I could reset.

Suggest you reflect the state of the pin as read on another GPIO, or toggle a pin, and scope that it is reading when you expect, give-or-take a bit of latency on the IRQ
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rogers.Gary
Senior II
Posted on February 10, 2016 at 01:27

Attached is a scope shot of the signals. The top is the clock signal I am using as an interrupt signal on the positive edge, and the bottom trace is the pin that I read on every interrupt. The clock is running at 5KHz.

As you suggested, I toggled Led6 on the discover board with each pass in the interrupt handler, and for reasons unknown, it is toggling very slow, about 500ms.

Why would this be? Confusing...or what....

clive1,

In the comment that says //process data, I have more code there that resets i to 0. I did set it to 0 anyway and there's no difference.

Could you please let me know - with my code as it is, should the read of pin 14 be valid on the interrupt?

Should the interrupt occur only on the rising edge of the clock?

Appreciate your help, thanks.

________________

Attachments :

20160209_173257.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I01z&d=%2Fa%2F0X0000000bSQ%2FHPLeoBx4MepoyG31QfjUd4_XcTp5RcrXcyFQbgX1Drw&asPdf=false
mark239955_stm1
Associate II
Posted on February 10, 2016 at 11:15

The following only applies for sure to STM32F4xx parts; it may apply to others as well, but I haven’t used them.

You can use Input Capture on TIM1 or TIM8 (the Advanced Control Timers) to trigger a DMA2 transaction on almost any memory address or internal bus (only ICODE is excluded, afaict).

 

In particular, you can use DMA2 (and only DMA2, DMA1 is far more restricted) to capture a GPIO port.

 

The upsides of this approach versus using an interrupt are lower (if not 0) latency between the clock edge and the read of the GPIO; and lower processor overhead if you can post-process an array of captures rather than processing each capture as it occurs.

Posted on February 10, 2016 at 16:01

You need to scope the LED, the pulse train looks to have an odd number of pulses, not clear on the repetition rate of the pulses, which could explain the LED blinking at a low rate, not sure you're going to be able to discern KHz by eye.

So you're showing me the data read, not the entry to the interrupt, I'm going to assume the interrupt is occurring at the edges like expected. I don't see the signal its supposedly sampling either, but the pulse train looks to be 5V, and floats at 3.3V between.

I'd probably shift the bits into a register as they arrive, rather than index them into an array. Easy task from there to mask the lower 19 bits.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..