Hi, I'm new here and, of course, I need your help.
I'm starting a new project using a MKV30F64VFM10. I'm using Kinetis Design Studio to develop code with Processor expert. After a while (!!!) I understand how to configure Clock, I/O, ... ("hardware" in one word) and it seems to work. In particular I tested an ADC input with different input values and their corrisponding digital values: good. After I developed the "Uart0 part" and checked it with a PC and this is working too. But all the Uart is developed in "polling mode", when I tried to do it in interrupt mode I started have problems. I think my mistake is in interrupt configuration, so I started a new project only to configurate a timer (PIT channel 0) to have interrupt every 10 secs; but it doesn't work... Now I try to explain the configuration I did, assuming MCG configuration is ok (I tested with an oscilloscope the bit duration on a 115200 baudrate Tx on uart0 and it is ok).
In Components_Init() of Cpu.c (generated by processor expert I suppose) I have this code:
NVIC_SetPriority(PIT0_IRQn, 7U);
OSA_InstallIntHandler(PIT0_IRQn, pitTimer1_IRQHandler);
PIT_DRV_Init(FSL_PITTIMER1,true);
PIT_DRV_InitChannel(FSL_PITTIMER1,FSL_PITTIMER1_CHANNEL,&pitTimer1_InitConfig0);
PIT_DRV_StartTimer(FSL_PITTIMER1,FSL_PITTIMER1_CHANNEL);
In main.c, after PE_low_level_init();, I added this line:
__enable_irq(); //"cpsie i" to enable general interrupt
in Events.c I have:
void pitTimer1_IRQHandler(void)
{
/* Clear interrupt flag.*/
PIT_HAL_ClearIntFlag(g_pitBase[FSL_PITTIMER1], FSL_PITTIMER1_CHANNEL);
/* Write your code here ... */
}
which is my Timer interrupt handler added by OSA_InstallIntHandler() (I always suppose) but when I debug the code this function is never executed!
So I added in my main this:
uint32_t MCR;
uint32_t LDVAL;
uint32_t CVAL;
uint32_t TCTRL;
uint32_t TFLG;
uint32_t ISER;
uint32_t IABR;
uint32_t CLRENA;
for(;;) {
MCR = PIT_MCR;
LDVAL = PIT_LDVAL0;
CVAL = PIT_CVAL0;
TCTRL = PIT_TCTRL0;
TFLG = PIT_TFLG0;
ISER = NVIC->ISER[1];
IABR = NVIC->IABR[1];
CLRENA = NVIC->ICER[1];
}
To control PIT values and NVIC settings.
What I saw is that PIT_CVAL0 starts from a value (a conversion of my 10 seconds I believe) and it rolls down to 0 value (after 10 secs).
When it reaches 0 PIT_TFLG0 goes from 0 to 1 (TIF bit means Timer Interrupt Flag set)
NVIC->ISER[1] and NVIC->ICER[1] are both 0x10000 (This seems good for PIT channel 0)
But NVIC->IABR[1] is always 0 and interrupt doesn't come :-(
Finally I added these 3 lines inside the same loop (for(;;){...}):
if (TFLG & 0x01) {
PIT_HAL_ClearIntFlag(g_pitBase[FSL_PITTIMER1], FSL_PITTIMER1_CHANNEL);
}
to reset pending bit of PIT channel 0 and I saw that TIF bit goes to 0 and goes one more time to 1 after 10 secs...
Can you help me please, like you can see I'm not the one who ask for everything (all this I did by myself, without help) but now I don't know what else to do, please hele me.
If you need more info please ask me.