FTC_STATUS
|
I2C_Write
|
(FTC_HANDLE ftHandle, PWriteControlByteBuffer pWriteControlBuffer, DWORD dwNumControlBytesToWrite, BOOL bControlAcknowledge, DWORD dwControlAckTimeoutmSecs, BOOL bStopCondition, DWORD dwDataWriteTypes, PWriteDataByteBuffer pWriteDataBuffer, DWORD dwNumDataBytesToWrite, BOOL bDataAcknowledge, DWORD dwDataAckTimeoutmSecs, PFTC_PAGE_WRITE_DATA pPageWriteData)
|
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.
|
bStopCondition
|
Send a Stop condition (TRUE) or do not send a Stop condition (FALSE) after all control bytes have been written to an external device.
|
dwWriteTypes
|
Specifies the type of write to be used when the data contained in the write data buffer is written to an external device. Write no data (NO_WRITE_TYPE), write the data one byte at a time (BYTE_WRITE_TYPE) or write the data in pages (PAGE_WRITE_TYPE).
|
pWriteDataBuffer
|
Pointer to buffer that contains the data to be written to an external device.
|
dwNumDataBytesToWrite
|
Number of bytes in the write data buffer which contain all the specified bits to be written to the external device. Valid range is 1 to 65535 bytes. If NO_BYTE_WRITE is specified, no data will be written to an external device. If BYTE_WRITE_TYPE is specified, only one byte will be written to an external device.
|
bDataAcknowledge
|
Check for acknowledgement after every data byte is written to an external device (TRUE) or do not check for acknowledgement after every data byte is written to an external device (FALSE).
|
dwDataAckTimeoutmSecs
|
Timeout in milliseconds to wait for an acknowledgement after a data byte has been written to an external device. A value of INFINITE indicates timeout never expires while waiting for an acknowledgement. Only valid if bDataAcknowledge is TRUE.
|
pPageWriteData
|
Pointer to a structure that contains the number of pages and the number of bytes per page to be written to an external device.
|
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_WRITE_DATA_BUFFER_POINTER
FTC_INVALID_NUMBER_DATA_BYTES_WRITE
FTC_DATA_ACKNOWLEDGE_TIMEOUT
FTC_INVALID_WRITE_TYPE
FTC_NUMBER_BYTES_TOO_SMALL_PAGE_WRITE
FTC_NULL_PAGE_WRITE_BUFFER_POINTER
FTC_FAILED_TO_COMPLETE_COMMAND
FTC_IO_ERROR
Remarks
This function will write data from the FT2232C to an external device 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, write data buffer and page write data definitions are given in the Appendix.
Example
#define MAX_I2C_M24C64_CHIP_SIZE_IN_BYTES 512
FTC_STATUS Status = FTC_SUCCESS;
FTC_HANDLE ftHandle;
DWORD DataWriteType = 0;
DWORD dwWriteDataBufferIndex = 0;
WriteControlByteBuffer WriteControlBuffer;
WriteDataByteBuffer WriteDataBuffer;
DWORD dwNumDataBytesToWrite = 0;
FTC_PAGE_WRITE_DATA PageWriteData;
DWORD dwWriteDataByteAddress = 0;
DWORD Index = 0;
// Example for M24C64 EEPROM
WriteControlBuffer[0] = '\xAE'; //1 0 1 0 A2 A1 A0 0 - device address 7
for (Index = 0; Index < MAX_I2C_M24C64_CHIP_SIZE_IN_BYTES; Index++)
WriteDataBuffer[Index] = '\xFF'; // Erase address locations
dwWriteDataByteAddress = 0;
// shift down by 8 bits
WriteControlBuffer[1] = ((dwWriteDataByteAddress >> 8) & '\xFF');
WriteControlBuffer[2] = (dwWriteDataByteAddress & '\xFF');
Status = I2C_Write(ftHandle, &WriteControlBuffer, 3, true, 20, true, BYTE_WRITE_TYPE, &WriteDataBuffer, MAX_I2C_M24C64_CHIP_SIZE_IN_BYTES, true, 20, &PageWriteData);