Input interrupt Handler example on KW41Z

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Input interrupt Handler example on KW41Z

跳至解决方案
1,933 次查看
diegocomin
Contributor IV

Hi,

I am using as a project base the "frdmkw41z_driver_examples_gpio_input_interrupt" SDK example. In this project the SW3 attached to the PTC4 pin is configured as an input interrupt and it uses the PORTB_PORTC_IRQHandler to receive the interrupt and set a flag to toggle a LED.

In my case I want to set up two input interrupts the SW3 and SW4 (PTC4 and PTC5), as there is only one IRQHandler for the same PORTB (PORTB_PORTC_IRQHandler) how can I receive the input interrupt from the SW4?

As I can see, there are only two IRQHandler: PORTB_PORTC_IRQHandler and PORTA_IRQHandler, so this means that the Board can only handle two input interrupts at the same time? How can I receive more digital input interrupts?

Regards,

Diego Comín

0 项奖励
1 解答
1,572 次查看
FelipeGarcia
NXP Employee
NXP Employee

Hi Diego,

 

You can receive as many interrupts as pins you have available, the thing is that the handler will be the same.

 

What you have to do is call the function int32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base) inside the IRQHandler.

This function will give you the current GPIO port interrupt status flag, for example, 0x00010001 means pin 0 and 17 have the interrupt.

 

Then, depending on the value PORTx_ISFR you can set flags according to your needs.

 

Please take the following IRQHandler as an example:

void BOARD_SW_IRQ_HANDLER(void)

{

interruptflag = GPIO_GetPinsInterruptFlags(BOARD_SW_GPIO);

if(0x10 == interruptflag) // flag for SW3

g_ButtonSW3Press = true;

if(0x20 == interruptflag) // flag for SW4

g_ButtonSW4Press = true;

/* Clear external interrupt flags. */

GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW3_GPIO_PIN);

GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW4_GPIO_PIN);

}

 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope it 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.
-------------------------------------------------------------------------------

在原帖中查看解决方案

3 回复数
1,573 次查看
FelipeGarcia
NXP Employee
NXP Employee

Hi Diego,

 

You can receive as many interrupts as pins you have available, the thing is that the handler will be the same.

 

What you have to do is call the function int32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base) inside the IRQHandler.

This function will give you the current GPIO port interrupt status flag, for example, 0x00010001 means pin 0 and 17 have the interrupt.

 

Then, depending on the value PORTx_ISFR you can set flags according to your needs.

 

Please take the following IRQHandler as an example:

void BOARD_SW_IRQ_HANDLER(void)

{

interruptflag = GPIO_GetPinsInterruptFlags(BOARD_SW_GPIO);

if(0x10 == interruptflag) // flag for SW3

g_ButtonSW3Press = true;

if(0x20 == interruptflag) // flag for SW4

g_ButtonSW4Press = true;

/* Clear external interrupt flags. */

GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW3_GPIO_PIN);

GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW4_GPIO_PIN);

}

 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope it 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.
-------------------------------------------------------------------------------

1,572 次查看
diegocomin
Contributor IV

Hi Felipe,

Thank you so much! That's the answer I was looking for, I will try it in my code and I report you my status. 


Could you also take a look to other issue I posted related to the I2C slave communication inside router_eligible_device_freertos project? R41Z I2C compatibility with Raspberry Pi?  

Regards,

Diego Comín 

0 项奖励
1,572 次查看
mjbcswitzerland
Specialist V

Hi Diego

You can see this video showing how you can do this: https://www.youtube.com/watch?v=CubinvMuTwU

This is standard in the uTasker project where each pin can be given its own interrupt call back.

Regards

Mark


Complete Kinetis solutions, training and support:http://www.utasker.com/kinetis.html

0 项奖励