FTDI Community

General Category => Discussion - Software => Topic started by: josh on February 19, 2018, 03:27:50 PM

Title: FT4222 question from a newbie
Post by: josh on February 19, 2018, 03:27:50 PM
Hi all,
I am trying to write my very first FTDI driver for the FT4222H chip in SPI slave mode.
I'm trying to write code to send DLen bytes of data to the master using a short slave transfer (without checksum) command according to the protocol in page 22 of this doc http://www.ftdichip.com/Support/Documents/AppNotes/AN_329_User_Guide_for_LibFT4222.pdf.

However, it is not working. Assuming I always check that ftStatus equals OK, here is the code. Am I doing something wrong?

ftStatus = FT_CreateDeviceInfoList(&dwNumDevs);

ftStatus |= FT_GetDeviceInfoList(devInfo, &dwNumDevs);

ftStatus |= FT_OpenEx((PVOID)(uintptr_t)devInfo.LocId,FT_OPEN_BY_LOCATION, &ftHandle);

ftStatus |= FT4222_SPISlave_Init(ftHandle);

ftStatus |= FT4222_SPI_SetDrivingStrength(ftHandle, DS_8MA, DS_8MA, DS_8MA);

char sp[5] = {0x5a, 0x83, serial_num, (DLen & 0xff) >> 8, DLen & 0xff };

ftStatus |= FT4222_SPISlave_Write( ftHandle, sp, 5,&sizeTransferred);
ftStatus |= FT4222_SPISlave_Write( ftHandle, Buffer, DLen, &sizeTransferred);


Thanks.
Title: Re: FT4222 question from a newbie
Post by: FTDI Community on February 20, 2018, 03:05:17 PM
Hi,

Can you take a look at the Examples contained in v1.4.0 of the LibFT4222 Windows Library, available here:

 http://www.ftdichip.com/Support/SoftwareExamples/LibFT4222-v1.4.zip (http://www.ftdichip.com/Support/SoftwareExamples/LibFT4222-v1.4.zip)

If you are still having problems please contact us on support1@ftdichip.com and we will assist you further.

Best Regards,
FTDI Community
Title: Re: FT4222 question from a newbie
Post by: josh on February 22, 2018, 03:25:19 AM
What is the size of the internal SPI shift register in slave mode?
Title: Re: FT4222 question from a newbie
Post by: Cactus on February 22, 2018, 01:52:02 PM
Hi Josh,
My (also newbie experience) with the FT4222h has been that to send data to a master from the FT4222 you only need to use FT4222_SPISlave_Write(handle,Buffer,dlen, &sizeTransferred).
However with the microprocessor you need to send clock signals, and then the buffer is transferred from the FT4222 when it is clocked by the master.
If you wish to send data from the master to the FT4222h however you need to use the 0x5a, 0x83... etc code (see photo).
Attached is a screenshot of the SPI trace (MOSI and CLK) of a microprocessor (Master) communicating with the FT4222h(as slave)
Title: Re: FT4222 question from a newbie
Post by: devangs3 on December 19, 2019, 09:31:56 PM
Hi,
I have a similar trouble with using the SPISlave_Write function from the win32 app to an ARM master. When I execute this function, my ARM master core cannot catch the data sent by the PC. Does this mean the ARM core has to continuously poll the FT4222? Does the TX buffer of FT4222 not persist until it is read? Any ideas appreciated. 
Title: Re: FT4222 question from a newbie
Post by: FTDI Community on December 20, 2019, 11:35:43 AM
Hello,

Is the data being transmitted on the SPI bus, have you managed to scope the lines to check?

Yes the Tx buffer of the FT4222H will persist until the data is read by the master.

Best Regards,
FTDI Community