External Interrupt Triggering for PSoC4

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Lin_Qiang
Level 4
Level 4
5 likes given First like given 50 replies posted

For the external falling edge interrupt of PSoC4, after using the automatically generated stop function to close the interrupt, use the automatically generated start function to open the interrupt after a period of time.
If there is no external falling edge to trigger the interrupt, is there any wrong operation that causes the interrupt to be triggered immediately when the start function is called.

0 Likes
1 Solution
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @Lin_Qiang ,

Can you please add the following piece of code before enabling the interrupt for the GPIO?

    //Loop to verify if pending interrupt on pin is cleared
    while((Pin_1_INTSTAT & Pin_1_MASK) == Pin_1_MASK)
    {
        //Toggle an LED or use a UART printf here for debugging
        
        //Try to clear the interrupt on Pin_1_INTSTAT
        Pin_1_ClearInterrupt();
        
        //Clear Pending on ISR component as well
        isr_1_ClearPending();
    }
    

 
Enable the interrupt for the GPIO after this and let me know if the interrupt is firing after this.

Warm Regards
Alen

View solution in original post

0 Likes
11 Replies
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @Lin_Qiang ,

Can you please let me know if you are using PSoC Creator or Modus Toolbox for your project?

Warm Regards
Alen

0 Likes

Hi Alen,

Yes, I am using PSoC Creator.

BestRegards

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @Lin_Qiang ,

Can you please clarify if you are using a normal GPIO input pin component with falling edge interrupt or since you mention start and stop API's are you using a SCB component for example like I2C?

Are you facing any specific issues in a project when using a component with falling edge interrupts?
If so, is it possible to share your project with us as well?.

Generally it is the practice to clear any pending interrupts before calling the start API for a component so that the IRQ pending register corresponding to that peripheral is cleared so that no interrupts are triggered because of any previous settings to this register when the component is started.

Warm Regards
Alen

 

0 Likes
Lin_Qiang
Level 4
Level 4
5 likes given First like given 50 replies posted

Hi Alen,

Thank you very much for your reply.

Can you please clarify if you are using a normal GPIO input pin component with falling edge interrupt or since you mention start and stop API's are you using a SCB component for example like I2C?

-->I am using a normal GPIO input pin component. It is just to detect external voltage changes (eg below 4.5V).

Are you facing any specific issues in a project when using a component with falling edge interrupts?
If so, is it possible to share your project with us as well?.

-->I use falling edge interrupt to detect if the voltage is below 4.5V.
In order to test the system stability, I repeatedly adjust the voltage (12V→2V→12V) during a certain period, and the interruption during this period is the state of stop.
But when I restore 12V and then start interrupt, the interrupt will occurs immediately.

Generally it is the practice to clear any pending interrupts before calling the start API for a component so that the IRQ pending register corresponding to that peripheral is cleared so that no interrupts are triggered because of any previous settings to this register when the component is started.

-->I've tried just clearing this interrupt before start, but it doesn't seem to work.
What needs to be done to clear any pending interrupts?

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @Lin_Qiang ,

If you have named your input GPIO pin component, say PIN_1, then calling the API PIN_1_ClearInterrupt() should clear the pending interrupt on that pin.
Can you make sure that this bit is cleared by reading back the interrupt status register and making sure that the bit is set to 1 (to clear the interrupt ) before enabling the interrupt for the GPIO again?

If you are using a PSoC 4200 device, then in the PSoC 4100/4200 Family PSoC® 4 Registers TRM, you have to check the PRTX_INTSTAT register for the port of your input pin. In this case, bits 7:0 of this register are the interrupt pending bits as shown below (pg 118):

AlenAn14_0-1644555561223.png

To make things easier, you can read the macro PIN_1_INTSTAT in PSoC Creator (assuming the pin component is named as PIN_1) and make sure the bit corresponding to the pin is 1 before you enable the interrupt.

Hope this helps.

Warm Regards
Alen

 

0 Likes

Hi Alen,

I have called the API PIN_1_ClearInterrupt() before enabling the interrupt, but it still doesn't solve the problem.
I wonder if it's possible to reconfigure once when interrupts are enabled, but maybe it's not necessary.

BestRegards

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Can you please let me know if you tried reading the PIN_1_INTSTAT register (Try displaying the value of this register via UART) after calling the function PIN_1_ClearInterrupt() to make sure that the interrupt pending bit corresponding to the pin is set to 1 (reading 1 on this bit means the interrupt pending bit is cleared) before enabling the interrupt?

This is to make sure that the interrupt won't be triggered when enabled again.

Can you also please let me know the MPN of the PSoC 4 device and the Pin on the same that you are using for the interrupt purpose.

Regards
Alen

0 Likes
 

Hi Alen,

The chip model I am using is CY8C4146LQS-S423. I used two external interrupts to detect voltage drops below 6V or 4.5V respectively. This is achieved through a special chip. When the voltage drops below 6V or 4.5V, it will output a low level, usually 3.3V. The two interrupt pins are P.0.0 and P1.4 respectively.
These two interrupts will be disabled at power-on and enabled after about 30s. But if there is a continuous voltage change before 30s, an interrupt will be generated when it is enabled that should not be detected, and this problem will not always occur.
I have not tried to monitor the state of the PIN_1_INTSTAT register, but have called the API PIN_1_ClearInterrupt().

BestRegards

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @Lin_Qiang ,

Can you please add the following piece of code before enabling the interrupt for the GPIO?

    //Loop to verify if pending interrupt on pin is cleared
    while((Pin_1_INTSTAT & Pin_1_MASK) == Pin_1_MASK)
    {
        //Toggle an LED or use a UART printf here for debugging
        
        //Try to clear the interrupt on Pin_1_INTSTAT
        Pin_1_ClearInterrupt();
        
        //Clear Pending on ISR component as well
        isr_1_ClearPending();
    }
    

 
Enable the interrupt for the GPIO after this and let me know if the interrupt is firing after this.

Warm Regards
Alen

0 Likes

Hi Alen,

Thank you for your reply.
After the above code is added before the interrupt enable, the problem no longer occurs.
Thanks again for your help.

BestRegards

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @Lin_Qiang ,

Glad your query is resolved.
Please feel free to post any queries or issues you may have on Infineon products in the community and we will be happy to help.

Warm Regards
Alen

0 Likes