title: How can I start and stop a timer on STM32?
body: <p>I have a big problem. I don't know how I can stop a timer with a button and restart the timer with another button.</p>
  
  <p>This is the code that I have for it so far:</p>
  
  <hr>
  
  <p>This code is the interrupt handler for the button that starts the timer. I thought that it is possible by enabling the timer, that works so far.</p>
  
  <pre><code>void EXTI0_1_IRQHandler(void)
  {
      if ((EXTI-&gt;PR &amp; EXTI_PR_PR1) == EXTI_PR_PR1)  /* Check line 1 has triggered the IT */
      {
          EXTI-&gt;PR = EXTI_PR_PR1; /* Clear the pending bit */
          NVIC_EnableIRQ(TIM7_IRQn);
  
      }
  }
  </code></pre>
  
  <hr>
  
  <p>This code is the interrupt handler for the button that stops the timer. This piece of code doesn't work, and the timer stays on.</p>
  
  <pre><code>void EXTI4_15_IRQHandler(void)
  {
      if ((EXTI-&gt;PR &amp; EXTI_PR_PR4) == EXTI_PR_PR4)  /* Check line 1 has triggered the IT */
      {
          EXTI-&gt;PR = EXTI_PR_PR4; /* Clear the pending bit */
          NVIC_DisableIRQ(TIM7_IRQn);
      }
  }
  </code></pre>
  
  <p>Does anyone have some tips or know how it must be?</p>