cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

Hello,

   

I made a simple app to play with interrupt handling. In loop it increments a counter and it's value is sent to UART.

   

When a byte is received on UART an ISR is called and the counter should be reset. By some reason the app works until a byte is received and than it hangs. The app hangs even if ISR has no code at all. Here is my code:

   

 main.c:

   

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include <stdio.h>

#pragma interrupt_handler uartIsrRx;

unsigned char counter;

void main(void)
{
    unsigned int i;
    unsigned char str[16];
   
    M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
    UART_Start(UART_PARITY_NONE);
    UART_IntCntl(UART_ENABLE_RX_INT);
   
    while (1)       
    {
        counter++;
        csprintf(str, "c=%d\r\n", (int)counter);
        UART_PutString(str);
        for (i=0; i!=20000; i++);   
    }
}

void uartIsrRx(void )
{
    counter=0;
}

   

 

   

UARTINT.asm:

   

 _UART_RX_ISR:

...
... 
   ;---------------------------------------------------
   ; Insert a lcall to a C function below this banner
   ; and un-comment the lines between these banners
   ;---------------------------------------------------
   
   PRESERVE_CPU_CONTEXT
   lcall _uartIsrRx
   RESTORE_CPU_CONTEXT
   reti

   

Attachment:

   

UART and PSoC global settings.

   

 

   

Best Regards

0 Likes
Reply
4 Replies
JoMe_264151
Expert II

This is now done twice: remove the #pragma

   

or

   

change the code in UARTINT.asm to just a

   

LJMP _UARTIsrRx

   

 

   

In both of your original code-sections you issue a return from interrupt which pops one byte more from the stack than a simple return. So your stack gets clobbert and nothing runs anymore.

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

Thanks Bob! Now it works.

0 Likes
Reply
JoMe_264151
Expert II

Congratulations!

   

Did you ever consider using a PSoC 4? There is the Pioneer Kit which is low-cost and has debugging capabilities (Breakpoints, variable inspection) which your PSoC1 Kit hasn't got. Additionally there is a 4$ Prototyping kit onto which you can load your debugged projects.

   

 

   

Bob

0 Likes
Reply
ETRO_SSN583
Esteemed Contributor

http://www.cypress.com/?rid=77780     Pioneer Kit

   

 

   

http://www.cypress.com/?rID=92146     PSoC 4 CY8CKIT-049 4xxx Prototyping Kits

   

 

   

 

   

Regards, Dana.

   

 

   

   

 

   

 

   

CY8CKit-049

0 Likes
Reply