i2c出现这样的错误:ERROR: IIC_Write: send slave address fail!
那一段write的驱动代码是这样的:
DWORD IIC_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
{
UINT32 count, ret;
uchar *pWriteBuffer;
if ((pBuffer == NULL) || (dwNumBytes <= 0))
return 0;
pWriteBuffer = MapPtrToProcess((LPVOID)pBuffer, GetCallerProcess());
// 设置从机地址及当前状态
I2cCurSla = I2cSla;
I2cStatus = I2C_STATUS_SETADDR;
StartI2C(I2cCurSla);
ret = WaitForSingleObject(gI2CEvent, I2C_RW_TIMEOUT); /* 挂起当前线程,直到IIC中断的产生 */
ResetEvent(gI2CEvent);
if ((IICError != I2C_ERROR_NO_ERR) || (ret != WAIT_OBJECT_0))
{
RETAILMSG(1, (TEXT("ERROR: IIC_Write: send slave address fail! \r\n")));
return 0;
}
I2cStatus = I2C_STATUS_SEND; // 进入发送状态
for (count = 0; count < dwNumBytes; count ++)
{
IIC_SendByte(*pWriteBuffer); /* 启动I2C总线,发送在中断中进行 */
pWriteBuffer++;
/* 挂起当前线程,直到IIC中断的产生 */
ret = WaitForSingleObject(gI2CEvent, I2C_RW_TIMEOUT);
ResetEvent(gI2CEvent);
if (ret != WAIT_OBJECT_0)
{
RETAILMSG(1, (TEXT("ERROR: IIC write data fail! \r\n"))); return count;
}
if (IICError != I2C_ERROR_NO_ERR)
{
RETAILMSG(1, (TEXT("ERROR: IIC_Write: send data fail! \r\n")));
break;
}
}
StopI2C(1);
return count;
}
我分析了一下,应该是主机发出IIC_START信号(命令)后等待从机ACK,超时,但为什么会出现这样呢,我的硬件用的是ZLG7290都是好的啊,在linux环境下是正常的。请大牛们指点一下