Use of GPIO Interruptions

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

Use of GPIO Interruptions

1,601 Views
pablo_cosgaya
Contributor II

Hello,

I've been trying to setup interruptions on PTB5 (Pin 12) of MKE16Z64VLD but it is not working. I am following the example called gpio_input_interrupt present on the SDK but still I cannot get it to work.

void PORTBCD_IRQHandler(void)
{
/*GPIOB5 PORTB PIN 12*/
GPIO_PortClearInterruptFlags(GPIOB, 1U << 5U);
INT= 1;

/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}

int main(void) {
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
/* Init FSL debug console. */
BOARD_InitDebugConsole();

/* Define the init structure for the input pin */
gpio_pin_config_t sw_config = {
kGPIO_DigitalInput, 0,
};

#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
GPIO_SetPinInterruptConfig(GPIOB, 5U, kGPIO_InterruptFallingEdge);
#else
PORT_SetPinInterruptConfig(PORTB, 5U, kPORT_InterruptFallingEdge);
#endif
EnableIRQ(PORTBCD_IRQHandler);
GPIO_PinInit(GPIOB, 5U, &sw_config);

while(1) {

       if (INT)
      {PRINTF (" Interruption");
       INT=0;}

               }
return 0 ;

}

As you can see the code I am using is almost the same one as the example. I am kind of clueless of why it may be failing, so any kind of help will be appreciated. 

Best Regards,

Pablo Cosgaya

0 Kudos
Reply
7 Replies

1,433 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Pablo,

 

I checked your code and it seems that you are not enabling the pin mux functionality on pin_mux.c

 

You should set is as follows:

PORT_SetPinMux(PORTB, 5U, kPORT_MuxAsGpio);

 

I hope this helps.

 

Best regards,

Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

1,433 Views
pablo_cosgaya
Contributor II

Hello again,

I have added  this function and it doesn't seem to be working either, the code neer enters the interruption is still not working yet. I have also tried using asm("cpsie   i") and there has been no luck either. I have also tried using the DisableGlobalIRQ and EnableGlobalIRQ functions as well to check if gloal interrupts were off but that method has also failed.

Is there any kind of setup guide or aplication note that goes step by step that I can check?

Best Regards,

Pablo

0 Kudos
Reply

1,433 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Pablo,

 

Unfortunately, we do not have such an application note explaining that. What I recommend you is to base your project in gpio_input_interrupt example from SDK and change the interrupt pin for PTB5. Please make sure of the following:

 

-Initialize clock.

-Initialize corresponding pin.

-Configure interrupt.

-Initialize GPIO.

-Use the appropriate interrupt handler.

 

I hope this helps.

 

Best regards,

Felipe

0 Kudos
Reply

1,433 Views
pablo_cosgaya
Contributor II

Hello again,

I finally found the problem, turns out it was a HW problem instead of a SW one. I had pin 30 connected pulled down via a resistor on my PCB which caused the interruptions to never happen as it was the NMI pin which according to the reference manual should not have a LOW logic level if you need to use Interrupts. Thanks everyone for the help!

Regards,

Pablo

0 Kudos
Reply

1,433 Views
mjbcswitzerland
Specialist V

Hi

Are you sure that you have enabled interrupts globally?

General guide to GPIO interrupts: https://www.youtube.com/watch?v=CubinvMuTwU&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q&index=18

Regards

Mark

Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html
Kinetis KE:
- http://www.utasker.com/kinetis/FRDM-KE02Z.html
- http://www.utasker.com/kinetis/FRDM-KE02Z40M.html
- http://www.utasker.com/kinetis/FRDM-KE04Z.html
- http://www.utasker.com/kinetis/FRDM-KE06Z.html
- http://www.utasker.com/kinetis/FRDM-KE15Z.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
Reply

1,433 Views
pablo_cosgaya
Contributor II

Hello,

I am not completely sure of what you mean, I've tried NVIC_GetEnableIRQ(PORTBCD_IRQn)) and it tells me interrupts are active, so it should be working but nevertheless the code never enters the interruption function. I have also tried enabling the interrupts on the main function just in case something was overwriting it but there was no response with that method either.

The GPIO port and pins are initialized using the BOARD_InitBootPins(); and BOARD_InitBootPeripherals(); functions which seem to be working properly, I have checked inside of those the details of the initialization of the GPIO port and they seem to be correct and the port has the clock gate enabled as well.

I don't really know what could be the problem, I will attach both the .mex I am using as well as the code just in case I am missing something obvious, which could honestly just be the case as I am quite new to microcontroller programming.

Best Regards,

Pablo 

0 Kudos
Reply

1,433 Views
mjbcswitzerland
Specialist V

Check that the Cortex core's global interrupt mask (PRIMASK) is not set. You will find an instruction like

asm("cpsie   i")

which clears it from its masked state after reset.

Regards

Mark

0 Kudos
Reply