Hi there,
I am a complete newbie to Freescale microcontrollers and the Freedom KL25Z development board, but I have watched all of Eli Hughes' excellent introductory videos. I'm trying to build on his examples by writing a simple program that toggles an LED on or off by watching for an interrupt on a pin driven by a simple pushbutton switch. I want to configure this pin to use the internal pullup resistor so that when the switch is pushed, the pin is pulled low; correspondingly, I want the interrupt to fire on a falling edge.
The code below outlines my basic approach to this, and I think I have enabled interrupts for both Port A Pin 20 (where the switch is connected) and also Port A on the NVIC. However, when I push the button, the code seems to exit immediately and I see the message "Suspended: Signal 'Halt' received..." from the CodeWarrior debug view. What am I doing wrong?
#include "derivative.h" /* include peripheral declarations */
int fired = 0;
void PORTA_IRQHandler() {
fired = 1;
}
int main(void)
{
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
PORTA_PCR20 = PORT_PCR_MUX(1) | PORT_PCR_IRQC(6) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK; // Interrupt on falling edge.
// enable IRQ on Port A, pin 20
int irq_num = INT_PORTA - 16;
NVIC_ICPR |= 1 << irq_num;
NVIC_ISER |= 1 << irq_num;
for (;;) {
if (fired == 1) {
// toggle LED
fired = 0;
}
}
return 0;
}
I have a breakpoint set within the ISR which is never reached.
Solved! Go to Solution.
Looks like I had the misfortune of picking the RESET pin to test interrupts on! Switching to another pin on port A did the trick.
Hello everyone,
I am also trying to program an interrupt on a falling edge but with the Freedom KL05Z development board. I have followed the previous example and I have tried different pins but it's not working. I don't know what am I missing, in the reference manual of the KL05Z the configuration do not seem to be different...
Thank you in advance! :smileyhappy:
Hi
Have you enabled the "global interrupt" as well as configuring the NVIC and the port interrupt itself?
Regards
Mark
Hi Mark,
I'm sorry, I am very new to Freescale microcontrollers and I don't know how to enable the global interrupt. I have been looking for it in the reference manual and this is in section 11.6.2. Global pin control: "However, the interrupt functions cannot be configured using the global pin control registers". I must be mistaking parameters...
Thank you for your time!
Cris
The global interrupt control is in the ARM procesor.
Using Codewarrior it can be enabled with asm("cpsie i");
Regards
Mark
Looks like I had the misfortune of picking the RESET pin to test interrupts on! Switching to another pin on port A did the trick.
I see that I made a mistake and should have set PORT_PCR_IRQC(0xA) instead, but the code still terminates prematurely.