This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why not clear buffer

Please help me to find the problem:

In my program, I use UART to receive data by UART interrupt, please see following.

#define uchar unsigned char
#define DATALTH 255

volatile uchar SerBuffer;
volatile uchar I_ptr;

void isr_UART(void) interrupt SIO_VECTOR using 0
{
uchar c;

if(RI)
{
c = SBUF;
RI = FALSE;
SerBuffer[I_ptr & (DATALTH -1)] = c;
}
}

But when I use
memset(SerBuffer,0x00,DATALTH);
or
Addr = strchr(SerBuffer,0x22);
to clear "SerBuffer" or search
0x22 from "SerBuffer" and during the progress there are data received by UART, then there will be serious error.

Please tell me the reason.
thank you.

Parents
  • why Keil not push all the variables which are used in normal progress into stack when interrupt occur.?

    Keil didn't push and pop all the variables because you desired when you added the using X keyword.

    The compiler switch the register bank ( PSW , so it doesn't need to push and pop the registers during the ISR, with this operation you save some bytes ( that is vital in some applications ) and execution speed.

    You can "let" the compiler use PUSHs and POPs, you need to use a directive and delete the using X keyword from your function, prototypes and so on.

Reply
  • why Keil not push all the variables which are used in normal progress into stack when interrupt occur.?

    Keil didn't push and pop all the variables because you desired when you added the using X keyword.

    The compiler switch the register bank ( PSW , so it doesn't need to push and pop the registers during the ISR, with this operation you save some bytes ( that is vital in some applications ) and execution speed.

    You can "let" the compiler use PUSHs and POPs, you need to use a directive and delete the using X keyword from your function, prototypes and so on.

Children
No data