我正在为 MSP430 微 Controller 编写嵌入式 C 代码,但我遇到了返回错误值的函数。当我使用调试器单步执行代码时,它显示该函数应该返回 1,但它在设置的 int 上返回 0。
代码:
void sendUart(unsigned char string[], int length){
if(string != 0){
while(~responseAOK()){
int BLEstatus = BLEReadyForData(); **//Function called here**
if(BLEstatus){ **//At this point, BLEstatus is 0 (incorrect)
unsigned int i;
for(i=0;i<length-1;i++){
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = string[i];
send[sendIndex] = string[i];
sendIndex++;
}
sendIndex = 0;
}
}
}
}
int BLEReadyForData(){
if(P2DIR & BIT3){
P2DIR &= ~BIT3;
}
if(P2IN & BIT3){
return 1; //debugger step-through reaches this line of code
}
else return 0;
}
最佳答案
您应该首先关闭优化。它使逐步调试变得困惑。 例如,在 IAR 中是
Project -> Options -> C/C++ Compiler -> Optimizations tab -> Level -> None
关于尽管调试器显示 C 函数返回 1,但它仍返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55671793/