RT1064. how to read IRQ edge state

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

RT1064. how to read IRQ edge state

Jump to solution
1,400 Views
atas2000
Contributor II

Hello.

Help me figure out how the interrupt fired. 

I configured interrupt to fire on raising and falling edge with interrupt config parameter:

kGPIO_IntRisingOrFallingEdge

In which register  the state of the falling or rising edge is reflected?

An one more.

Is it possible to change interrupt settings inside the IRQ function?

For example change kGPIO_IntLowLevel to kGPIO_IntHighLevel.

I tried, but the changes did not work. The interrupt continued to work with the old settings.

Labels (1)
0 Kudos
1 Solution
1,291 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Aleks,

Regarding your questions please see my comments below.

In which register the state of the falling or rising edge is reflected?

Unfortunately, there aren't any register that shows if it was either falling or rising edge. However, inside the IRQ handler, you can read the state of the pin, this way you can determine if it was a rising or falling edge. Something like the following:

void EXAMPLE_GPIO_IRQHandler(void)
{
    /* clear the interrupt status */
    if(GPIO_PinRead(EXAMPLE_SW_GPIO, EXAMPLE_SW_GPIO_PIN))
    {
     /* Rising edge */
     interrupt_flag = 1;
    }
    else
    {
     /* Falling edge */
     interrupt_flag = 0;
    }

    GPIO_PortClearInterruptFlags(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
    /*GPIO_GetPinsInterruptFlags*/

    /* Change state of switch. */
    g_InputSignal = true;
    /* 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
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Is it possible to change interrupt settings inside the IRQ function?

Yes, it is possible. To achieve this you need to follow the next procedure.

void EXAMPLE_GPIO_IRQHandler(void)
{
    /* clear the interrupt status */
    GPIO_PortClearInterruptFlags(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
    /* Change state of switch. */
    g_InputSignal = true;
    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
      exception return operation might vector to incorrect interrupt */

    if(change_interrupt)
    {
     GPIO_PortDisableInterrupts(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
        GPIO_PinInit(EXAMPLE_SW_GPIO, EXAMPLE_SW_GPIO_PIN, &sw_reconfig);
        GPIO_PortEnableInterrupts(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
        change_interrupt = false;
    }
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Please consider that keeping the IRQ handlers as short and fast as possible is a good C programming practice. So, it would be good to consider changing the interrupt settings outside the IRQ handler.


Have a great day,
TIC

-------------------------------------------------------------------------------
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.
-------------------------------------------------------------------------------

View solution in original post

2 Replies
1,292 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Aleks,

Regarding your questions please see my comments below.

In which register the state of the falling or rising edge is reflected?

Unfortunately, there aren't any register that shows if it was either falling or rising edge. However, inside the IRQ handler, you can read the state of the pin, this way you can determine if it was a rising or falling edge. Something like the following:

void EXAMPLE_GPIO_IRQHandler(void)
{
    /* clear the interrupt status */
    if(GPIO_PinRead(EXAMPLE_SW_GPIO, EXAMPLE_SW_GPIO_PIN))
    {
     /* Rising edge */
     interrupt_flag = 1;
    }
    else
    {
     /* Falling edge */
     interrupt_flag = 0;
    }

    GPIO_PortClearInterruptFlags(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
    /*GPIO_GetPinsInterruptFlags*/

    /* Change state of switch. */
    g_InputSignal = true;
    /* 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
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Is it possible to change interrupt settings inside the IRQ function?

Yes, it is possible. To achieve this you need to follow the next procedure.

void EXAMPLE_GPIO_IRQHandler(void)
{
    /* clear the interrupt status */
    GPIO_PortClearInterruptFlags(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
    /* Change state of switch. */
    g_InputSignal = true;
    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
      exception return operation might vector to incorrect interrupt */

    if(change_interrupt)
    {
     GPIO_PortDisableInterrupts(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
        GPIO_PinInit(EXAMPLE_SW_GPIO, EXAMPLE_SW_GPIO_PIN, &sw_reconfig);
        GPIO_PortEnableInterrupts(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);
        change_interrupt = false;
    }
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Please consider that keeping the IRQ handlers as short and fast as possible is a good C programming practice. So, it would be good to consider changing the interrupt settings outside the IRQ handler.


Have a great day,
TIC

-------------------------------------------------------------------------------
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,291 Views
atas2000
Contributor II

Thanks for the answer.

0 Kudos