Skip to main content
fshah48
Associate II
March 23, 2017
Solved

TIM2 interrupt behaviour

  • March 23, 2017
  • 2 replies
  • 1535 views
Posted on March 23, 2017 at 13:47

I am using TIM2.CH2 input compare. No other interrupts are activated except TIM2.CH2. In TIM2_IRQ handler all IC bits except CH2 are set. Why?

Using STM32Discovery on IAR. I expect TIM2_IRQ to fire up on trigger from outside. It does but CH2 interrupt ic leared and all other 3 IC interrupt bits are SET. Why?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on March 23, 2017 at 14:15

    The register is just a latch of occurring events, it is gated with the Interrupt Enable to create physical interrupts, but you don't need to enable them for the latch to function.

    2 replies

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    March 23, 2017
    Posted on March 23, 2017 at 14:15

    The register is just a latch of occurring events, it is gated with the Interrupt Enable to create physical interrupts, but you don't need to enable them for the latch to function.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    waclawek.jan
    Super User
    March 23, 2017
    Posted on March 23, 2017 at 14:17

    Similar

    https://community.st.com/0D50X00009Xkg8cSAB

    fshah48
    fshah48Author
    Associate II
    March 24, 2017
    Posted on March 24, 2017 at 12:48

    Well, I need to get interrupt to react. I also tried following:

    TIM_GenerateEvent(TIM2, TIM_EventSource_CC2); from SysTick interrupt

    handler to generate TIM2.CH2 IC interrupt. TIM2 interrupt responds but

    CC2IF is cleared in TIM2-SR. All other capture bits are set.

    Another surprise is that TIM2.PSC is set to 0 when I expressly set it to 3.

    /* Time base configuration */

    TIM_TimeBaseStructure.TIM_Period = 0xFFFF;

    TIM_TimeBaseStructure.TIM_Prescaler = 3; // divide by 4

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

    All these code snippets are imported from examples you provide.

    Please help.

    On Thu, Mar 23, 2017 at 6:17 PM, waclawek.jan <

    Tesla DeLorean
    Guru
    March 24, 2017
    Posted on March 24, 2017 at 14:22

    Code shows you configuring TIM4 not TIM2

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); // Not TIM2

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