How to disable the interrupts in ISR for UART

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

cross mob
ShNa_1340526
Level 1
Level 1
First like given Welcome!

Hi all,

I am using some ISR for UART UART SCB Mode ver 3.2 and using the following code

uint8 flag = 0;

CY_ISR(uartInterrupt)

{

    uint32 source = 0;

     flag = 1;

   

    UART_UartPutString("\nFlag = 1\r\n");

    source = UART_GetRxInterruptSourceMasked();

    UART_ClearRxInterruptSource(source);

   

    UART_UartPutChar(UART_UartGetChar());

    /* `#END` */

}

int main()

{

   

     uint32 ch;

    UART_Start();

    UART_SCB_IRQ_StartEx(uartInterrupt);

    //UART_RX_ISR_StartEx(uartInterrupt);

   

    /* Transmit string through UART */

    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */

 

    UART_UartPutString ("\r\n***********************************************************************************\r\n");

    UART_UartPutString ("UART Initialisedr\r\n");

    for (;;)

    {

        ch = UART_UartGetChar();

         if(flag == 1)

        {

          flag = 0;

          ch = UART_UartGetChar();

          UART_UartPutChar(ch);

          UART_UartPutString("\nFlag = 0\r\n");

        }     

    }

}

Observation :

1. Control is not coming out from ISR "CY_ISR(uartInterrupt)"

2. Could not able to clear interrupt

Please help

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

Generally:

Do not use lengthy code in an interrupt handler. Sending data over the UART is very slow compared to normal CPU speed.

Do not recurse in an interrupt handler. It is not quite clear due to some missing information if you do something like that.

Every global variable that is changed in an interrupt handler should be declared as "volatile". so you need

volatile uint8 flag = 0;

This will prevent you from compiler optimizing-out redundant accesses to the variable flag. See here.

Can you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

View solution in original post

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

Generally:

Do not use lengthy code in an interrupt handler. Sending data over the UART is very slow compared to normal CPU speed.

Do not recurse in an interrupt handler. It is not quite clear due to some missing information if you do something like that.

Every global variable that is changed in an interrupt handler should be declared as "volatile". so you need

volatile uint8 flag = 0;

This will prevent you from compiler optimizing-out redundant accesses to the variable flag. See here.

Can you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes
lock attach
Attachments are accessible only for community members.

Thanks for reply and suggestion i will change in code as volatile uint8 flag = 0;

0 Likes

Hi Bob

Can you address the issue with ref to attached code?

Sham

0 Likes