How to read SPI data with FTDI chip FT232R?

Hello all

I'm trying to read and write serial data with a FTDI chip (FT232R).

I'm using the IC in Synchronous Bit Bang Mode using D0 as a CLK output and D1 as a DATA input/output.

First i shall shift out 16 bits on DATA and then change it to an input and shift back 16 bits.

I have successfully shifted out DATA but i have trouble reading back.

Anyone here having any example code?

Reply to
Sven
Loading thread data ...

and

and

Have you looked at this:

formatting link

--------------------------------------- This message was sent using the comp.arch.embedded web interface on

formatting link

Reply to
heindekock

Yes

But I don't understand the FT_Read() function.

Does the chip read all pinns during FT_Write() and then FT_Read() returns all read values?

Reply to
Sven

Sorry - I just saw it implemented on a micro for in application programming over USB, I didn?t write the code myself so I can?t help you further.

Best of luck to you.

--------------------------------------- This message was sent using the comp.arch.embedded web interface on

formatting link

Reply to
heindekock

It is easier to use a SEPARATE pin for input and output.

Use FT_SetBitMode to determine which pins are input and output, once.

Because it fifos the data as you change the output, inputs are read. Using the Baud rate clock to clock out and in the values at the same time. If you read data sheet mentioned below it does say it reads FIRST ALL pins, so you will have to mask the bits to get the bit you want.

So data bit input must be PRELOADED before the write occurs.

You can ONLY read in that mode by writing at same time. You may have to use GPIO of other pins to enable or disable external hardware, and possibly

Write 16 bits (external device enabled for write)

Write 17 or 16 bits (external device DISabled for write) Read the data back possibly discarding first byte if using 17 bits for external data not preloaded.

Similar to FT2232.

I assume you have looked at data sheets for

AN232R-01 Bit Bang Modes for the FT232R and FT245R D2XX programmers guide.

Yes their guides and examples leave a lot to be desired for things missing, like timing diagrams for EACH mode and operation, as well as basic programme flow for minimal operation.

Double check the FTDI site for ALL languages as they also do not put examples for all modes in each language.

Don't even get me going on their pseudo I2C implementations.

--
Paul Carpenter          | paul@pcserviceselectronics.co.uk
    PC Services
 Timing Diagram Font
  GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
 For those web sites you hate
Reply to
Paul Carpenter

Hello again.

I'm looking more (intensively) at application note AN232R-01 now.

formatting link

I notice something at page 5 about Synchronous Bit Bang Mode.

The timing diagram shows that the chip uses 6 time slots in this mode of operation, t1 to t6. And during t1, t3, t4, t5, t6 it reads the pins (5 time slots). And only at t2 (1 time slot) it writes to the pin.

So when I send X bytes with FT_Write() I should have X*5 bytes to read with FT_Read()?

Any thoughts about that?

I don't know if it's right. I'm going to test this tomorrow. :-)

Reply to
Sven

Did you read my previous post?

First RE-read the paragraph at the TOP of that page

"Synchronous Bit Bang mode is the same as the FT2232 Synchronous Bit Bang mode. With Synchronous Bit Bang mode, data will only be sent out if there is space in the device for data to be read from the pins. This Synchronous Bit Bang mode will read the data bus pins first, before it sends out the byte that has just been transmitted. It is therefore 1 byte behind the output and so to read the inputs for the byte that you have just sent, another byte must be sent. "

As explained in the paragraph and the timing digram it takes 6 clock cycles (BAUD rate set) to

Read inputs pause (toggle read pin to clock next input pins from your devices) clock out data pins that are outputs pause Toggle write pin to clock outputs to your devices pause

As described in the quoted paragraph above data is clocked in just before data is clocked out.

So you CANNOT easily do your preferred scheme of

write data change direction Read data

The device does not work that way.

You are aware that SPI data lines are NOT bidirectional?

SPI has two data lines

Master Slave MOSI output input MISO input output

MOSI = Master OUT Slave IN

MISO = Master IN Slave OUT

By the way as described in the description above, make sure you flush the RX Fifo before writing data.

--
Paul Carpenter          | paul@pcserviceselectronics.co.uk
    PC Services
 Timing Diagram Font
  GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
 For those web sites you hate
Reply to
Paul Carpenter

Hello again

I have solved the problem. I used the FT_GetStatus() right after calling FT_Write(). That way FT_GetStatus() sayed I had 0 bytes to receive. Now I simply call FT_Read() after FT_Write() and let it wait for the same amount of data to read as i wrote. And I also got a lot of junk bytes to read because I didn't always empty the rx buffer.

The FT232R is going to be connected to a PIC MCU to the MCLR (reset), PGC (clock) and a two way PGD (data).

Thank's all :-)

Reply to
Sven

And also thank you for the nice timing diagram font. :-)

Reply to
Sven

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.