NewBee question. Can anybody point me to an example of how to code (barebones) an interrupt from the SW1 button on a K64 eval. board?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NewBee question. Can anybody point me to an example of how to code (barebones) an interrupt from the SW1 button on a K64 eval. board?

456 Views
johnbaker
Contributor IV

I am new to Microcontroller coding and need to figure out how to code an interrupt request routine.  I can blink the LED's, enable the RTC, and create PIT timers and check for when they fire but am having problems figuring out an actual interrupt like what happens when you push the SW1 button on the K64 evaluation board.  Any help would be appreciated.

Thanks

Labels (1)
0 Kudos
1 Reply

277 Views
mjbcswitzerland
Specialist V

Hi John

To program an interrupt on the SW1 button of the K64 TWR board (falling edge when pressed) the following operations are required:

Interrupt vector 0x3d entered to point to the PORTC interrupt handling routine

IRQ60_64_PRIORITY = 0x00006000; // set priority of PORT C interrupt(s) to 6 (for example)

IRQ32_63_SER = 0x20000000; // enable the PORT C interrupt in the NVIC

PORTC_PCR6 = 0x000a0103; // configure and enable negative edge interrupt on PTC6

You can change the register names to match those in your header files and can look at the register content to work out what is being done.

If you need more details you can download the uTasker project [KINETIS Project Code], which also simulates the port interrupt operation. Below is a user interface code to configure any pin for interrupt operation. Each port has one interrupt vector but the interrupt interface allows a user interrupt call-back handler to be associated with a single pin or single interrupt handler to respond to changes on multiple pins, which makes port change interrupts to be used with great ease.

// Interrupt call-back handler

//

static void test_sw1_press(void)

{

    // Insert IRQ code (interrupt has been cleared)

}

//Interrupt configuration

    INTERRUPT_SETUP interrupt_setup;                                     // interrupt configuration parameters

    interrupt_setup.int_type       = PORT_INTERRUPT;                     // identifier to configure port interrupt

    interrupt_setup.int_handler    = test_sw1_press;                     // handling function

    interrupt_setup.int_priority   = PRIORITY_PORT_C_INT;                // interrupt priority level

    interrupt_setup.int_port       = PORTC;                              // the port that the interrupt input is on

    interrupt_setup.int_port_bits  = PORTC_BIT6;                         // the IRQ input connected (SW1 on TWR-K64F)

    interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON);     // interrupt is to be falling edge sensitive

    fnConfigureInterrupt((void *)&interrupt_setup);                      // configure interrupt

Regards

Mark

µTasker Kinetis support

0 Kudos