GPIO Interrupt on KL25Z works only with internal clock setup

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

GPIO Interrupt on KL25Z works only with internal clock setup

779 Views
pokemongoesar
Contributor I

I work with bear metal on the KL25z and I have read the last weak documentation and forum posts

about external Interrupt on the KLZ.

My problem is that the interrupt is only working with the Clock setup to PortA and toggles then the

Interrupt over and over again but it isn't working with an external source.

But I want to get an Interrupt if an external signal is incoming but if I comment out the Line:

SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;

I get the HardFault Stackframe at the declaration of PORTA_PCR17 :

Stack frame:
 R0 =  0000031C
 R1 =  40049000
 R2 =  E000E100
 R3 =  C0000000
 R12 = 00000016
 LR =  80008980
 PC =  0000092E
 PSR = 81000000
Misc
 LR/EXC_RETURN= FFFFFFF9

My Code:

int main(int argc, char* argv[]) {
    // Send a greeting to the trace device (skipped on Release).
    trace_puts("Hello ARM World!");

    SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
    __asm volatile("cpsie i");    //Enable Global Interrupts
    NVIC_SetPriority(PORTA_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL);
    PORTA_PCR17  |=  PORT_PCR_MUX(1)  |  PORT_PCR_PE_MASK  | 

                                     PORT_PCR_PS_MASK | PORT_PCR_IRQC(0x08); // Interrupt on rising and falling edge

    NVIC_EnableIRQ(PORTA_IRQn); //Enable interrupt on IRQN
    while (1) {}
}

extern "C" void
PORTA_IRQHandler() {
    trace_puts("1");
    trace_puts("2");
}

I hope someone can tell me the problem, I have no clue what I do wrong, I read so many docs and

I'm now done with my knowledge....

Greedings,

Max

0 Kudos
2 Replies

643 Views
pokemongoesar
Contributor I

I tested different IRQC Options and I found out that 'Interrupt when logic one - 1100' triggers directly, I think the pin might be pulled up internally and the option 'Interrupt when logic zero - 1000' works only one time after the first time i put in GND to initalize the interrupt it keeps running forever, even when I plug in 5V it keeps running and vice versa with the logic zero option.

I also tried 'NVIC_ClearPendingIRQ(PORTA_IRQn);' in the Interrupt but without any success.

Did anyone know what I missed in the Interrupt and Pin Setup?

0 Kudos

643 Views
mjbcswitzerland
Specialist V

Hi

You can't access PORTx_PCRy registers without them being clocked so a hard-fault in such a case is normal.

When your interrupt fires you must clear its pending flag by writing to PORTx_ISFR otherwise it will continuously re-enter.

Kinetis GPIO interrupt Video: https://www.youtube.com/watch?v=CubinvMuTwU

(also discussing sharing interrupt vectors for unrestricted operation)

Regards

Mark

Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html
Kinetis KL25:
- http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market
Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

0 Kudos