Weird thing is going on here.
I have LPC1788 board and I just started writing a simple application. If I initialize timer like this, code seems to be executed, but of course my timer interrupt is not called.
void initTimer (void) { LPC_TIM_TypeDef *timer = LPC_TIM1; LPC_SC->PCONP |= (0x1<<2); timer->TC = 0x00; //Clear Timer Counter timer->PR = 0x00; //No prescaler timer->MCR = 0x3; //enable interrupt timer->MR0 = 0x02710; //interrupt every 1ms //NVIC_EnableIRQ(TIMER1_IRQn); timer->TCR = 0x02; //reset timer timer->TCR = 0x01; //enable timer counter } void TIMER1_IRQHandler(void) { LPC_TIM1->IR = (1u<<0); // Reset the MR0 Interrupt; Writing a zero has no effect. decrementFlags(); }
As soon as I enable NVIC IRQ, my code crash and points to Default_Handler PROC in startup.s. Deducing R15(PC) with -8 and use U 0xXXX, I end up in SVC_Handler part. My Timer1_IRQ never got called.
There is really nothing going on in the code besides this. As I just started writing program and hit the wall...
Any idea what else could I try, to debug this ?
Thanks.
Well, I thought that interrupt will not actually execute before the timer been started, and that happens after setting the NVIC.
timer->MCR = 0x3; //enable interrupt NVIC_EnableIRQ(TIMER1_IRQn); //enable handler timer->TCR = 0x01; //enable timer counter
The timer does not care about what you do with the NVIC. It's the reverse - you need to make sure the NVIC is ready when the timer needs it.
The timer starts when you order it to start. So the timer starts when you make your assign to T0TCR.
But I don't think the timer needs to start. When you write T0MCR = 3, you explicitly enable match control register 0. And with T0TC = 0 and T0MR0 = 0 - why shouldn't the hardware comparator then instantly see a match without waiting for you to turn on the counter with the final T0TCR assign?
If out with a gun, it's best to aim first and then fire. When initializing processor hardware, it's best to do all preparations before you start to activate any enable bits. Never arm a mouse trap with your fingers still in the trap :)