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.
Use the <pre> and </pre> tags when posting code. You seem to have mis-typed the code when you posted it:
volatile uchar SerBuffer; : SerBuffer[I_ptr & (DATALTH -1)] = c; : memset(SerBuffer,0x00,DATALTH);
I'm sorry for mis-type. In fact, I define "SerBuffer" with volatile uchar SerBuffer[DATALTH]; Thanks.
I don't know exactly if it's going to solve your problem or not but, when I was glancing your code something caught my attention...
void isr_UART(void) interrupt SIO_VECTOR using 0
If as you thought, why Keil not push all the variables which are used in normal progress into stack when interrupt occur. I'l test as you said. Thanks
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.