Help with FT2232H flow control

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Help with FT2232H flow control

Dave McMahan

Hello,

 

I am using the FT2232H chip in an Android (linux) environment.  I am working with the latest libftdi (version 1.2), libusb (version 1.0).

 

I have built the code as a static library for Android and written an example program.  I am using port B on the chip for serial communications.  I can set the baud rate, parity, data bits, stop bits and this all works.  I can send and receive test patterns.  I am testing this on FT2232H Mini-Module purchased from FTDI.

 

My problem is in using hardware flow control with RTS and CTS.  The RTS output is always high, which prevents data from coming.  If I jumper RTS and CTS together, no data flows because of this.  If I simply ground CTS, I can send and receive data in loop back.  I have a USBee AX logic analyzer running on a separate laptop to see all the lines and their states.

 

I have changed the example program many times with several different combinations of API functions, changed order of API functions, etc.  Nothing seems to help.

 

I know my hardware works because I can use the same module on MacBook and Linux using the D2XX library from FTDI and hardware flow control works exactly like it should.    I tried to copy exactly the same API functions and order of calling from D2XX to libftdi but this also has the same problem.

 

I am using libftdi because it supports current Android software.   Current D2XX libraries are not available for Android, so I can’t use a 64-bit environment (a requirement for me).

 

Please let me know what I should be looking at or what other information you would like me to provide.  I don’t know which way to go to solve this.

 

 

  -dave

 



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with FT2232H flow control

Anders Larsen
Hi,

On 2015-08-18 22:01, Dave McMahan wrote:

> Hello,
>
> I am using the FT2232H chip in an Android (linux) environment.  I am
> working with the latest libftdi (version 1.2), libusb (version 1.0).
>
> I have built the code as a static library for Android and written an
> example program.  I am using port B on the chip for serial
> communications.  I can set the baud rate, parity, data bits, stop bits
> and this all works.  I can send and receive test patterns.  I am  
> testing
> this on FT2232H Mini-Module purchased from FTDI.
>
> My problem is in using hardware flow control with RTS and CTS.  The  
> RTS
> output is always high, which prevents data from coming.  If I jumper  
> RTS
> and CTS together, no data flows because of this.  If I simply ground
> CTS, I can send and receive data in loop back.  I have a USBee AX  
> logic
> analyzer running on a separate laptop to see all the lines and their
> states.

It sounds as if you are using plain serial communications?

If so, the FT2232H should Just Work (tm) - the Kernel driver ftdi_sio.ko
should take care of everything, including hardware flow control
(without any special libraries like libftdi or D2XX)

Cheers
Anders

> I have changed the example program many times with several different
> combinations of API functions, changed order of API functions, etc.
> Nothing seems to help.
>
> I know my hardware works because I can use the same module on MacBook
> and Linux using the D2XX library from FTDI and hardware flow control
> works exactly like it should.    I tried to copy exactly the same API
> functions and order of calling from D2XX to libftdi but this also has
> the same problem.
>
> I am using libftdi because it supports current Android software.
> Current D2XX libraries are not available for Android, so I can’t use a
> 64-bit environment (a requirement for me).
>
> Please let me know what I should be looking at or what other  
> information
> you would like me to provide.  I don’t know which way to go to solve
> this.
>
>   -dave

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Help with FT2232H flow control

Dave McMahan

Anders,

Thanks for your quick response.

Unfortunately, I can't use only plain serial communications.  I must use GPIO signals connected to Port A and serial communications on Port B.    

As far as I can tell on Android Lollipop running on a Nexus9 tablet, there is no kernel driver for ftdi.  

In any event, I must use libftdi to control the GPIO signals (both inputs and outputs) and I thought it would be a bad idea to mix a kernel driver with libftdi calls on the same device at the same time.


  -dave



> From: Anders Larsen [mailto:[hidden email]]
> Sent: Tuesday, August 18, 2015 5:22 PM
> To: [hidden email]
> Subject: Re: Help with FT2232H flow control
>
> Hi,
>
> On 2015-08-18 22:01, Dave McMahan wrote:
> > Hello,
> >
> > I am using the FT2232H chip in an Android (linux) environment.  I am
> > working with the latest libftdi (version 1.2), libusb (version 1.0).
> >
>
> It sounds as if you are using plain serial communications?
>
> If so, the FT2232H should Just Work (tm) - the Kernel driver ftdi_sio.ko
> should take care of everything, including hardware flow control
> (without any special libraries like libftdi or D2XX)
>
> Cheers
> Anders



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with FT2232H flow control

Anders Larsen
Hi Dave,

On 2015-08-18 23:29, Dave McMahan wrote:
> Anders,
>
> Thanks for your quick response.
>
> Unfortunately, I can't use only plain serial communications.  I must  
> use GPIO signals connected to Port A and serial communications on  
> Port B.

that alone is not a problem, it's just a bit tricky to set up.

You must "unbind" Port A from the serial driver in order to use the
GPIO pins with libftdi (will check tomorrow @work how I did that and
report back).

> As far as I can tell on Android Lollipop running on a Nexus9 tablet,  
> there is no kernel driver for ftdi.

It should not be too difficult to build the ftdi_sio kernel module
since the Google has published the Kernel sources.

http://www.androidpolice.com/2014/11/05/google-releases-kernel-source-for-nexus-9-volantis-and-nexus-player-fugu/

> In any event, I must use libftdi to control the GPIO signals (both  
> inputs and outputs) and I thought it would be a bad idea to mix a  
> kernel driver with libftdi calls on the same device at the same time.

It is not a problem using separate drivers to handle the separate USB
endpoints of the FT2232H chip - the ports really are independent.

Cheers
Anders

> > From: Anders Larsen [mailto:[hidden email]]
> > Sent: Tuesday, August 18, 2015 5:22 PM
> > To: [hidden email]
> > Subject: Re: Help with FT2232H flow control
> >
> > Hi,
> >
> > On 2015-08-18 22:01, Dave McMahan wrote:
> > > Hello,
> > >
> > > I am using the FT2232H chip in an Android (linux) environment.  I  
> am
> > > working with the latest libftdi (version 1.2), libusb (version  
> 1.0).
> > >
> >
> > It sounds as if you are using plain serial communications?
> >
> > If so, the FT2232H should Just Work (tm) - the Kernel driver  
> ftdi_sio.ko
> > should take care of everything, including hardware flow control
> > (without any special libraries like libftdi or D2XX)
> >
> > Cheers
> > Anders
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Help with FT2232H flow control

Dave McMahan

Anders,

I really would prefer not to have to rebuild the entire Android kernel to solve this problem.  There are all kinds of logistical and technical issues for me if I have to go that way.  For example, it would mean I would need to instruct my users to reflash their Nexus9 image with my new kernel changes.  They would not be happy to do this.  I know the chip can do what I need  because I have seen it work when using the D2XX libraries on other platforms.



I think I may have found something interesting.

Originally, I was only calling these functions (error checking removed for clarity, but I have it in the code):

    ftdiComm = ftdi_new();
    ftdiStatus = ftdi_set_interface(ftdiComm, INTERFACE_B);
    ftdiStatus = ftdi_usb_open(ftdiComm, VID, PID);
    ftdiStatus = ftdi_set_line_property(ftdiComm, BITS_8, STOP_BIT_1, NONE);
    ftdiStatus = ftdi_set_baudrate(ftdiComm, baudrate);    // baudrate = 921600
    ftdiStatus = ftdi_setflowctrl(ftdiComm, SIO_RTS_CTS_HS);      //  Enable CTS/RTS hardware flow control

    ftdiComm->usb_read_timeout  = 1;        //  1 millisecond timeout for read and write.  There is no API function to set this, so we just write to the structure directly
    ftdiComm->usb_write_timeout = 1;

    ftdiStatus = ftdi_set_latency_timer(ftdiComm, 1);           //  Set latency to 1 millisecond, the minimum


The code above never sets the RTS pin low on my logic analyzer.

I was reading some forum on this and it gave me an idea.  I added this line after setting flow control:

    ftdiStatus = ftdi_setrts(ftdiComm, 1);      //  Set RTS low by default


I assumed that using hardware handshake flow control would automatically control the RTS output based on the receive buffer fullness.   Apparently, that's not totally true.  It seems like there is a 'default' state defined by ftdi_setrts().  I must set that default state to 1 (which makes it come out of the pin as 0 volts).   I tried setting it setting it to 0 at first but found RTS was always 3.3 volts output, the wrong value for correct flow control.

With this change, I can see RTS goes low at startup.  I then write/read many 100 byte chunks and that works with RTS never going high because I always read the buffer before it fills.

Then, I stop reading and just write 10,000 bytes (some arbitrarily big number to fill the receive buffer).  I see RTS goes high during the transmission.  Woot!!!   After writing 10,000 bytes, I read whatever I can from the buffer.  RTS goes low when I start pulling data out of the buffer  Woot!!  Woot!!  :-)   I can read 7,768 bytes from a full receive buffer.

I need to do more testing tomorrow to really make sure all this works like I expect.   I also have to implement the GPIO controls on the other port.

Does my understanding of the need to call ftdi_setrts() make sense?  I believed it would be useless until I did this test.

   -dave





-----Original Message-----
From: Anders Larsen [mailto:[hidden email]]
Sent: Tuesday, August 18, 2015 5:54 PM
To: [hidden email]
Subject: Re: Help with FT2232H flow control

Hi Dave,

On 2015-08-18 23:29, Dave McMahan wrote:
> Anders,
>
> Thanks for your quick response.
>
> Unfortunately, I can't use only plain serial communications.  I must  
> use GPIO signals connected to Port A and serial communications on  
> Port B.

that alone is not a problem, it's just a bit tricky to set up.

You must "unbind" Port A from the serial driver in order to use the
GPIO pins with libftdi (will check tomorrow @work how I did that and
report back).

> As far as I can tell on Android Lollipop running on a Nexus9 tablet,  
> there is no kernel driver for ftdi.

It should not be too difficult to build the ftdi_sio kernel module
since the Google has published the Kernel sources.

http://www.androidpolice.com/2014/11/05/google-releases-kernel-source-for-nexus-9-volantis-and-nexus-player-fugu/

> In any event, I must use libftdi to control the GPIO signals (both  
> inputs and outputs) and I thought it would be a bad idea to mix a  
> kernel driver with libftdi calls on the same device at the same time.

It is not a problem using separate drivers to handle the separate USB
endpoints of the FT2232H chip - the ports really are independent.

Cheers
Anders

> > From: Anders Larsen [mailto:[hidden email]]
> > Sent: Tuesday, August 18, 2015 5:22 PM
> > To: [hidden email]
> > Subject: Re: Help with FT2232H flow control
> >
> > Hi,
> >
> > On 2015-08-18 22:01, Dave McMahan wrote:
> > > Hello,
> > >
> > > I am using the FT2232H chip in an Android (linux) environment.  I  
> am
> > > working with the latest libftdi (version 1.2), libusb (version  
> 1.0).
> > >
> >
> > It sounds as if you are using plain serial communications?
> >
> > If so, the FT2232H should Just Work (tm) - the Kernel driver  
> ftdi_sio.ko
> > should take care of everything, including hardware flow control
> > (without any special libraries like libftdi or D2XX)
> >
> > Cheers
> > Anders
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]

Loading...