尽管调试器显示 C 函数返回 1,但它仍返回 0

标签 c embedded msp430

我正在为 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/

相关文章:

c - "static/extern uint8_t array[2] = {0};"是否符合 ANSI C 规范?

c - 如何在 Windows 中将 linux header 添加到 Eclipse CDT

linux - 为嵌入式Linux发行版(openwrt)编译软件

linux - 我可以使用 USB 转串口适配器与我的 VMWare Fusion 开发板通信吗?

java - 您使用 ARM Jazelle 的体验如何?

c - C 中的大数组初始化问题

c++ - 复制跨步数据(进出 CUDA 设备)的有效方法?

c - 如何在64位机器下将libxml2和libcurl编译成32位?

c - 数字的 X 根

c - 带 CC430F6137 的 ModBUS RTU