因为要控温,所以要不停的通过IIC接口向从机写数据,就出问题了,有时写不进去,查了一下是因为IICCON[4]中断位没有清0,不知为什么,哪位高手遇到过这个问题,怎么解决的?
void WrIIC(__u8 slvAddr, __u8 cmd, __u16 data)
{
IICCtrl.iicMode = WRDATA;
IICCtrl.iicPt = 0;
IICCtrl.iicData[0] = (__u8)cmd;
IICCtrl.iicData[2] = (__u8)(data & 0xFF);
IICCtrl.iicData[1] = (__u8)((data & 0xFF00) >> 8);
IICCtrl.iicDataCount = 3;
// RETAILMSG(1, (TEXT("WrIIC::data0 = 0x%x, data1 = 0x%x, data2 = 0x%x\r\n"),
// IICCtrl.iicData[0], IICCtrl.iicData[1], IICCtrl.iicData[2]));
v_pIICregs->rIICDS = slvAddr; //
//Master Tx mode, Start(Write), IIC-bus data output enable
//Bus arbitration sucessful, Address as slave status flag Cleared,
//Address zero status flag cleared, Last received bit is 0
v_pIICregs->rIICSTAT = 0xf0;
//Clearing the pending bit isn't needed because the pending bit has been cleared.
//RETAILMSG(1, (TEXT("WrIIC::test1...\r\n")));
while(IICCtrl.iicDataCount != -1)
Run_IicPoll();
//RETAILMSG(1, (TEXT("WrIIC::test2...\r\n")));
//Delay(5);//延时必须加,大概延时6ms左右
IICCtrl.iicMode = POLLACK;
while(1)
{
v_pIICregs->rIICDS = slvAddr;
IICCtrl.iicStatus = 0x100; //To check if _iicStatus is changed
v_pIICregs->rIICSTAT = 0xf0;//Master Tx, Start, Output Enable, Sucessful, Cleared,Cleared, 0
v_pIICregs->rIICCON = 0xaf; //Resumes IIC operation.
while(IICCtrl.iicStatus == 0x100)
{
Run_IicPoll();
Delay(2);
}
Delay(5);
//if(!(_iicStatus & 0x1))
break; //When ACK is received
}
v_pIICregs->rIICSTAT = 0xd0; //Master Tx condition, Stop(Write), Output Enable
v_pIICregs->rIICCON = 0xaf; //Resumes IIC operation.
Delay(1); //Wait until stop condtion is in effect.
//Write is completed.
// RETAILMSG(1, (TEXT("WrIIC::ok...\r\n")));
}
经过确认,驱动一直在下面两句里循环
while(IICCtrl.iicDataCount != -1)
Run_IicPoll();
函数 Run_IicPoll()如下:
void Run_IicPoll(void)
{
if(v_pIICregs->rIICCON & 0x10) //Tx/Rx Interrupt Enable
IicPoll();
}