我正在为MSP430微控制器编写嵌入式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;
}
答案 0 :(得分:0)
您应该先关闭优化。它使逐步调试变得混乱。 例如,在IAR中是
Project -> Options -> C/C++ Compiler -> Optimizations tab -> Level -> None