- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 -
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Schematic
Note: Pin_1 for falling edge, Pin_2 for rising edge
Pin_1 configuration
Pin_2 configuration
TeraTerm log
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Schematic
Note: Pin_1 for falling edge, Pin_2 for rising edge
Pin_1 configuration
Pin_2 configuration
TeraTerm log
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.