enable CMP! interrupt on T_3.5

NikoTeen

Well-known member
Hi,
in this forum I found code examples for using the comparator in a Teensy 3.5.
For comparator 1 a code example used
Code:
NVIC_ENABLE_IRQ(IRQ_CMP1); // handler is now cmp1_isr()
The macro name says that it is an enable function. The comment says that with this macro cmp1_isr() is attached to the interrupt.
In kinetis.h I found the definition of NVIC_ENABLE_IRQ but I don't understand what's going on there.

Performs this macro both, enable and attach, or only one of it?
 
ISTR there is also a clock enable bit that allows the comparitor to function. Perhaps it was in a post by @thereminengineer (apologies)
 
Hi,
in this forum I found code examples for using the comparator in a Teensy 3.5.
For comparator 1 a code example used
Code:
NVIC_ENABLE_IRQ(IRQ_CMP1); // handler is now cmp1_isr()
The macro name says that it is an enable function. The comment says that with this macro cmp1_isr() is attached to the interrupt.
In kinetis.h I found the definition of NVIC_ENABLE_IRQ but I don't understand what's going on there.

Performs this macro both, enable and attach, or only one of it?

cmp1_isr() is defined in cores\Teensy3\mk20dx128.c as shown below.

Code:
void cmp1_isr(void)		__attribute__ ((weak, alias("unused_isr")));

Further down in the same file, cmp_isr is assigned as default interrupt vector for the CMP1 interrupt. So, if you enable the interrupt, and the interrupt occurs, the default cmp1_isr() will be executed. It doesn't do anything, so the interrupt flag won't be cleared, and your program will hang. You need to implement your own cmp1_isr() in your sketch, process the interrupt and clear the flag. Because the function in the Teensy3 core is defined as "weak", the linker will use your function instead of the default.
 
Back
Top