I want to run CTimer 2- for example in the match mode. And can't get interrupts when matched.
static ctimer_callback_t ctimer_callback[] = {timer3_interrupt_handler};
void timer3_interrupt_handler(uint32_t flags)
{
static int tst_cnt = 0;
tst_cnt++;
Logger::instance().log("timer3_interrupt_handler %d \r\n", tst_cnt);
}
void init_timer ()
{
CLOCK_AttachClk(kMAIN_CLK_to_CTIMER2);
// Initialize CTIMER2 with the default configuration
ctimer_config_t config;
CTIMER_GetDefaultConfig(&config);
CTIMER_Init(CTIMER2, &config);
// Initialize match config
ctimer_match_config_t matchConfig;
matchConfig.enableCounterReset = true; // Match will reset the counter
matchConfig.enableCounterStop = true; // Match will stop the counter
matchConfig.matchValue = 10 * CLOCK_GetCtimerClkFreq(2);
matchConfig.outControl = kCTIMER_Output_NoAction; // No action is taken upon match
matchConfig.outPinInitState = true; // Initial value of the output
matchConfig.enableInterrupt = true; // Generate interrupt upon match
CTIMER_RegisterCallBack(CTIMER2, &ctimer_callback[0], kCTIMER_SingleCallback);
// Setup the CTIMER to generate an interrupt upon match
CTIMER_SetupMatch(CTIMER2, kCTIMER_Match_2, &matchConfig);
// Start CTIMER3
CTIMER_StartTimer(CTIMER2);
}
And it doesn't call interrupt handler. May be first we should enable global interrupts? Or something else?
Hi!
This example doesn't work. I tested it. And I wrote message due to it doesn't work. Check it on your side on the F1 CPU.
Hi,
The MCUXpresso SDK provided [ctimer_match_interrupt_example] with below ctimer callback table:
/* Array of function pointers for callback for each channel */
ctimer_callback_t ctimer_callback_table[] = {
ctimer_match0_callback, ctimer_match1_callback, NULL, NULL, NULL, NULL, NULL, NULL};
Please refer above code to place ctimer2 callback function at correct position.
More detailed info, please refer MCUXpresso SDK ctimer match interrupt example.
Wish it helps.
Mike