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?
Didn't find your answer? Ask the community — no account required.
H
heindekock
and
and
Have you looked at this:
formatting link
--------------------------------------- This message was sent using the comp.arch.embedded web interface on
formatting link
S
Sven
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?
H
heindekock
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
P
Paul Carpenter
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
S
Sven
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. :-)
P
Paul Carpenter
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
S
Sven
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 :-)
S
Sven
And also thank you for the nice timing diagram font. :-)
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.