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.
您好,我现在使用的是28035官方IIC例子,没有改动,EEPROM是24C02,现在调试过程遇到一个问题,正常写2个数据,读回2个数据 都正常,比如写0x01,0x02,读回来也是0x01,0x02,但是在程序中我写4个数据0x01,0x02,0x03,0x04后,在读回来后返回0x02,0x03,0x04,0x04,读回来的值不对,slave地址:0x50,数据地址:0x00,读写数据地址相同,使用SCD和ARDY中断方式。下面是程序,哪位大虾帮忙解决一下
写函数:
Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
Uint16 i;
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}
I2caRegs.I2CSAR = 0x50
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = msg->NumOfBytes+2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
for (i=0; i<msg->NumOfBytes; i++)
{
I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
}
I2caRegs.I2CMDR.all = 0x6EA0;
return I2C_SUCCESS;
}
读函数:
Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// 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;
}
I2caRegs.I2CSAR = msg->SlaveAddress;
if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620;//0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}
return I2C_SUCCESS;
}
几年以前的事的,我当时是调好的。就是用TI的例程。 当时调的是用256的EEPROM不调的。 在使用例程时对例程做了修改,反而调不通。最后回复到原来的状态反而就可以了,不用管FIFO。主要是要理解例程中的那个状态机。
我在e2e.ti.com的 C2000论坛中和一个老外有讨论。你也可以进入这个论坛去看看。那里是24小时必回,都是TI的FE大牛 。
国内的论坛我基本下上了,因为这里FE还没有你懂。懂的也不会应你的,人家都是经理。