We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, There is a strange behavior in my project. I declare a global variable SwitchToBtFlag in project.h
#ifdef _project_c_ #define AUTOEXT #else #define AUTOEXT extern #endif, AUTOEXT volatile bit SwitchToBtFlag; #undef AUTOEXT
void fun_a( void ) { … if( condition ) SwitchToBtFlag = 1; else SwitchToBtFlag = 0; … } void fun_b( void ) { … if( SwitchToBtFlag ) { SwitchToBtFlag = 0; … } }
Richard, I found out what went wrong. Sorry, it is my mistake. I fogot that an ISR also accessed the flag. That is why the flag was altered unexpectedly. Thanks for your help. chao.
"fogot that an ISR also accessed the flag" For future reference, the uVision Source Browser would have shown that up immediately! It'd be worth your while getting to know it now...!
Hi, I had another global variable that was enum type. When it was located in xdata space (the default addressing mode, large mode) the content would be altered by something. I tried to find out what altered it and got nothing. I am sure that it was not altered by stack overflowing, ISR or main stream functions. But, when I placed (using data) it in data space it was okay. What are the possible reasons for that? Thanks for answering my question. chao.
You could see that effect from an array index out of bounds, or bad pointer, potentially anywhere in the code. Moving the variable doesn't really fix the problem, but does change what gets stepped on. Check the old address of the variable in xdata and see if it is being written to. If you have an ICE with trace capability, (or a logic analyzer, if your xdata is really external), go back to the old code and set it up to trap writes to that address. Then see what address in the code is writing where it shouldn't.