2009-04-02 10:07 PM
Interrupt on a falling edge.
2011-05-17 04:07 AM
One of my GPIO's is an active high from a CPLD. It goes low when an event occurs from the CPLD. I want to be able to perform an operation every time this GPIO pin is pulled low. What peripheral would be the best to use in this scenario? I have tried TIM, PWM input mode and EXTI interrupt and I really haven't been able to get them to check for a falling edge, I never get out of the ISR for some reason.
All I am trying to do is get an interrupt whenever a GPIO pin (configured for input) goes low. It's that straight forward and I am not sure what's messing it up. Any other suggestions are most welcome. Thanks!2011-05-17 04:07 AM
Hi siddj;
As I understood, the CPLD interrupts STM32 by a falling edge. In EXTI configuration and if the CPLD forces always the STM32 GPIO during the interrupt, you'll never get out from ISR since the EXTI is an edge-senstive-interrupt and not a level-sensitive-interrupt. So if I'm right, you have to ensure that your CPLD generates a short pulse to generate the event to the STM32 and make sure that you clear the ISR pending bit in the EXTI ISR. B.R. M3allem2011-05-17 04:07 AM
Thank you for your response. I am making sure that the pending bit is cleared. The thing is, when the interrupt is enabled, my program moves on to the ISR even when there is no external interrupt present. This is just when I am configuring my clocks and things like that.
Also here is what I would want to do. My GPIO is pulled low by the CPLD. This is an interrupt from the CPLD which is cleared by me when I get that interrupt. So I am actually pulling the pin back to high in my ISR. SO I should be going to the ISR only when the GPIO is pulled low. I don't know what would be the most suitable peripheral, TIM or EXTI to set up this interrupt?2011-05-17 04:07 AM
Quote:
The thing is, when the interrupt is enabled, my program moves on to the ISR even when there is no external interrupt present. This is just when I am configuring my clocks and things like that. Since your program jumps directly to ISR after enabling the interrupt even if there is no falling edge generated by your CPLD, this implies that the STM32 see a low edge on this GPIO since the start of your program. I suspect that there is no connection between your CPLD and STM32, and the GPIO remains floating that still continiously see a low level in its input and your program will never get out from the ISR. Also add an ISR clearing pending bit at the begenning of your program as following: (example EXTI0) /* Clear EXTI line 0 pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); /* Clear EXTI line 0 global interrupt pending bit */ NVIC_ClearIRQChannelPendingBit( EXTI0_IRQChannel ); Hope that will help! B.R. M3allem2011-05-17 04:07 AM
I appreciate your response, I had given up on using the EXTI and now am trying to get the same thing done with a timer. I am trying to configure it for a PWM input, to see the falling edge. I also need to set up a timer when the falling edge occurs in my isr and stop when the 2nd falling occurs.
SO I am guessing the timer would be the right way to go. I will try with the EXTI, hopefully that does the trick if this doesn't. Its been 2 work days on this!! Thanks again.2011-05-17 04:07 AM
This is what is messing the up the pending bit. I am using line 8 cos the pin i am working with is B8 and i configure that pin in Input analog mode. Now pin A8 is used to output a clock of 8 Mhz/MCO/internal oscillator.
Every time i have the clock outputted on A8 i keep on getting a pending bit even after i clear it it would not go away, it gets set again for some reason. When I remove the code for the clock, the pending bit does clear and it does not get set again. I can easily get out of my ISR and move on to the main program. I am configuring the line 8 EXTI, my clock is also on line 8(A8) and the pin for the interrupt is also on line 8(B8). I am specifying in my code; GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8); So I am not sure why the clock is repeatedly setting the pending bit? Any suggestions would be appreciated!2011-05-17 04:07 AM
Hi siddj,
Could you please share All your configurations (linked to this issue): GPIOs, Interrupts, MCO, as well as your ISR? B.R. M3allem2011-05-17 04:07 AM
Here is my config.
/* Output HSI clock on MCO pin */ RCC_HSICmd(ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCO_HSI); /*EXTI Config */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect Key Button EXTI Line to Key Button GPIO Pin */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8); /*Falling edge detect */ EXTI_InitStructure.EXTI_Line = EXTI_Line8; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* NVIC Config*/ { NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXTI9_5_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line8) != RESET) { /* Clear the EXTI line pending bit */ EXTI_ClearITPendingBit(EXTI_Line8); ITStatus EXTIStatus; EXTIStatus = EXTI_GetITStatus(EXTI_Line8); EXTI_ClearFlag(EXTI_Line8) ; } } I would want to do more things in my IRQ but this is just a model for now which I am trying to get it to work. What I would want to do is send commands to the CPLD in this IRQ function. But first I would want to be able to interrupt my program whenever B8 goes low, which never happens! Thanks for looking in to it hopefully you might have some breakthrough!2011-05-17 04:07 AM
Oh and by the way, I make sure I configure my CPLD in such a way that I pull pin B8 high before I do the EXTI_Config and NVIC_Config! Oh and there is a typo, I do have it set as :
I was just trying different things! EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;