libftdi Archives

Subject: More FT2232H USB->serial woes

From: "T. Horsnell" <tsh@xxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Wed, 16 Dec 2009 11:40:12 +0000
Hi all,
I'm having a miserable time trying to use USB->serial on a FT2232H mini-module.
I have:
. Channel-A TX pin connected to Channel-A RX pin
. Channel-A TXLED# connected to VCC
. Channel-A RXLED# connected to VCC

I use the attached test program to:
. Open channel A
. Disable channel-A flow control
. Set channel-A baudrate to 1 Mbaud.
. Write 1 char to channel-A
. Read 1 char from channel-A

I plug in the mini-module, do 'rmmod ftdi_sio usbserial'
and run the program. It works once, and the TXLED and RXLED both flick.
After that, it no longer works, and neither the TXLED or RXLED flick.
Instead, it just loops in the ftdi_read_data loop until I
re-plug the mini-module. Then it works just once again, and
loops thereafter. And so on..

Any ideas please?

Thanks,
Terry

I have:
libftdi-0.16

$ uname -a
Linux localhost.localdomain 2.6.27.25-78.2.56.fc9.i686 #1 SMP Thu Jun 18 
12:47:50 EDT 2009 i686 i686 i386 GNU/Linux

$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=i386-redhat-linux
Thread model: posix
gcc version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC)














--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   
//Write a char to channel A and then read a char from channel A.
//channel-A's TX pin is connected to channel-A's RX pin

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <usb.h>
#include <ftdi.h>

const int vendor_id=0x0403;
const int product_id=0x6010;            //FT2232H

#define BAUD_RATE 1000000

int main(int argc, char **argv)
{
struct ftdi_context ftdic;
int i;

unsigned char sent,rcv;

printf("setting up channel A\n");
ftdi_init(&ftdic);

if (ftdi_set_interface(&ftdic, INTERFACE_A) != 0) {printf("Set interface 
failed\n"); exit(0);}

i = ftdi_usb_open(&ftdic, vendor_id, product_id); 
if(i < 0 && i != -5)
  {
  fprintf(stderr, "unable to open ftdi device: %d - %s\n",i,ftdic.error_str);
  exit(-1);
  }
printf("ftdi open A succeeded: %d\n",i);

printf("setting flowcontrol\n");
i=ftdi_setflowctrl(&ftdic, SIO_DISABLE_FLOW_CTRL);
if (i != 0)
  {
  printf("setting channel A flow-control failed. stat=%i\n",i);
  exit(0);
  }

if (ftdi_set_baudrate(&ftdic,BAUD_RATE) != 0) {printf("set baud of %i 
failed\n",BAUD_RATE); exit(0);}

sent='0';
i = ftdi_write_data(&ftdic, &sent, 1);
if(i < 0)
  {
  fprintf(stderr,"write failed for %x, error %d - %s\n",sent,i,ftdic.error_str);
  }

printf("Reading a byte\n");
i=0;
while (i == 0)
  {
  i = ftdi_read_data(&ftdic, &rcv, 1);
  if(i < 0)
    {
    fprintf(stderr,"read failed, error %d - %s\n",i,ftdic.error_str);
    exit(0);
    }
  printf("Waiting..\n");
  }
if (sent != rcv) printf("Error. i=%i, char written=%c char 
received=%c\n",i,sent,rcv);

ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
}

Current Thread