GPIO Interrupts

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

cross mob
SaGh_4441651
Level 3
Level 3
First like received First like given

I have 2 hardware buttons that are connect to P1.2 and P1.3. I need to generate interrupts on each of this button press. I have configured the Pin component and the ISR as below -

Capture6.JPG

Capture3.JPG

Capture4.JPG

Capture5.JPG

My questions are -

1) DO I need to connect the ISR component here?

2) There are other components connected on this port, so I don't want other components to be affected in any way - when I enable / clear interrupts for these 2 hardware buttons.

3) I tried following this code -

CY_ISR(INT_ISR_Button)

{

     /* Set the flag */

     isrFlag = 1u;

     /* Check which pin caused interrupt by reading interrupt status register */

     if(Pin_Button_INTSTAT & (0x01u << Pin_Button_SHIFT))

     {

          /* Triggered by Pin_Button_0 */

          ledState = LED_OFF;

     }

     else

     {

          /* Triggered by Pin_Button_1 */

          ledState = LED_ON; }

          /* Clear interrupt */

          Pin_Button_ClearInterrupt();

     }

}

Found this code in this document - https://www.cypress.com/file/127101/download Page 49-50

Following this - I am unable to generate interrupts on the  said pins. What am I missing here?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> I have configured 2 indivdial pins as Digital inputs.

What a challenging question!

So I interpreted your question was how to configure 2 GPIO input for interrupt.

Assumption:

(1) Last time you were using PSoC 4100S Plus

(2) There was no hint about if interrupt is rising edge or falling edge

So I tried with CY8CKIT-149 (PSoC 4100S Plus) and 2 inputs,

one for falling edge, and the other for rising edge.

IMG_4048.JPG

Schematic

Note: Pin_1 for falling edge, Pin_2 for rising edge

002-schematic.JPG

Pin_1 configuration

003-Pin_1_1.JPG

004-Pin_1_2.JPG

006-isr_1.JPG

Pin_2 configuration

005-Pin_2_2.JPG

005-Pin2_1.JPG

007-isr_2.JPG

TeraTerm log

000-TeraTerm-Log.JPG

main.c

====================

#include "project.h"

#include "stdio.h"

volatile int falling_flag = 0 ;

volatile int rising_flag = 0 ;

CY_ISR(falling_isr)

{

    Pin_1_ClearInterrupt() ;

    falling_flag = 1 ;

}

CY_ISR(rising_isr)

{

    Pin_2_ClearInterrupt() ;

    rising_flag = 1 ;

}

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_UartPutString(str) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(100) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(100) ;

}

void splash(void)

{

    cls() ;

    print("PSoC 4100S Plus GPIO INT TEST ") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

void init_hardware(void)

{

    UART_Start() ;

  

    isr_1_StartEx(falling_isr) ;

  

    isr_2_StartEx(rising_isr) ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

}

int main(void)

{

    init_hardware() ;

  

    splash() ;

    for(;;)

    {

        if (falling_flag) {

            CyDelay(20) ; /* for debounce */

            falling_flag = 0 ;

            print("Pin_1 SW pushed\n") ;

        }

        if (rising_flag) {

            CyDelay(20) ; /* for debounce */

            rising_flag = 0 ;

            print("Pin_2 SW pushed\n") ;

        }

    }

}

====================

moto

View solution in original post

0 Likes
3 Replies
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

If you have some doubts about the GPIO. Please refer to the below linker:

PSoC4:

https://www.cypress.com/documentation/application-notes/an86439-psoc-4-using-gpio-pins

PSoC6:

https://www.cypress.com/file/385856/download

If you have the specific question, please describe it in details.

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> I have configured 2 indivdial pins as Digital inputs.

What a challenging question!

So I interpreted your question was how to configure 2 GPIO input for interrupt.

Assumption:

(1) Last time you were using PSoC 4100S Plus

(2) There was no hint about if interrupt is rising edge or falling edge

So I tried with CY8CKIT-149 (PSoC 4100S Plus) and 2 inputs,

one for falling edge, and the other for rising edge.

IMG_4048.JPG

Schematic

Note: Pin_1 for falling edge, Pin_2 for rising edge

002-schematic.JPG

Pin_1 configuration

003-Pin_1_1.JPG

004-Pin_1_2.JPG

006-isr_1.JPG

Pin_2 configuration

005-Pin_2_2.JPG

005-Pin2_1.JPG

007-isr_2.JPG

TeraTerm log

000-TeraTerm-Log.JPG

main.c

====================

#include "project.h"

#include "stdio.h"

volatile int falling_flag = 0 ;

volatile int rising_flag = 0 ;

CY_ISR(falling_isr)

{

    Pin_1_ClearInterrupt() ;

    falling_flag = 1 ;

}

CY_ISR(rising_isr)

{

    Pin_2_ClearInterrupt() ;

    rising_flag = 1 ;

}

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_UartPutString(str) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(100) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(100) ;

}

void splash(void)

{

    cls() ;

    print("PSoC 4100S Plus GPIO INT TEST ") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

void init_hardware(void)

{

    UART_Start() ;

  

    isr_1_StartEx(falling_isr) ;

  

    isr_2_StartEx(rising_isr) ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

}

int main(void)

{

    init_hardware() ;

  

    splash() ;

    for(;;)

    {

        if (falling_flag) {

            CyDelay(20) ; /* for debounce */

            falling_flag = 0 ;

            print("Pin_1 SW pushed\n") ;

        }

        if (rising_flag) {

            CyDelay(20) ; /* for debounce */

            rising_flag = 0 ;

            print("Pin_2 SW pushed\n") ;

        }

    }

}

====================

moto

0 Likes

Hey Motoo Tanaka,

Thank you for your response. I didn't realize my question was posted even before I finished writing it down completely. I have edited my question to completion now.