Hello,
I am trying to create an interrupt through pit.
But I didn't find any resourceful material in order to call an interrupt.
I want to know what all modification is required to be done in order to call interrupt isr.
All i know is I have to define vector in isr.h for the required isr function only.
Solved! Go to Solution.
Gagan,
Here is a simple example for the KL25Z MCU.
// PIT Initialization
SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; // Enable the clock to the PIT module
PIT_LDVAL0 = 8000000; // Default start value
PIT_MCR = PIT_MCR_FRZ_MASK; // Enable clock for timer, freeze timer in debug mode
PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK; // Enable timer and timer interrupt
// Initialize the NVIC to enable the PIT interrupt
NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32);
NVIC_ISER |= 1 << ((INT_PIT - 16) % 32);
In CW 10.3 and for FRDM-KL25Z the GCC compiler is used, this compiler creates the vector table with the names of each interrupt. So it is just necessary to name you ISR with the same name in the vector table (PIT_IRQHandler in the kinetis_sysinit.c).
void PIT_IRQHandler()
{
PIT_TCTRL0 = 0; // Disable timer
PIT_TFLG0 |= PIT_TFLG_TIF_MASK; // Clear the timer interrupt flag
PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK; // Enable timer
}
Hope it helps.
Regards,
Tomas
Gagan,
Here is a simple example for the KL25Z MCU.
// PIT Initialization
SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; // Enable the clock to the PIT module
PIT_LDVAL0 = 8000000; // Default start value
PIT_MCR = PIT_MCR_FRZ_MASK; // Enable clock for timer, freeze timer in debug mode
PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK; // Enable timer and timer interrupt
// Initialize the NVIC to enable the PIT interrupt
NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32);
NVIC_ISER |= 1 << ((INT_PIT - 16) % 32);
In CW 10.3 and for FRDM-KL25Z the GCC compiler is used, this compiler creates the vector table with the names of each interrupt. So it is just necessary to name you ISR with the same name in the vector table (PIT_IRQHandler in the kinetis_sysinit.c).
void PIT_IRQHandler()
{
PIT_TCTRL0 = 0; // Disable timer
PIT_TFLG0 |= PIT_TFLG_TIF_MASK; // Clear the timer interrupt flag
PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK; // Enable timer
}
Hope it helps.
Regards,
Tomas
Hello Tomas, i'm trying to follow your example but it didn't work...i've copied your code but i've a question...i have to write the instruction for the interrupt in Kinetis_sysinit.c or in main.c?
Thanks Davide.
Sorry, I do not know which series chip you use. So here, I give you a PIT example initial code for your reference. In this code, it use interrupt flag check method.
///////////////////////////////////////////////////////////////////////////////////////////
PIT_MCR= 0x00;
PIT_LDVAL = 0x16E3600;
PIT_TCTRL = PIT_TCTRL0_TIE_MASK;
PIT_TCTRL |= PIT_TCTRL0_TEN_MASK;
while(PIT_TFLG == 0) ;//Waiting Interrupt
PIT_TFLG = PIT_TFLG0_TIF_MASK; // Clear Interrupt flag
PIT_TCTRL = 0 ; //Disable TEN
///////////////////////////////////////////////////////////////////////////////////////////