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.
我在进行写操作时,程序一直处在I2caRegs.I2CMDR.bit.STP=1;状态,导致我无法进行写操作,
I2CA_WriteData(struct I2CMSG *msg)
{
int16 i;
while (I2caRegs.I2CMDR.bit.STP == 1)
{
return i_ERROR;
}
}
我再单步调试例子程序时,进行写操作:当运行完I2caRegs.I2CMDR.all = 0x6E20;-----当运行完这一步后,我通过watch window,看,为何I2caRegs.I2CMDR.all = 0x4220?,请看源程序:
Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
Uint16 i;
// 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.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}
// Setup slave address
I2caRegs.I2CSAR = msg->SlaveAddress;
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
// Setup number of bytes to send
// MsgBuffer + Address
I2caRegs.I2CCNT = msg->NumOfBytes+2;
// Setup data to send
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
// for (i=0; i<msg->NumOfBytes-2; i++)
for (i=0; i<msg->NumOfBytes; i++)
{
I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
}
// Send start as master transmitter
I2caRegs.I2CMDR.all = 0x6E20;-----当运行完这一步后,我通过watch window,看,为何I2caRegs.I2CMDR.all = 0x4220?
return I2C_SUCCESS;
}
探索者 说:我再单步调试例子程序时,进行写操作:当运行完I2caRegs.I2CMDR.all = 0x6E20;-----当运行完这一步后,我通过watch window,看,为何I2caRegs.I2CMDR.all = 0x4220?,请看源程序:
Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
Uint16 i;// 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.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}// Setup slave address
I2caRegs.I2CSAR = msg->SlaveAddress;// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}// Setup number of bytes to send
// MsgBuffer + Address
I2caRegs.I2CCNT = msg->NumOfBytes+2;// Setup data to send
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
// for (i=0; i<msg->NumOfBytes-2; i++)
for (i=0; i<msg->NumOfBytes; i++){
I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
}// Send start as master transmitter
I2caRegs.I2CMDR.all = 0x6E20;-----当运行完这一步后,我通过watch window,看,为何I2caRegs.I2CMDR.all = 0x4220?return I2C_SUCCESS;
}
bit13,11置位后自动清零,bit12位为保留位,读取始终为0
硬件加了上拉电阻10k,同样的程序在不同的2808板子上可以,但是在28035上就会I2caRegs.I2CMDR.bit.STP =1,是否等于1软件是无法配置的吧?
Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
Uint16 i;
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}
// Setup slave address
。。。。。。。。。。。。。。。。。。。
}
恩,谢谢,我还发现在ccs中单步调试时 读取数据时 I2caRegs.I2CSTR.bit.ARDY=0;而全速运行模式时 I2caRegs.I2CSTR.bit.ARDY=1,为何有这样的区别啊