PSoC Multiple Pins Interrupts

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

cross mob
RoRo_4659551
Level 4
Level 4
25 replies posted 10 replies posted 10 likes given

Hi,

I am trying to configure multiple pins connected to interrupts but I receive an error [see attached pictures].

RoRo_4659551_1-1620121963019.png

 

RoRo_4659551_2-1620121972232.png

 

RoRo_4659551_0-1620121952291.png

 

Thanks,

Roy Roif

 

@Motoo_Tanaka 

 

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,

As I wrote in my previous post, if you have an interrupt with pin P5[x], 

interrupt for P5[1] may not be redefined.

Anyway, I tried to create a sample with your device.

schematic

Note: This assumes that all the pins are connected to a low-active switch(es),

so I added a "NOT" between pin and isr.

I assigned 12[6] and 12[7] for UART pins.

Change them if you are assigning them to other pins.

010-schematic.JPG

Pins

011-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"

#define STR_BUF_LEN 64
char str[STR_BUF_LEN+1] ;
void print(char *str)
{
    UART_PutString(str) ;
}

volatile int pin1_flag = 0 ;
volatile int pin2_flag = 0 ;
volatile int pin3_flag = 0 ;
volatile int pin4_flag = 0 ;
volatile int pin5_flag = 0 ;
volatile int pin6_flag = 0 ;
volatile int pin7_flag = 0 ;

CY_ISR(pin1_isr)
{
    pin1_flag = 1 ;
    isr_1_ClearPending() ;
}

CY_ISR(pin2_isr)
{
    pin2_flag = 1 ;
    isr_2_ClearPending() ;    
}

CY_ISR(pin3_isr)
{
    pin3_flag = 1 ;
    isr_3_ClearPending() ;
}

CY_ISR(pin4_isr)
{
    pin4_flag = 1 ;
    isr_4_ClearPending() ;    
}

CY_ISR(pin5_isr)
{
    pin5_flag = 1 ;
    isr_6_ClearPending() ;    
}

CY_ISR(pin6_isr)
{
    pin6_flag = 1 ;
    isr_6_ClearPending() ;    
}

CY_ISR(pin7_isr)
{
    pin7_flag = 1 ;
    isr_7_ClearPending() ;    
}


void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    UART_Start() ;
    print("\x1b[2J\x1b[;H") ;
    print("PSoC 5LP Multi Pins Interrupt Test ") ;
    snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
    print(str) ;
    
    isr_1_StartEx(pin1_isr) ;
    isr_2_StartEx(pin2_isr) ;
    isr_3_StartEx(pin3_isr) ;
    isr_4_StartEx(pin4_isr) ;
    isr_5_StartEx(pin5_isr) ;
    isr_6_StartEx(pin6_isr) ;
    isr_7_StartEx(pin7_isr) ;    
}

int main(void)
{
    init_hardware() ;

    for(;;)
    {
        if (pin1_flag) {
            pin1_flag = 0 ;
            print("Pin1 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin2_flag) {
            pin2_flag = 0 ;
            print("Pin2 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin3_flag) {
            pin3_flag = 0 ;
            print("Pin3 was pressed\n\r") ;
            CyDelay(100) ;
        }        
        if (pin4_flag) {
            pin4_flag = 0 ;
            print("Pin4 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin5_flag) {
            pin5_flag = 0 ;
            print("Pin5 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin6_flag) {
            pin6_flag = 0 ;
            print("Pin6 was pressed\n\r") ;
            CyDelay(100) ;
        }          
        if (pin7_flag) {
            pin7_flag = 0 ;
            print("Pin7 was pressed\n\r") ;
            CyDelay(100) ;
        }          
    }
}

At least this project could be built without error.

(But I could not test it, as I don't have a board with that device).

moto

View solution in original post

10 Replies
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,

The user reference you addressed was my private CDC account.

Please refer to the following reference

https://community.cypress.com/t5/user/viewprofilepage/user-id/15414

 

Now returning to your question.

The pin interrupt structure of arm Cortex-M is per port and not per pin.

P0[0] ~ P0[7] share same interrupt.

So in your cate P5[0] ~ P5[7] share same interrupt.

And you/we need to determine which pin generated the interrupt in ISR.

(or  check the interrupt source)

I tried a sample with CY8CKIT-059 (CY8C5888LTI-LP097] and as I could not use P5[x]

I used P3[0] ~ P3[4].

schematic

002-schematic.JPG

Pin configure (of DIN)

I bundled 5 pins into 1 pin(s) component with 1 irq.

To use falling event as interrupt, I configured the pin resistor pull-up.

003-pin_config1.JPG

And I set Interrupt Falling edge.

004-pin_config2.JPG

Pins

005-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"

#define STR_BUF_LEN 64
char str[STR_BUF_LEN+1] ;
void print(char *str)
{
    UART_PutString(str) ;
}

volatile int pin_intr_flag = 0 ;
volatile uint8_t pin_intr_src=0 ;

CY_ISR(pin_isr)
{
    pin_intr_flag = 1 ;
    pin_intr_src=DIN_ClearInterrupt() ;
}

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    UART_Start() ;
    print("\x1b[2J\x1b[;H") ;
    print("PSoC 5LP Pin Interrupt Test ") ;
    snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
    print(str) ;
    
    /* DIN_INTR_ALL or DIN_0_INTR | DIN_1_INTR | DIN_2_INTR | DIN_3_INTR | DIN_4_INTR */
    DIN_SetInterruptMode(DIN_INTR_ALL, DIN_INTR_FALLING) ; 
    
    DIN_ClearInterrupt() ;
    isr_1_ClearPending() ;
    isr_1_StartEx(pin_isr) ;
}


int main(void)
{
    uint8_t intr_src=0 ;
    
    init_hardware() ;

    for(;;)
    {
        if (pin_intr_flag) {
            intr_src=pin_intr_src ;
            pin_intr_flag = 0 ;
            
            print("PIN ") ;
            
            if (intr_src & 0x01) { /* DIN_0 pushed */
                print("0 ") ;
            }
            if (intr_src & 0x02) { /* DIN_1 pushed */
                print("1 ") ;
            }
            if (intr_src & 0x04) { /* DIN_2 pushed */
                print("2 ") ;
            }
            if (intr_src & 0x08) { /* DIN_3 pushed */
                print("3 ") ;
            }
            if (intr_src & 0x10) { /* DIN_4 pushed */
                print("4 ") ;
            }
            
            print("pushed \n\r") ;
            CyDelay(20) ;
        }
    }
}

Tera Term log

001-TeraTerm-log.JPG

I hope this can be some hint for you.

moto

 

 

0 Likes

I have already designed my PCB with pins connected to P5_0-P5_6, is there a way to use these pins?

 

Thanks,

Roy Roif

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I think that if you change the pin assignment in Pins to fit your hardware,

above trick should work for you.

It was only I could not use P5[0] ~ P5[6] with my CY8CKIT-059.

moto

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Roy,

Maybe it is as simple as:

Len_CONSULTRON_0-1620129860803.png

This doesn't work on all PSOCs.  However it does work on the CY8CKIT_059.

It may not be as efficient as the port HW interrupt but this allows you to individualize ISRs.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

ok I will try that, and which commands should i add for the interrupts?

0 Likes

Roy,

It would be the exact same commands you were planning on using in your posted example.

For example:

CY_ISR(isr1)
{
/* Your ISR code here */
}
CY_ISR(isr2)
{
/* Your ISR code here */
}

main()
{
...
isr_1_StartEx(&isr1);
isr_2_StartEx(&isr2);
...
}
Len
"Engineering is an Art. The Art of Compromise."
0 Likes
RoRo_4659551
Level 4
Level 4
25 replies posted 10 replies posted 10 likes given

Hi All,

I tried to use both suggested methods  but the failure still occurs.

 

Thanks,

Roy Roif

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Would you let us know the device you are using?

And also what kind of failure you are getting now?

moto

0 Likes
RoRo_4659551
Level 4
Level 4
25 replies posted 10 replies posted 10 likes given

I am using CY8C5467AXI-LP108 and im getting the same failures as mentioned in the main post.

"apr.M0038:IO "DIN_O2(0)" cannot be placed into "P5[1]" because it has an interrupt that conflicts with another interrupt already in this port. Pick a different place for this IO."

 

Thanks,

Roy Roif

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,

As I wrote in my previous post, if you have an interrupt with pin P5[x], 

interrupt for P5[1] may not be redefined.

Anyway, I tried to create a sample with your device.

schematic

Note: This assumes that all the pins are connected to a low-active switch(es),

so I added a "NOT" between pin and isr.

I assigned 12[6] and 12[7] for UART pins.

Change them if you are assigning them to other pins.

010-schematic.JPG

Pins

011-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"

#define STR_BUF_LEN 64
char str[STR_BUF_LEN+1] ;
void print(char *str)
{
    UART_PutString(str) ;
}

volatile int pin1_flag = 0 ;
volatile int pin2_flag = 0 ;
volatile int pin3_flag = 0 ;
volatile int pin4_flag = 0 ;
volatile int pin5_flag = 0 ;
volatile int pin6_flag = 0 ;
volatile int pin7_flag = 0 ;

CY_ISR(pin1_isr)
{
    pin1_flag = 1 ;
    isr_1_ClearPending() ;
}

CY_ISR(pin2_isr)
{
    pin2_flag = 1 ;
    isr_2_ClearPending() ;    
}

CY_ISR(pin3_isr)
{
    pin3_flag = 1 ;
    isr_3_ClearPending() ;
}

CY_ISR(pin4_isr)
{
    pin4_flag = 1 ;
    isr_4_ClearPending() ;    
}

CY_ISR(pin5_isr)
{
    pin5_flag = 1 ;
    isr_6_ClearPending() ;    
}

CY_ISR(pin6_isr)
{
    pin6_flag = 1 ;
    isr_6_ClearPending() ;    
}

CY_ISR(pin7_isr)
{
    pin7_flag = 1 ;
    isr_7_ClearPending() ;    
}


void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    UART_Start() ;
    print("\x1b[2J\x1b[;H") ;
    print("PSoC 5LP Multi Pins Interrupt Test ") ;
    snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
    print(str) ;
    
    isr_1_StartEx(pin1_isr) ;
    isr_2_StartEx(pin2_isr) ;
    isr_3_StartEx(pin3_isr) ;
    isr_4_StartEx(pin4_isr) ;
    isr_5_StartEx(pin5_isr) ;
    isr_6_StartEx(pin6_isr) ;
    isr_7_StartEx(pin7_isr) ;    
}

int main(void)
{
    init_hardware() ;

    for(;;)
    {
        if (pin1_flag) {
            pin1_flag = 0 ;
            print("Pin1 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin2_flag) {
            pin2_flag = 0 ;
            print("Pin2 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin3_flag) {
            pin3_flag = 0 ;
            print("Pin3 was pressed\n\r") ;
            CyDelay(100) ;
        }        
        if (pin4_flag) {
            pin4_flag = 0 ;
            print("Pin4 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin5_flag) {
            pin5_flag = 0 ;
            print("Pin5 was pressed\n\r") ;
            CyDelay(100) ;
        }
        if (pin6_flag) {
            pin6_flag = 0 ;
            print("Pin6 was pressed\n\r") ;
            CyDelay(100) ;
        }          
        if (pin7_flag) {
            pin7_flag = 0 ;
            print("Pin7 was pressed\n\r") ;
            CyDelay(100) ;
        }          
    }
}

At least this project could be built without error.

(But I could not test it, as I don't have a board with that device).

moto