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

PSoC™ 4 Forum Discussions

SaWa_284216
Level 4
Level 4

 I have searched around but have not found an answer on how to do this.

   

I read the SCB documenation but the interrupt information doesn't make much sense to me.

   

What I want is to have an interrupt fire on every byte received.

   

I have attached an external interrupt (I think this is the right one, it says for 8 bytes or less use an external)

   

In advanced I have selected RX FIFO not empty and RX FIFO full. The UART is working but it just does not seem to fire the interrupt.

   

I have attached my code if someone can spot the error.

0 Likes
30 Replies
SaWa_284216
Level 4
Level 4

 Another problem I have is that I cannot place a hardware breakpoint on the interrupt file.

   

I am using the USB debugger on the PSoC 4 Pioneer but I have also tried my miniprog3. Both just won't place a hardware breakpoint on the ISR. It offers to replace them with software ones but they don't break..

   

This is with no other breakpoints on the project

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

I do nto see where you issued a -

   

 

   

UART_RX_FULL_Start( );

   

 

   

Regards, Dana.

0 Likes
SaWa_284216
Level 4
Level 4

 Hi Dana

   

Thanks for the reply

   

You are right I missed that off, but I have since added it and now I can put breakpoints on the ISR.

   

However the ISR is still not firing or changing the flag.  😞

0 Likes
SaWa_284216
Level 4
Level 4

 Attached is my updated project 

0 Likes
Bob_Marlowe
Level 10
First like given 50 questions asked 10 questions asked
Level 10

You misunderstood how the interrupts work. Fot the UA<Rt the interrupt is a pure signal to which you connect an interrupt handler as you did. This module has to be initializes preferrably with isr_StartEX(YourHandler).

   

Declare and define the handler with

   

CY_ISR_PROTO(YourHandler);

   

and

   

CY_ISR(YourHandler)

   

{

   

// Check UART Status

   

// Remove cause of interrupt (Reading received Bytes until FIFO empty

   

}

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

You should declare the flag as volatile -

   

 

   

    

   

          http://www.barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

Bob, why can't he use the place holder ISR function tool generates ? Where

   

he set the flag......

   

 

   

Regards, Dana.

0 Likes
SaWa_284216
Level 4
Level 4

 I am not sure how to do what Bob has suggested

   

But I have now added the volatile keyword on both the main.c and on the interrupt "extern uint8 volatile flag"

   

I've attched the updated code again but it is only this keyword which has changed. 

   

The code inside the "if(flag == 1)" loop never gets called.

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

The new bundle you posted just has timer based projects in it,

   

not UART we were working on ?

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
First like given 50 questions asked 10 questions asked
Level 10

@Dana

   

He CAN use it when using it correctly. He had an ist component dropped onto the schematic which he did not use and an interrupt handler within the component he did not use neither because the interrupt was not explicitely enabled.

   

So I pointed out the usual working approach that always leads to success by using the  isr_StartEx() and CY_INT().

   

@Sam

   

Lookup "CY_ISR" keyword in the "System Reference Guide" (from Help-Menu) and check the APIs in the isr-datasheet.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

On the schematic he dropped ISR component named UART_RX_FULL, and in the

   

UART_RX_FULL.c file generated by tool is a placeholder where he added the flag = 1; statement -

   

 

   

CY_ISR(UART_RX_FULL_Interrupt)
{
    /*  Place your Interrupt code here. */
    /* `#START UART_RX_FULL_Interrupt` */
    flag = 1;

    /* `#END` */
}

   

 

   

And then enabled it in main (globals enabled as well).

   

So what is wrong with this ? What am I missing ?

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

He had enabled it in main() after I indicated he should do so.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
First like given 50 questions asked 10 questions asked
Level 10

I did not have the latest workspace bundle. So latest update's interrupt should work

   

if

   

in the interrupt routine the cause of interrupt is not removed, ie the character is not red off.

   

in main() any characters are continously red, so interrupts may not happen.

   

I would suggest to

   

read the UART Rx-status within the interrupt routine to clear sticky status-bits

   

read the character within the interrupt routine to a global char when status indicated fifo not full

   

 

   

Bob

0 Likes
SaWa_284216
Level 4
Level 4

 Hi guys 

   

Sorry about the delay, Thanks for all the help by the way

   

I have tried to read the status as you suggested but I am not sure I am using the right command, anyway the code still never gets into the flag bit so the flag isn't being set.

   

I have attached the up to date workspace bundle, I don't know what happened with the last one.

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

This seems to indicate no need for clearing interrupts as you are in external mode.

   

 

   

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

Doesn't one have to uncomment the #START and #END in the ISR placeholder ?

   

 

   

*******************************************************************************/
CY_ISR(UART_RX_FULL_Interrupt)
{
    /*  Place your Interrupt code here. */
    /* `#START UART_RX_FULL_Interrupt` */
    flag = 1;
    UART_rx_Read(); // Clear interrupt?


    /* `#END` */
}

   

 

   

Regards, Dana.
 

0 Likes
SaWa_284216
Level 4
Level 4

 When I try to uncomment them I get a syntax error..

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

Don't uncomment the lines, my mistake.

   

 

   

I see the following note in this ap note (AN54460) -

   

 

   

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

I looped back Tx to Rx pin, set isr to level triggered, and I am hitting

   

breakpoint in interrupt routine. Not looped back I am still hitting

   

BP. I assume thats becuse FIFO not emptied.

   

 

   

Setting ISR back to derived not interrupt..

   

 

   

Regards, Dana.

0 Likes
SaWa_284216
Level 4
Level 4

 Hi Dana

   

You are right the interrupt is firing when I do a loop back test and use level triggered interrupts.

   

New problem though, it never gets out of the interrupt! the read doesn't clear the interrupt it seems.

   

Thankyou so much for experimenting with me, I so wanna use Cypress stuff but I keep finding niggles

0 Likes
ETRO_SSN583
Level 9
100 sign-ins 5 likes given 1000 replies posted
Level 9

But doesn't this code -

   

 

   

    for(;;)
    {
        TX_LED_Write(1);
        ch = UART_UartGetChar();
         
        if(flag == 1)
        {
          flag = 0;
          UART_UartPutChar(ch);
          TX_LED_Write(0);      
        }     
    }
 

   

When first char received, flag gets set, you then read out of fifo (emptying it), and then

   

you put char right back into fifo causing another interrupt ?

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Hi Sam,

   

I am experience the same problem as you - I am comfirming with my logic analyzer that data is coming in on the RX line, I have also confirmed that if I write something to the TX line using UART_UartPutChar(tx_data), data is transmited. My uart_isr interrupt never gets activated. Have you found a solution to yours yet?

   

 

   

All the Best,

   

Katrine

0 Likes
SaWa_284216
Level 4
Level 4

 Hi all

   

FIXED IT!

   

Well someone from Cypress helped me fix it.. The problem I was having was as Dana suggested I was trying to put a character out before I checked for the flag, I also was not properly clearing the source of the interrupt..

   


The cypress applications engineer showed me how to properly check for the source of the interrupt and to clear it, since doing this it is working perfectly.

   

I have attached the bundle.

   

Just want to say a big thankyou to everyone in the thread for their help 🙂

0 Likes
SaWa_284216
Level 4
Level 4

 For those who don't want to download the project here is my main loop

   

http://pastebin.com/nhvGWwyS

   

and here is my interrupt code

   

http://pastebin.com/v8bcusBx

0 Likes
Anonymous
Not applicable

 Great work! 

   

Thank you for sharing

0 Likes
tayoc_301426
Level 1
Level 1
0 Likes
Bob_Marlowe
Level 10
First like given 50 questions asked 10 questions asked
Level 10

@TAKASHI

   

When using IE, switch on the "Compatibility Mode"

   

 

   

Bob

0 Likes
Anonymous
Not applicable
        Missing a definition of "source"?? CY_ISR(UART_RX_ISR_Interrupt) { /* Place your Interrupt code here. */ /* `#START UART_RX_ISR_Interrupt` */ flag = 1; source = UART_GetRxInterruptSourceMasked(); UART_ClearRxInterruptSource(source); /* `#END` */ } Why do I get a tiny little box to write a post? Reminds of those complaint form jokes...   
0 Likes
HeLi_263931
Level 8
100 likes received 50 likes received 25 likes received
Level 8

You need to call SCB_ClearRxInterruptSource (or SCB_ClearTx...) to clear the interrupt flag. (See the SCB datasheet page 116).

0 Likes
Bob_Marlowe
Level 10
First like given 50 questions asked 10 questions asked
Level 10

Look at my last post and play with the "Compatibility mode"

   

 

   

Bob

0 Likes