Application Note
AN_329 User Guide For LibFT4222
Version 1.5
Document Reference No.: FT_001060 Clearance No.: FTDI#406
49
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Summary:
Write data to the specified I
2
C slave device with START and STOP conditions.
Parameters:
Address of the target I
2
C slave.
Pointer to the buffer that contains the data to be written to the device.
Number of bytes to write to the device.
Pointer to a variable of type uint16 which receives the number of bytes
written to the device.
Return Value:
FT4222_OK if successful, otherwise the return value is an FT error code.
Error code:
FT4222_DEVICE_NOT_OPENED: The initialization API is not called.
FT4222_IS_NOT_I2C_MODE: The device is not in i2c slave mode
FT4222_INVALID_POINTER: Parameter buffer is NULL
FT4222_INVALID_PARAMETER: bytesToWrite is equal to zero
FT4222_FAILED_TO_WRITE_DEVICE: Failed to write data.
Prerequisite:
FT4222_I2CMaster_Init
Example:
FT_HANDLE ftHandle = NULL;
FT_STATUS ftStatus;
FT4222_STATUS ft4222Status;
ftStatus = FT_Open(0, &ftHandle);
if (FT_OK != ftStatus)
{
// open failed
return;
}
// initial i2c master with 1000K bps
ft4222Status = FT4222_I2CMaster_Init(ftHandle, 1000);
if (FT4222_OK != ft4222Status)
{
// i2c master init failed
return;
}
const uint16 slaveAddr = 0x22;
uint8 master_data[] = {0x1A, 0x2B, 0x3C, 0x4D};
uint16 sizeTransferred = 0;
// write 4 bytes data to master
ft4222Status = FT4222_I2CMaster_Write(ftHandle, slaveAddr, master_data,
sizeof(master_data), &sizeTransferred);
if (FT4222_OK == ft4222Status)
{
// write data success