0
\$\begingroup\$

This is my timer 4 init:

void initTimer(){
  CLK_PCKENR1 |= (1<<4); //Enable Clock for Timer 4
  TIM4_EGR |= 1;
  TIM4_PSCR = (0x03);    //Prescaler, Divide Clock by 7
  TIM4_IER = 1;          //Enable Update Interrupt
  TIM4_CR1 |= 1;         //Enable Timer
}

This is my service routine:

#pragma vector = TIM4_OVR_UIF_vector
__interrupt void TIM4_OVF(void){
  if(!didInit){
    initMAX7219();
    didInit = true;
  }
  applyBuffer();
  shuffleRight();
  TIM4_SR &=~(1<<0);    //Clear Update interrupt flag
}

But nothing works, the timer counter register gets incremented properly but the interrupt function is never reached, why?

Happy new year!

\$\endgroup\$
  • \$\begingroup\$ Because of TIM4_PSCR should be power of 2. Should be one of: 1,2,4,...,128 \$\endgroup\$ – name Jan 17 '17 at 14:16
  • 1
    \$\begingroup\$ Did you enable global interrupts (i.e. EA=1) ? \$\endgroup\$ – Rohat Kılıç Jan 17 '17 at 14:21
0
\$\begingroup\$

working code:

void TIM4_init(void){

TIM4_PSCR = 7;
TIM4_ARR = 250;
TIM4_IER |= TIM4_IER_UIE;
TIM4_CR1 |= TIM4_CR1_CEN;
}
void  TIM4_overflow_interupt()  __interrupt (TIM4_UPD_OVF){
static unsigned nu = 0;
static unsigned pi = 0;
if (nu >= 100){
    nu = 0;
    if (pi){
        pi = 0;
        IND_LED_ON();
    }
    else{
        pi = 1;
        IND_LED_OFF();
    }
}

nu++;
TIM4_SR1 &= ~TIM4_SR1_UIF;
//TIM4_IER |= TIM4_IER_UIE;
}
\$\endgroup\$
  • 2
    \$\begingroup\$ Please give some more information on your code example. Just posting a snippet is not an answer. \$\endgroup\$ – Ariser Jan 18 '17 at 10:40

protected by Community Jul 9 '17 at 11:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.