简体   繁体   中英

need to use delay in a interrupt function using an STM32F4

so i'm using an STM32F4 based bare bone board (Black Pill) to run a program for my project im using the STM32CubeIDE for code generating

Current Overtime cases explanatory

the figure you just saw, is a graph i made simply on paint to explain the post my project revolve around inductance load protection against short circuits, (doesn't matter but just clarification) im using interrupts, where the first interrupt triggers once the current reaches a reference 1 value second interrupt triggers once the if reaches Value Reference 1 since current noises can't be filtered in my case, I have to avoid the triggering of instruction of int 2 there for I put a delay that is a bit bigger then the noise period (about 100ns) if delay ended and int trigger is still on (high) , shut down the system (change the output) if delay ended and int trigger is off (low), keep the system running (keep initial output)

this is the code i came up with so far

enter code here

I believe what you're looking for is a "Timer" and some interrupt handling magic. I will expand a little.

If your interrupt is OFF (in NVIC only, the rest is configured), but an interrupt triggering event occurred, the interrupt will NOT fire (obviously). But if you enable the interrupt in NVIC after that, it will fire immediately.

Example:

  1. You set up a GPIO as input, you setup EXTI (external interrupt) and SYSCFG (binding port to EXTI), basically, you make a rising edge interrupt
  2. In NVIC the corresponding interrupt is OFF
  3. Rising edge happens on GPIO, immediately goes back down to LOW
  4. You enable an interrupt in NVIC
  5. Interrupt fires (even if the input never had a rising edge after NVIC interrupt was turned on)

My idea is the following.

In the interrupt 1 handler, you do 2 things.

  1. Disable interrupt 2 in NVIC
  2. Launch a delay via Timer with interrupt.

When interrupt 1 fires, it immediately disables interrupt 2 and enables timer. The timer eventually fires its own interrupt, where it enables interrupt 2 in NVIC. If interrupt 2 event happened, the interrupt 2 handler will be called immediately. If not, interrupt 2 will not fire.

During all this waiting your MCU is free to do whatever it wants, full interrupt implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM