using iic in wince6 for ok6410

Umer Munir
Platform Type : SMDK6410
[IIC ERROR]TX Time out.
-IIC_IOControl Error Ecode=1460 (len=0)
[IIC ERROR]TX Time out.
[IIC ERROR]RX Time out.
-IIC_IOControl Error Ecode=1460 (len=0)

i get this error while writing data using iic.

my code is 



HANDLE hIIC;
BOOL bRet;

unsigned char iic_write_buffer = 127;
unsigned char iic_read_buffer = 0;
DWORD bytes;
DWORD dwErr;



  hIIC = CreateFile (L"IIC0:", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); 
  if (hIIC == INVALID_HANDLE_VALUE) {
    MessageBox(L"Unable to open i2c driver", L"Error", MB_OK);
    return;
  }

  UINT32 IICClock2 = 3000;

  bRet = DeviceIoControl(hIIC,IOCTL_IIC_SET_CLOCK,
&IICClock2,sizeof(UINT32),&IICClock2,sizeof(UINT32),&bytes,NULL);

UINT32 uiIICDelay = Clk_0;
    
if ( !DeviceIoControl(hIIC,
                      IOCTL_IIC_SET_DELAY, 
                      &uiIICDelay, sizeof(UINT32), 
                      NULL, 0,
                      &bytes, NULL) )
{
       dwErr = GetLastError();
        
       return;
}



  
  
IIC_IO_DESC IIC_Data;
UCHAR buff[2];

WCHAR Reg = 0x0001;
UCHAR Val = 0x11;
IIC_Data.SlaveAddress = 0x00;
IIC_Data.Data = buff;
IIC_Data.Count = 2;
buff[0] = Reg;
buff[1] = Val;

  
  bRet = false;

  

  bRet = DeviceIoControl(hIIC, IOCTL_IIC_WRITE,
      &IIC_Data, sizeof(IIC_IO_DESC), NULL, 0, NULL, NULL);

  
  
  

if (!bRet)
{
  dwErr = GetLastError();
  if (dwErr == 1)
  {
    int abc = dwErr;
  }
}

UCHAR StartReg = 0x0000;
PUCHAR pBuff;

IIC_IO_DESC IIC_AddressData;
IIC_AddressData.SlaveAddress = 0x01;
IIC_AddressData.Data = &StartReg;
IIC_AddressData.Count = 1;
    
IIC_Data.SlaveAddress = 0x01;
IIC_Data.Data = pBuff;
IIC_Data.Count = 1;
    
    // use iocontrol to read    
bRet =  DeviceIoControl(hIIC,
                         IOCTL_IIC_READ, 
                          &IIC_AddressData, sizeof(IIC_IO_DESC), 
                          &IIC_Data, sizeof(IIC_IO_DESC),
                          &bytes, NULL); 

if (!bRet)
{
  dwErr = GetLastError();
  if (dwErr == 1)
  {
    int abc = dwErr;
  }
}

CloseHandle(hIIC);

TruthSeeker
'PUCHAR pBuff;' is not initialised ie. should be a pointer to some
allocated space.

Try:

UCHAR Buff;

and

IIC_Data.Data = &Buff;

TruthSeeker
Also, you need to bit shift the slave address one to the left, also then OR
with 0x01 for the read address..

eg.

#define SLAVE_ADDRESS       0x01
#define SLAVE_ADDRESS_WRITE (SLAVE_ADDRESS << 1)
#define SLAVE_ADDRESS_READ  ((SLAVE_ADDRESS << 1) | 0x01)

IIC_AddressData.SlaveAddress = SLAVE_ADDRESS_WRITE;
IIC_Data.SlaveAddress        = SLAVE_ADDRESS_READ;

:)