Greetings, I recently bought a FRDM-KL27Z board and was trying some basic things with it, the latest attempt setting the TPM to output compare, and getting it to interrupt on said compare.
I created a new project, added the TPM drivers, initialize everything on the config tools (i'm not trying to alter the state of the channel pins just generate an interrupt on compare) copied the interrupt handler template and pasted it above my main and... it doesn't work.
When i pause the debugging session the program is stuck at the default handler, and setting a breakpoint here:
and pressing F5 to step into it takes me to the default interrupt handler:
What drives me mad is that this is exactly what the demo for the adc16 shows on handling interrupts (regardless of wich vector it is):
what am I missing, why does it fail on my code but not on the example?
I'll attach a zip of the project that i generated with the export tool from MCUxpresso.
Solved! Go to Solution.
Hi,
This is a common question when c/c++ mix. Use extern "C". Please see this link.
https://community.nxp.com/t5/LPC-Microcontrollers/Interrupt-working-under-C-but-not-C/m-p/863141
Regards,
Jing
Hi Santiago,
Please check in startup_mkl227z644.c. The interrupt vector table is g_pfnVectors. In this table, TPM2's interrupt service routine is TPM2_IRQHandler. The Config Tool will not touch this part. You much keep your code name same with the item in vector table.
Regards,
Jing
Hi, I had already checked the table, the config tool doesn't change the table but comes with this button:
I copied that and pasted it over my main, which is, again, exactly what the example for the adc16interrupt does, but just to check, I went and did as you instructed:
all the code remains the same I've simply renamed: TPM2_IRQHANDLER to TPM2_IRQHandler, not that it should matter becouse when i go to peripherals.h:
That all caps name is just a define to the same vector, again, what am I missing? why does the example compile and work but my code doesn't?
Hi,
This is a common question when c/c++ mix. Use extern "C". Please see this link.
https://community.nxp.com/t5/LPC-Microcontrollers/Interrupt-working-under-C-but-not-C/m-p/863141
Regards,
Jing
Yeah using extern "C" before the function name solved it.
I'll leave some info on why you have to use extern C:
https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c