/***************************************************************************** ** Function Name: IIC_WritePage() ** Descriptions: 写一页数据 ** Input: SlvAddr IIC从机地址 ** MemAddr 要写数据开始地址 ** pData 要写的数据 ** Count 要写的字节数 ** Output: ** Returned: *****************************************************************************/ void IIC_WritePage(INT32U SlvAddr, INT32U MemAddr, INT8U *pData, INT32U Count) { INT32U i,tmp; if(Count > IIC_Page_Size) { return; } pIIC->IICCON=(1<<7)|(0<<6)|(1<<5)|(0xf); pIIC->IICDS = SlvAddr; // 从器件地址 0xa0 pIIC->IICSTAT = 0xf0; // MasTx,Start while(!((pIIC->IICCON)&IIC_TXRXINT_PEND)); // 等待发送完从器件应答 //while((pIIC->IICSTAT)&IIC_RXACK); // 等待 应答 pIIC->IICDS = (MemAddr>>8)&0xff; // 高8位地址 for(i=0; i<10; i++); //for setup time until rising edge of IICSCL pIIC->IICCON = 0xaf; //resumes IIC operation. while(!((pIIC->IICCON)&IIC_TXRXINT_PEND)); // 等待发送完从器件应答 //while((pIIC->IICSTAT)&IIC_RXACK); // pIIC->IICDS = (MemAddr)&0xff; // 低8位地址 for(i=0; i<10; i++); //for setup time until rising edge of IICSCL pIIC->IICCON = 0xaf; //resumes IIC operation. //while(!((pIIC->IICCON)&IIC_TXRXINT_PEND)); // 等待发送完从器件应答 //while((pIIC->IICSTAT)&IIC_RXACK); // 写入地址发送完 while(1) { while(!((pIIC->IICCON)&IIC_TXRXINT_PEND)); // 等待发送完从器件应答 //while((pIIC->IICSTAT)&IIC_RXACK); //for(i=0; i<2; i++); if((Count--)==0) { pIIC->IICSTAT = 0xd0; //stop MasTx condition pIIC->IICCON = 0xaf; //resumes IIC operation. for(i=0; i<800; i++); //wait until stop condtion is in effect. //The pending bit will not be set after issuing stop condition. break; } pIIC->IICDS = *pData; //_iicData[0] has dummy. pData++; for(i=0; i<10; i++); //for setup time until rising edge of IICSCL pIIC->IICCON = 0xaf; //resumes IIC operation. } while(1) { pIIC->IICDS = SlvAddr; // 从器件地址 0xa0 pIIC->IICSTAT = 0xf0; // MasTx,Start pIIC->IICCON = 0xaf; //resumes IIC operation. while(!((pIIC->IICCON)&IIC_TXRXINT_PEND)); // 等待发送完从器件应答 //while((pIIC->IICSTAT)&IIC_RXACK); // 等待 应答 if(!((pIIC->IICSTAT)&IIC_RXACK)) { break; } } pIIC->IICSTAT = 0xd0; //stop MasTx condition pIIC->IICCON = 0xaf; //resumes IIC operation. for(i=0; i<800; i++); }
IIC采用软件查询中断的方式, 出现后部分数据写入错误,请大家看看问题在哪?谢谢了! |