This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

程序遇到判断语句时,不执行,而且无法插入中断,不知道什么原因



while(I2cBus.MsgStatus != I2C_MSGSTAT_INACTIVE)

{

temp = I2cBus.MsgStatus;

if(temp == I2C_MSGSTAT_SEND_NOSTOP)

{

// Send Address

  // Wait until the STP bit is cleared from any previous master communication.

  // Clearing of this bit by the module is delayed until after the SCD bit is

  // set. If this bit is not checked prior to initiating a new message, the

  // I2C could get confused.

I2cBus.BusStatus = I2C_BUS_ACTIVE;

while(I2C_WriteAddr(DataAddr) != I2C_SUCCESS)

{

}

// for(i=0; i<1000; i++);

I2cBus.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY;

}

else if(temp == I2C_MSGSTAT_RESTART)

{

I2caRegs.I2CSAR = AT24C256_ADDR;

I2caRegs.I2CCNT = 8; // Setup how many bytes to expect

// Update message status

I2cBus.MsgStatus = I2C_MSGSTAT_READ_BUSY;

I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver

}

}

下面这个判断一直不执行,不知道什么原因;

CCS5.1的编译器

else if(temp == I2C_MSGSTAT_RESTART)

{

}

  • 说明这个条件永远不成立if(temp == I2C_MSGSTAT_RESTART)

    编译器在编译到不可能成立的条件时,会跳过这段代码,所以你也不能设置断点

    检查一下temp,看看其值能否为I2C_MSGSTAT_RESTART