Managed to get a timer-ISR running using timer TC3. The ISR fires at the expected rate.
But if the interrupt is enabled, and I want to upload changed code, it does not work. I have to go via the Bootloader, so I suspect that there are resource conflicts: maybe TC3 or the changed GCLK is also used by hidden parts of the arduino base-sw-packet.
Here the init-funct that configures the timer:
void TIM_TimerInit(void)
{
// Set GCLK0 (48MHz) as clock source for timer TC3
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID_TCC2_TC3;
// Put the timer TC3 into match frequency (MFRQ) mode, divide clock by 1024, reset timer on the next prescaler pulse (not GCLK)
TC3->COUNT16.CTRLA.reg = TC_CTRLA_WAVEGEN_MFRQ | TC_CTRLA_PRESCALER_DIV1024 | TC_CTRLA_PRESCSYNC_PRESC;
// Set TC3 period to 1Hz: 48MHz / (1024 * 3Hz) - 1 = 15624, wait for sync
TC3->COUNT16.CC[0].reg = 15624;
while (TC3->COUNT16.STATUS.bit.SYNCBUSY);
// Enable TC3 overflow interrupts
TC3->COUNT16.INTENSET.reg = TC_INTENSET_OVF;
// Enable TC3, wait for sync
TC3->COUNT16.CTRLA.bit.ENABLE = 1;
while (TC3->COUNT16.STATUS.bit.SYNCBUSY);
// set NVIC priority for TC3 to 0 (highest), connect TC3 to NVIC
NVIC_SetPriority(TC3_IRQn, 0);
NVIC_EnableIRQ(TC3_IRQn);
}
Does anybody know how to find out which on-chip resources can be used without messing up something else?
thanks for your proposal. I think I found the root cause - although I do not understand it completely:
Timer 3 is still in use.
I gave a different name to my ISR (to stick to my personal naming conventions :-): Its name was ISR_TIM_TC3.
At the top of the file I added: #define TC3_Handler ISR_TIM_TC3
After using the original name, and removing the #define, everything works as expected.
Nevertheless thanks a lot for your support !
... and just a minute ago I found that the renaming itself is not the problem, but the #define was the wrong way around. It should be: #define ISR_TIM_TC3 TC3_Handler