FTDI Community

General Category => Discussion - Software => Topic started by: Pereubu123 on February 21, 2019, 10:48:01 AM

Title: MPSSE commands on falling or rising edge?
Post by: Pereubu123 on February 21, 2019, 10:48:01 AM
Data is typically clocked in and out on clock edges. 
Either the rising or falling edge can be used on transmit or receive.
In the 93C46D example, the EEPROM clocks data in and out on the rising edge.
I have my own selected SPI flash component, with clocking in (sampling) data on rising clock edge,
and clocking out data for that particular SPI memory chip on falling edge. Actually, input data is latched in on the rising edge of serial clock (C), and
output data is available from the falling edge of C.

What is confusing is:

(taken form AN_135 FTDI MPSSE Basics Version 1.1)
"In the 93C46D example noted above, the EEPROM clocks data in and out on the rising edge. 
In this case, the MPSSE should be configured for data transfer on falling edges for both transmit and receive. 
This allows the data out from both the MPSSE and the target device to stabilize before being clocked in on the next edge."
Now, I expect that I have to use opposite: MPSSE should be configured clocking in data on falling edge while clocking out data
on rising edge. But what is the meaning "This allows the data out from both the MPSSE and the target device to stabilize before
being clocked in on the next edge"?

So, is that Ok to follow the logic above to configure MPSSE to  latch input data on the rising edge of serial clock (C), and
output data to be  available from the falling edge of C.
Title: Re: MPSSE commands on falling or rising edge?
Post by: Pereubu123 on February 22, 2019, 12:53:16 PM
Maybe I tried to explain the problem in rather confusing way. I will try again:

Let assume that memory device work in mode 0 or mode 3. let us decide to use mode 0.
Where CPOL = 0, CPHA = 0, mode 0.
For this mode, input data is latched in on the rising edge of serial clock (C), and
output data is available from the falling edge of C.
So when we let say  my program is used to read one word data from a random address:
one write command plus address is used  and then on the side mpsse we should use on the
raising edge sampling in to get the data from from spi flash componenet?

That is why the sample in "Interfacing FT2232H Hi-Speed Devices To SPI Bus Application Note AN_114" (page 13) looks very odd:

//send WRITE command  O
utputBuffer[dwNumBytesToSend++] = MSB_FALLING_EDGE_CLOCK_BIT_OUT; 
OutputBuffer[dwNumBytesToSend++] = 2; 
OutputBuffer[dwNumBytesToSend++] = READ; 
//send address 
OutputBuffer[dwNumBytesToSend++] = MSB_FALLING_EDGE_CLOCK_BIT_OUT; 
OutputBuffer[dwNumBytesToSend++] = 7; 
OutputBuffer[dwNumBytesToSend++] = (BYTE)(address); 
//read data   

OutputBuffer[dwNumBytesToSend++] = MSB_FALLING_EDGE_CLOCK_BYTE_IN;     
OutputBuffer[dwNumBytesToSend++] = '\x01';   
OutputBuffer[dwNumBytesToSend++] = '\x00'


The question is why we are using MSB_FALLING_EDGE_CLOCK_BYTE_IN?

Why FALLING_EDGE instead of RAISING_EDGE?
Title: Re: MPSSE commands on falling or rising edge?
Post by: FTDI Community on March 22, 2019, 04:38:07 PM
Hi,

The EEPROM protocol is slightly different from standard SPI such as that used by MCUs and other sensors. We'll need to check why that edge was used in that particular app note but in general for standard mode 0 SPI you would use IN on the rising edge and OUT on the falling edge in your MPSSE commands, as you mentioned. For example, we use these in our libMPSSE library when you select mode 0 (see ftdi_spi.c in the source for reference).

Best Regards, FTDI Community