Use of interrupt, STM32F407, with PE4, falling edge trigger
I would like to respond to the falling edge of a square wave that is of 50% duty cycle, running at 1us pulses (500kHz). This signal comes from my LA2016 logic analyzer (has PWM outputs) and is fed into PE4 of my STM32 discovery board (STM32F407VG MCU). This signal is also connected to my logic analyzer so that I am able to inspect it. PE4 is configured as an input with no internal pullup set.
I have also placed PE2 under inspection in my logic analyzer. Idea is that every time I sense a falling edge of the 1us pulse, I will quickly toggle PE2 on and off. PE2 is configured as an output with open drain drive, pulled up externally with a 1k resistor.
I did manage to sense a falling edge with polling. Though I have other code I would like to run and decided an interrupt would be the best way!
Spent hours understanding how to do this and i think I got it down (shows in my comments). Though my implementation does not seem to be working properly. I know that my input and output pins work correctly since I was able to use polling so it has to be in my understanding of the interrupt mechanism.
Any hints?
void ConfigureInterrupt()
{
/* Configure dataline2 (PE4) as interrupt */
// Disable the IRQ number, for EXTI4, this is 10 (from vector table)
__disable_irq();
// Note: I used this function here. I could have used the
// NVIC_ICER0 register instead and write a 1 to bit10
// Enable the clock for SYSCFG and EXTI engine
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
// Select PE for EXTI engine
SYSCFG->EXTICR[1] = SYSCFG_EXTICR2_EXTI4_PE;
// Unmask EXTI4 to be used for interrupt mechanism
EXTI->IMR |= EXTI_IMR_IM4;
// Select the external trigger to be of falling edge
EXTI->FTSR |= EXTI_FTSR_TR4;
// Make sure that there is no rising edge trigger
EXTI->RTSR &= ~EXTI_RTSR_TR4;
// Enable the IRQ number, for EXTI4, this is 10 (from vector table)
NVIC_EnableIRQ(EXTI4_IRQn);
}
void PulseSense()
{
// Code before this line configures input and output pins,
// omitted for forum question.
// Setup the input pin interrupt
ConfigureInterrupt();
while(1)
{
// Polling code - disabled for now
// DKO... are macro names for my code
//while(DkoGetDataline2() == LOW);
//while(DkoGetDataline2() == HIGH);
//DKO_DATALINE1_GPIO->ODR |= (1 << DKO_DATALINE1_PIN);
// DKO_DATALINE1_GPIO->ODR &= ~(1 << DKO_DATALINE1_PIN);
}
}
void EXTI4_IRQHandler(void)
{
// Pulse the output quickly
DKO_DATALINE1_GPIO->ODR &= ~(1 << DKO_DATALINE1_PIN);
DKO_DATALINE1_GPIO->ODR |= (1 << DKO_DATALINE1_PIN);
// Clear the EXTI engine Pending Register
EXTI->PR |= EXTI_PR_PR4;
// Note: Even though we write a 1 to this register
// the manual says this is how you go about
// clearing it, which is kinda weird.
}