首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

三星2440 IIC驱动的有关问题

2012-03-02 
三星2440 IIC驱动的问题因为要控温,所以要不停的通过IIC接口向从机写数据,就出问题了,有时写不进去,查了一

三星2440 IIC驱动的问题
因为要控温,所以要不停的通过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"))); 

}


[解决办法]
能不能写进去跟中断没有关系吧,应该跟时序有关

热点排行