Your browser does not allow scripts
Please click here to view a static table of contents without scripts
I2C_Read
Return to Introduction  Previous page  Next page
Read data from an external device to the FT2232C using the I2C protocol.

FTC_STATUS
I2C_Read
(FTC_HANDLE ftHandle, PWriteControlByteBuffer pWriteControlBuffer, DWORD dwNumControlBytesToWrite, BOOL bControlAcknowledge, DWORD dwControlAckTimeoutmSecs, DWORD dwReadTypes, PReadDataByteBuffer pReadDataBuffer, DWORD dwNumDataBytesToRead)




Parameters
ftHandle
Handle of the device.
pWriteControlBuffer
Pointer to buffer that contains the control and address data to be written to an external device.
dwNumControlBytesToWrite
Number of bytes in the write control buffer to be written to an external device. Valid range 1 to 255 bytes.
bControlAcknowledge
Check for acknowledgement after every control byte is written to an external device (TRUE) or do not check for acknowledgement after every control byte is written to an external device (FALSE).
dwControlAckTimeoutmSecs
Timeout in milliseconds to wait for an acknowledgement after a control byte has been written to an external device. A value of INFINITE indicates timeout never expires while waiting for an acknowledgement. Only valid if bControlAcknowledge is TRUE.
dwReadTypes
Specifies the type of read to be used when the data contained in the read data buffer is read from an external device. Read the data one byte at a time (BYTE_READ_TYPE) or read the data in a continuous block (BLOCK_READ_TYPE).
pReadDataBuffer
Pointer to buffer that contains the data to be read from an external device.
dwNumDataBytesToRead
Number of bytes to be read from an external device. Valid range 1 to 65535 bytes. If BYTE_READ_TYPE specified, only one byte will be returned in the read data buffer.




Return Value
FTC_SUCCESS if successful, otherwise the return value is one of the following FTC error codes:

   FTC_INVALID_HANDLE
   FTC_NULL_CONTROL_DATA_BUFFER_POINTER
   FTC_INVALID_NUMBER_CONTROL_BYTES
   FTC_CONTROL_ACKNOWLEDGE_TIMEOUT
   FTC_NULL_READ_DATA_BUFFER_POINTER
   FTC_INVALID_NUMBER_DATA_BYTES_READ
   FTC_INVALID_READ_TYPE
   FTC_
FAILED_TO_COMPLETE_COMMAND
   FTC_IO_ERROR



Remarks
This function will read data from an external device to the FT2232C using the I2C protocol. The data will be clocked at a rate specified by the clock divisor set by calling either the I2C_InitDevice or I2C_SetClock functions.

The write control buffer and read data buffer definitions are given in the
Appendix.



Example

#define MAX_I2C_M24C64_CHIP_SIZE_IN_BYTES 512

FTC_STATUS Status = FTC_SUCCESS;
FTC_HANDLE ftHandle;
BYTE DataByte = 0;
WriteControlByteBuffer WriteControlBuffer;
DWORD DataReadType = 0;
ReadDataByteBuffer ReadDataBuffer;
DWORD dwNumDataBytesToRead = 0;
DWORD dwReadDataByteAddress = 0;

// Example for M24C64 EEPROM

WriteControlBuffer[0] = '\xAF'; //1 0 1 0 A2 A1 A0 1 - device address 7

dwReadDataByteAddress = 0;

DataReadType = BYTE_READ_TYPE; //BLOCK_READ_TYPE; //

if (DataReadType == BYTE_READ_TYPE)
   dwNumDataBytesToRead = 1;
else
   dwNumDataBytesToRead = MAX_I2C_M24C64_CHIP_SIZE_IN_BYTES;

// shift down by 8 bits
WriteControlBuffer[1] = ((dwReadDataByteAddress >> 8) & '\xFF');
WriteControlBuffer[2] = (dwReadDataByteAddress & '\xFF');

Status = I2C_Read(ftHandle, &WriteControlBuffer, 3, true, 20, DataReadType, &ReadDataBuffer, dwNumDataBytesToRead);