CY8C4025AZI-S413 Gloabal variables in ISR not getting updated

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.
habe_4632221
Level 1
Level 1

Hello,

We are implementing UART and timer peripherals using interrupt

At Power ON variables/flags which are used in UART or Timer ISR are declared as '0' and in ISR value for these variables is set to '1' on ISR successful execution of ISR. Though variables are getting updated in ISR but their updated values are not available in main loop or other functions.

Variables are defined as 'Volatile' even tried with no optimization option but still remains same.

Code is tested with PSoC created 4.1 and PSoC created 4.3.

Please help to resolve the issue.

Code for timer and UART is attached for reference

With Regards,

Harshal Belan

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

Hi,

By any chance, have you seen following topic?

global variables updated in ISR does not updated in main loop

I wonder if the attachment of my last response can work for you or not.

The main.c was

=================

#include "project.h"

volatile uint8 gb_char = 0;

volatile char flag = 0 ;

CY_ISR(Uart_Rx_Interrupt)

{

    UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY) ;

    if (UART_SpiUartGetRxBufferSize()) {

        gb_char = UART_UartGetChar();

        if(gb_char == 0x23)

        {

            flag = 1;

            UART_SpiUartWriteTxData(gb_char);

        }

    }

}

void Uart_Initialize (void)

{

    UART_Start();

    UART_SpiUartClearRxBuffer() ;

    UART_SpiUartEnableIntRx(UART_INTR_RX_NOT_EMPTY) ;

    Uart_isr_StartEx(Uart_Rx_Interrupt);

}

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    Uart_Initialize();

    for(;;)

    {

        if(flag == 1)

        {

//          flag = 0 ;

            led17_Write(1);

        }

        if(flag == 0)

        {

            led17_Write(0);

        }

    }

}

=================

moto

View solution in original post

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

Hi,

By any chance, have you seen following topic?

global variables updated in ISR does not updated in main loop

I wonder if the attachment of my last response can work for you or not.

The main.c was

=================

#include "project.h"

volatile uint8 gb_char = 0;

volatile char flag = 0 ;

CY_ISR(Uart_Rx_Interrupt)

{

    UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY) ;

    if (UART_SpiUartGetRxBufferSize()) {

        gb_char = UART_UartGetChar();

        if(gb_char == 0x23)

        {

            flag = 1;

            UART_SpiUartWriteTxData(gb_char);

        }

    }

}

void Uart_Initialize (void)

{

    UART_Start();

    UART_SpiUartClearRxBuffer() ;

    UART_SpiUartEnableIntRx(UART_INTR_RX_NOT_EMPTY) ;

    Uart_isr_StartEx(Uart_Rx_Interrupt);

}

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    Uart_Initialize();

    for(;;)

    {

        if(flag == 1)

        {

//          flag = 0 ;

            led17_Write(1);

        }

        if(flag == 0)

        {

            led17_Write(0);

        }

    }

}

=================

moto

0 Likes