Search code examples
pythonserial-portpyserialftdiflow-control

Flow control on a FT232RL


I have a FT232RL chip. I am using it for usb to RS232 protocol conversion which i need to convert the data and use it further.

The "data set" (the device on the other side, like a modem, in my case a MAX485 IC) that i am using cannot be configured. All i can give it is a control signal to read or write. So its not very useful.

My application requires me to be able to set that to "write mode" when i am sending data and then AS SOON AS I AM DONE SENDING, i need to be able to set it to "read mode" to receive the response signal it generates.

Note: The control signal is a simple HIGH or LOW The data can be a few bytes

I think one way to do this is to be able to read how much data is there in the RS232 transmit buffer. As soon as that becomes "0", all data will have been transmitted and i can set the control pin to "read mode"

Another way to do it is using FLOW CONTROL

I wish to explain my understanding of flow control before stating my problem for clarity purpose:

(1) I send the data via Python to the ftdi via usb

(2) The ftdi needs write a HIGH on the DTR line

(3) On receiving a HIGH on the DSR line, it needs to start transmitting(this is assuming i have disabled rts/cts flow control settings)

(4) Once it is done transmitting, it needs to write a LOW on the DTR line marking end of transmission

The problem is that i cant get the DTR line to turn ON and OFF as expected STEP (2) does not happen

import serial
ser = serial.Serial("com1")      # initialised port as ser
ser.dsrdtr = True                # set dsrdtr mode
ser.write("blah blah")           # sent a command

I even tried the following:

ser.setDTR(True)                 # write a HIGH on DTR
ser.setDTR(False)                # write a LOW on DTR

This still doesnt solve my complete problem.

Please advice

EDIT: I need to mention that the FT232RL i am using is on a breakout board by nex-robotics and the pins that i have access to are: 3.3V, 5V, CD, RXD, TXD, DTR, GND, DSR, RTS, CTS and RI and ofcourse a usb port to connect it to my laptop

EDIT2: Can I use Mprog 3.5 or a similar software to flash an EEPROM which can support what i wish to do? If yes, How?


Solution

  • TL;DR

    According to the FTDI documentation the default configuration of pin CBUS2 is TXDEN, which is expressly designed for this feature, so just use pin CBUS2 for your transceiver enable.

    Background

    The FTDI chip is certainly capable of DTR/DSR flow control.

    But that is for when the hardware handles the flow control by itself (communicating with the far end, which can provide back pressure). No software involvement is required.

    With a multidrop bus like RS485, the actual flow control is handled in software, and hardware just sends data when directed by the software.

    As one of your commenters suggests, you could write additional software to turn DTR on, send data, and turn DTR back off. But that is problematic for meeting tight timing, and there is no actual need for that, because the FTDI chip has support for turning the transmitter on for you, based on when you are sending data. This support may or may not be available on the DTR signal you are using, though.

    FTDI's name of the signal which can control a transceiver is TXDEN. Depending on which FTDI chip you are using, this could be routed to one of a few different pins.

    To set that routing up, you simply run FTDI's FT_Prog. You can scan and parse the current devices, and then make changes using a GUI. You can save and restore configurations from XML files as well. The program will show you the routing options for TXDEN.

    EDIT by ASKER:- This answer is complete with the following points:-

    1) Download MPROG 3.5 as the programmer for the FTDI.

    2) Select any one of programmable pins from any of the CBUS0 - CBUS4

    3) Then after read and parse, change the selected pin to TXDEN and hit program

    4) Do the necessary hardware connections for TXDEN

    TXDEN is high till the FTDI is sending data and becomes low immediately and hence serves my purpose