UART Rx interrupt handling fail

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

cross mob
lock attach
Attachments are accessible only for community members.
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
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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
Anonymous
Not applicable

Thanks Bob! Now it works.

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

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
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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