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\$
  • 3
    \$\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

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