FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: SPI Slave  (Read 16007 times)

zabuailah

  • Newbie
  • *
  • Posts: 2
    • View Profile
SPI Slave
« on: March 03, 2023, 05:39:09 PM »

Hi,

I am using FT4222H-SPI-Slave to send data to an SPI-Master. As you know FT4222H-SPI-Slave appends a dummy byte (0x00) at the first byte automatically.

The master word size is 32-bit, so first I send 3 dummy bytes (0x000000), and then I send the actual data (I want the master to receive first a whole dummy word and then receive the actual data).

So I use FT4222_SPISlave_Write() twice and then notify the master to receive the data, as follows:
1. Call FT4222_SPISlave_Write() to buffer the 3 dummy bytes
2. Call FT4222_SPISlave_Write() again to buffer the actual data (two words: 0xAAAAAAAA, 0xBBBBBBBB)
3. Notify the master to receive the data

Results:
1. If the master receives the 3 words from FT4222H-SPI-Slave in one transaction, then it receives { 0x00000000, 0x00000000, 0x00000000 }
2. But if I modified the master code to receive each word in a separate transaction, then it receives { 0x00000000, 0x00AAAAAA, 0xAABBBBBB }

Question-1: Why FT4222H-SPI-Slave doesn't send the data correctly in the one transaction manner?
Question-2: Why FT4222H-SPI-Slave appends a dummy byte in the second word (0x00AAAAAA) in the multiple transactions manner?

Kindly, find attached the analyzer screenshots.
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Re: SPI Slave
« Reply #1 on: March 07, 2023, 04:33:07 PM »

Hello,

If you use FT4222_SPISlave_Write() to write SPI slave data it will append 0x00 in every time the API FT4222_SPISlave_Write() is called.

You can also try to replace FT4222_SPISlave_Write() with FT_Write() as it does not append 0x00 at the beginning.

There are only two USB FIFOs to store the data from PC Host and each FIFO is 512 bytes (but status bytes occupy 2 bytes).
When the API FT_Write() is called, it will send a bulk transfer.
If the transfer size is <512 , it will be treated a short packet transfer and occupy one USB buffer.
If the transfer size is >=512 and <=1024, it will be treated two packets transfer and occupy two USB buffers.
SPI Slave is a passive transfer.
Also make sure the SPI Master sends the clock and do not let the buffer overflow.

Best Regards,
FTDI Community
Logged

zabuailah

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SPI Slave
« Reply #2 on: April 05, 2023, 07:36:35 AM »

Hi,

I have started using FT_Write() to send data to the master.

I have observed that when I call FT_Write() once to send the data, the master receives it correctly. However, in some cases, I have to call FT_Write() multiple times to send the complete data. In such scenarios, the master only receives the first chunk of data correctly since it receives the whole data in one transaction by activating Slave Select once.

I have realized that the master needs to receive each chunk of data in a separate transaction to receive the complete data correctly. By a chunk, I mean the data sent by a call of FT_Write().

Therefore, I would like to inquire if there is a specific configuration that can resolve this issue, or if there is an alternative API that I can use. If neither is possible, could you please suggest another chip that could be used instead of FT4222H?

Thank you for your assistance.

Best regards,
Zakaria
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Re: SPI Slave
« Reply #3 on: April 06, 2023, 04:01:32 PM »

Hello,

If you want to write a big chunk of slave data you can follow the instructions:

1. Set a very big value for write timeouts
For example : = FT_SetTimeouts(ftHandle, 1000, 5000);  // set write timeout of 5 sec

2. Use FT_Write to write the specific size of data. // the size can be very long

Then the writing data will be a continuous data.

Note:
When FT_write is executed on SPI Slave transaction. The program will be hold until the sending data finished, or timeout occurs.

Best Regards,
FTDI Community
Logged