EasyManua.ls Logo

FTDI LibFT4222 - Page 59

Default Icon
78 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Application Note
AN_329 User Guide For LibFT4222
Version 1.5
Document Reference No.: FT_001060 Clearance No.: FTDI#406
58
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Error code:
FT4222_DEVICE_NOT_OPENED: The initialization API is not called.
FT4222_INVALID_POINTER: Parameter pRxSize is NULL
Prerequisite:
FT4222_I2CSlave_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 slave
ft4222Status = FT4222_I2CSlave_Init(ftHandle);
if (FT4222_OK != ft4222Status)
{
// i2c slave init failed
return;
}
ft4222Status = FT4222_I2CSlave_SetClockStretch(ftHandle, TRUE);
if (FT4222_OK != ft4222Status)
{
// set clock stretch failed
return;
}
while(1)
{
uint16 rxSize;
if(FT4222_I2CSlave_GetRxStatus(ftHandle, &rxSize) == FT4222_OK)
{
if(rxSize>0)
{
uint8 *pRead_data = (uint8 *)malloc(rxSize) ;
uint16 sizeTransferred;
if(FT4222_I2CSlave_Read(ftHandle,pRead_data, rxSize, &sizeTransferred)==
FT4222_OK)
{
// got slave data
}
free(pRead_data);
}
}
else
{
printf("I2C slave get status error\n");
}
}
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);

Table of Contents