网上说6410的iic驱动有些问题,根据网上的资料修改了一下驱动后,用网上下载的一个exe测试程序随便读写都没有任何问题,网址如下:http://download.csdn.net/source/1488970
后来我自己研究下驱动后,根据自己的理解写了一个测试的代码,可以读写,但是读写的数据很不正常。代码如下:请做过的高手指点错误:
DWORD
HW_WriteRegisters(
PUCHAR pBuff, // Optional buffer
UCHAR StartRegs,
DWORD nRegs // number of registers
)
{
UCHAR tmpbuf[512];
DWORD dwErr=1;
DWORD bytes;
IIC_IO_DESC IIC_Data;
tmpbuf[0]=StartRegs;
memcpy(&tmpbuf[1],pBuff,nRegs);
IIC_Data.SlaveAddress = CAMERA_WRITE;
IIC_Data.Count = nRegs;
IIC_Data.Data = tmpbuf;
// use iocontrol to write
if ( !DeviceIoControl(hI2C,
IOCTL_IIC_WRITE,
&IIC_Data, sizeof(IIC_IO_DESC),
NULL, 0,
&bytes, NULL) )
{
dwErr = 0;
}
return dwErr;
}
DWORD
HW_ReadRegisters(
PUCHAR pBuff, // Optional buffer
UCHAR StartReg, // Start Register
DWORD nRegs // Number of Registers
)
{
DWORD dwErr=1;
DWORD bytes;
IIC_IO_DESC IIC_AddressData, IIC_Data;
IIC_AddressData.SlaveAddress = CAMERA_WRITE;
IIC_AddressData.Data = &StartReg;
IIC_AddressData.Count = 1;
IIC_Data.SlaveAddress = CAMERA_WRITE;
IIC_Data.Data = pBuff;
IIC_Data.Count = 1;
// use iocontrol to read
if ( !DeviceIoControl(hI2C,
IOCTL_IIC_READ,
&IIC_AddressData, sizeof(IIC_IO_DESC),
&IIC_Data, sizeof(IIC_IO_DESC),
&bytes, NULL) )
{
dwErr = 0;
}
return dwErr;
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD i;
UCHAR bufin[100];
UCHAR bufout[100];
DWORD nbyte=100;
DWORD bytes;
UCHAR StartAddr=0x2;
UINT32 IICClock = 412500;
UINT32 uiIICDelay;
for(i=0;i<100;i++)
bufin[i]=0;
bufin[0]=0x5;
hI2C = CreateFile( L"IIC0:",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
if ( INVALID_HANDLE_VALUE == hI2C )
{
MessageBox (0,TEXT("Open Error!"),NULL,MB_OK);
return FALSE;
}
else
{
MessageBox (0,TEXT("Open !"),NULL,MB_OK);
}
if ( !DeviceIoControl(hI2C,
IOCTL_IIC_SET_CLOCK,
&IICClock, sizeof(UINT32),
NULL, 0,
&bytes, NULL) )
{
RETAILMSG(1,(TEXT("IOCTL_IIC_SET_CLOCK ERROR: %u \r\n")));
return FALSE;
}
uiIICDelay = Clk_5;
if ( !DeviceIoControl(hI2C,
IOCTL_IIC_SET_DELAY,
&uiIICDelay, sizeof(UINT32),
NULL, 0,
&bytes, NULL) )
{
RETAILMSG(1,(TEXT("IOCTL_IIC_SET_DELAY ERROR: %u \r\n")));