libftdi Archives

Subject: 232R device RTS hardware handshake signal

From: frrrt_ <frrrt_@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 14 May 2009 23:54:40 +0200
Hello all!

I'm trying with no success to use the RTS handshaking signal on a 232R device
(http://www.ftdichip.com/Products/EvaluationKits/TTL-232R-3V3.htm)


My setup involves transmitting (with another PC and a similar USB-serial adapter) at a fast pace random characters to the RX pin of the above device, which is read every second by my program reader.c (see attachment)


Under these circumstances I expect the hardware RX buffer of the chip to quickly fill up, and if the hardware handshaking signals work correctly, then the chip should shout "hey my RX buffer is full, don't send me any more data!" by toggling RTS to logic 0 aka 0 Volts (remember RTS# pin on FTDI
232R chips is active low)

However, RTS logic value measured with a multimeter sits constantly at 3.3V, no matter how long I wait.


Any ideas? Help/suggestions would be really appreciated as I tried to debug this problem in many ways with no luck...



Cheers,
Luca






As an aside, I found a list of commands accepted by 232R chips (http://yosemitefoothills.com/Electronics/FTDI_Chip_Commands.html) and tried to modify libftdi (with no difference on the above described RTS pin behavior) as follows





int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl)
{
   ////original
   //if (usb_control_msg(ftdi->usb_dev, SIO_SET_FLOW_CTRL_REQUEST_TYPE,
//SIO_SET_FLOW_CTRL_REQUEST, 0, (flowctrl | ftdi->index),
                       //NULL, 0, ftdi->usb_write_timeout) != 0)
   //   ftdi_error_return(-1, "set flow control failed");

   //return 0;



   ////modified by me: see if it's a problem related to libftdi not
   //  properly activating handshaking signals on both RX and TX
   //  sections of 232R chips.....

   if (usb_control_msg(ftdi->usb_dev, SIO_SET_FLOW_CTRL_REQUEST_TYPE,
SIO_SET_FLOW_CTRL_REQUEST, 0, (flowctrl | ftdi->index),
                       NULL, 0, ftdi->usb_write_timeout) != 0)
       ftdi_error_return(-1, "set flow control failed");


   if (usb_control_msg(ftdi->usb_dev, SIO_SET_FLOW_CTRL_REQUEST_TYPE,
                       0x01, 0,                     0x10          ,
                       NULL, 0, ftdi->usb_write_timeout) != 0)
       ftdi_error_return(-1, "set flow control failed");


   if (usb_control_msg(ftdi->usb_dev, SIO_SET_FLOW_CTRL_REQUEST_TYPE,
                       0x01, 0,                     0x11          ,
                       NULL, 0, ftdi->usb_write_timeout) != 0)
       ftdi_error_return(-1, "set flow control failed");

   printf("\n\n Modified libFTDI\n\n");



   return 0;



}





--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
//   readwrite.c   Copyright (c) 2009    Luca Mannatrizio     
<ltrizio@xxxxxxxxxxxxx>
//
//
//---------------------------------------------------------------------------------
//
// COMPILE ARGUMENTS
//
// compile with the following
// gcc -O receiver.c -o receiver /usr/local/lib/libftdi.a -W -Wall -Wformat 
/usr/lib/libusb.a
//
//---------------------------------------------------------------------------------
//
// NOTES
//
// To avoid the need to be root to run the program just setup permissions for 
your
// FTDI device in /etc/udev/rules.d
//
// Within file 40-permission.rules add the following line
//
//    SYSFS{idVendor}=="0403", SYSFS{idProduct}=="6001"   GROUP="whatever group 
you are in"
//
// for example plugdev and then add yourself (if not already done) to the 
plugdev group
//
// libftdi-0.15 does this already to allow any members of the plugdev group to 
access FTDI devices
//
//---------------------------------------------------------------------------------
//
// PROBLEMS TO SOLVE
//
//
// 1. RTS hanshaking signal misbehaves after setting hardware flow control.
//
//
// FTDI documentation reports the following:
//
// *. RTS# and CTS# are by factory setting active low (hence the reason for 
character #) unless eeprom of
//     FTDI chip has been set to the contrary. I checked my FTDI device is 
configured with factory settings.
//
// *. RTS# is an output from FTDI device that controls flow of data into FTDI 
RX pin
//     0: whatever device attached to FDTI device can transmit
//     1: whatever device attached to FDTI device should stop transmitting
//
// *. CTS# is an input to FTDI device that controls the flow of data out of 
FTDI TX pin
//     0: FTDI device can send data
//     1: FTDI device cannot send data
//
//




// The RX pin of the device which this program runs upon is driven externally 
and filled with random data
// at a pace faster than this program polls the device.
// As a result I expect the hardware RX buffer of the chip which this program 
runs upon to quickly fill up
// If the hardware handshaking signals work correctly, then the chip should 
shout "hey my RX buffer is full, don't send me any more data!"
// by toggling RTS to logic 0 aka 0 Volts (remember RTS# pin on FTDI chips is 
active low)








#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/unistd.h>
#include <pthread.h>
#include <getopt.h>
#include "ftdi.h"
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>



struct ftdi_context ctx;


static void Error(const char *where,int rv,struct ftdi_context *ctx,int doclose)
{
        if(rv)
        {
                fprintf(stderr,"%s: rv=%d, error=%s, errno=%s (%d)\n",
                        where,rv,ctx->error_str,strerror(errno),errno);
                if(doclose)
                {
                        rv=ftdi_usb_close(ctx);
                        fprintf(stderr,"close: rv=%d, error=%s, errno=%s 
(%d)\n",
                                rv,ctx->error_str,strerror(errno),errno);
                }
                ftdi_deinit(ctx);
                exit(1);
        }
        else
                fprintf(stderr,"%s: OK\n",where);
}





////////////////////////////////////////////////////////////
//
//   Main
//

int main() {



   int i;


   int           rv;
   int           vendor = 0x0403;
   int           device = 0x6001;



   const int bufsize = 16;
   unsigned char buf[bufsize];


   // Initialize
   rv=ftdi_init(&ctx);
   Error("init",rv,&ctx,0);




   // Open FTDI device by its serial
   rv=ftdi_usb_open_desc(&ctx, vendor, device, NULL , "FTCY0SGG");

   // Open first FTDI device encountered
   //rv=ftdi_usb_open_desc(&ctx, vendor, device, NULL , NULL);

   Error("open",rv,&ctx,0);


   // Reset
   rv=ftdi_usb_reset(&ctx);
   Error("reset",rv,&ctx,1);


   // Disable bitbang
   rv=ftdi_disable_bitbang(&ctx);
   Error("bitbang is OFF",rv,&ctx,1);

   //rv=ftdi_enable_bitbang(&ctx, 1<<0x02);
   //Error("bitbang is ON",rv,&ctx,1);


   // Set baudrate to 115200
   rv=ftdi_set_baudrate(&ctx,115200);
   Error("set baudrate to 115200",rv,&ctx,1);


   // Set hardware flow control
   rv=ftdi_setflowctrl(&ctx,SIO_RTS_CTS_HS);
   Error("set hardware flow control",rv,&ctx,1);

   // Set software flow control
   //rv=ftdi_setflowctrl(&ctx,SIO_XON_XOFF_HS);
   //Error("set software flow control",rv,&ctx,1);




   printf("\n\n\nReading (in main with no threads) from device FTCY0SGG");

   while ( 1 ) 
   {
      rv=ftdi_read_data(&ctx,buf,bufsize);
      if(rv<0) Error("read",rv,&ctx,1);
      else
      {
         printf("%3d: ",rv);
         for(i=0; i<rv; i++)
            printf("%02x%s",buf[i],i%8==7 ? i%16==15 ? "\n     " : "  " : " ");
      }
      printf("\n"); fflush(stdout);

   sleep(1);

   }





}








Current Thread
  • 232R device RTS hardware handshake signal, frrrt_ <=