AnsweredAssumed Answered

Enabling interrupt on a pin

Question asked by indraastra on Jun 11, 2013
Latest reply on May 29, 2014 by Mark Butcher

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.

Outcomes