Having trouble with ftdi2232H Usb <--> Serial (2)

Thread Starter

xbbncvg

Joined Apr 18, 2024
1
Hi,

I have a Ft2232 H device and I am trying to put it in the MPSSE mode.
The two channels, ie, A and B are being detected as device 0 and
Device 1.

When I send put Channel A in MPSSE mode and send a bad command , I get
the correct reply of 0xFD and the error byte.

However, when I execute exactly the same code with Channel B, I do not
get any response.

Please tell me where my error lies.

I have not touched the loopback settings and have left them to the
default value.

I am using only one channel at a time. When I try to use both together
with different software handles, I get a Segmentation Fault.

I have used the entire code from
http://www.ftdichip.com/Documents/AppNotes/AN_135_MPSSE_Basics.pdf
however, the code works perfectly for Channel A, but when I change the
index to channel B's index (ie 1) , it gets stuck on the Bad Command
Detection, since it never obtains a reply.

Rich (BB code):
#include <ftd2xx.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

int main()
{

FT_STATUS ftStatus;
FT_DEVICE_LIST_INFO_NODE *devInfo;
DWORD numDevs;
// create the device information list
ftStatus = FT_CreateDeviceInfoList(&numDevs);

if (ftStatus == FT_OK) {        printf("Number of devices is %d\n",numDevs); }

if (numDevs > 0) {
       // allocate storage for list based on numDevs
       devInfo =
(FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
       // get the device information list
       ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs);
       if (ftStatus == FT_OK) {
              for (int i = 0; i < numDevs; i++) {
                     printf("Dev %d:\n",i);
                     printf(" Flags=0x%x\n",devInfo.Flags);
                     printf(" Type=0x%x\n",devInfo.Type);
                     printf(" ID=0x%x\n",devInfo.ID);
                     printf(" LocId=0x%x\n",devInfo.LocId);
                     printf(" SerialNumber=%s\n",devInfo.SerialNumber);
                     printf(" Description=%s\n",devInfo.Description);
                     printf(" ftHandle=0x%x\n",devInfo.ftHandle);
              }
       }
}


FT_HANDLE hdev1;
ftStatus=FT_OpenEx(devInfo[1].SerialNumber, FT_OPEN_BY_SERIAL_NUMBER, &hdev1);

if(ftStatus!=FT_OK )
{
cout<<"Device Error"<<endl;
exit(1);
}

if(FT_ResetDevice(hdev1)!=FT_OK) cout<<"Error"<<endl;
if(FT_SetUSBParameters(hdev1, 65535, 65535)!=FT_OK) cout<<"Error"<<endl;
FT_SetChars(hdev1, false, 0, false, 0);
if(FT_SetTimeouts(hdev1, 5000, 5000)!=FT_OK) cout<<"Error"<<endl;
if(FT_SetBitMode(hdev1, 0, 0x00)!=FT_OK) cout<<"Error"<<endl;

sleep(2);
UCHAR bitmode;
if(FT_SetBitMode(hdev1, 0, 0x02)!=FT_OK) cout<<"Error"<<endl;


DWORD BytesWritten=0;
UCHAR command1[3];
command1[0]=0xAB;

FT_Write(hdev1, command1, 1, &BytesWritten);

cout<<"Written "<<BytesWritten<<endl;

unsigned char readbuf[10];
BytesWritten=0;
FT_Read(hdev1, readbuf, 10, &BytesWritten);
for(int i=0;i<BytesWritten;i++)
printf("Read %x \n ", readbuf);

FT_Close(hdev1);

return 0;
}

The output is:

Rich (BB code):
Number of devices is 2
Dev 0:
Flags=0x2
Type=0x6
ID=0x4036010
LocId=0x0
SerialNumber=FTT3AMJI A
Description=USB <-> Serial Cable A
ftHandle=0x0
Dev 1:
Flags=0x2
Type=0x6
ID=0x4036010
LocId=0x0
SerialNumber=FTT3AMJI B
Description=USB <-> Serial Cable B
ftHandle=0x0
Written 1
It works for channel A but not for B. Im using Fedora 12 and kernel 2.6.31-12

Thanks,
Srinivasan Iyer
India
I ran into this issue today (in 2024), where I opened both ports using D2XX functions. In my case, my project uses an FT2232H for two different needs: "Bit Bang" on Port A to support relays, and MPSSE on port B to connect to a SPI bus with a sole A/D device. My software calls D2XX APIs to set up both ports. After that, Port A ran fine. On port B, I sent the same set of commands you used to put it in MPSSE mode and sent the illegal command byte. Then I called FT_GetQueueStatus expecting it to report 2 bytes waiting to be read (the reject code 0xFA and the illegal byte I wrote), and got back a zero count! All along, the return codes from these D2XX functions were always zero (success). This behavior appeared consistent across the board with port B: I could send a lot of commands, get back success return codes on all, but any time I tried to read, I'd get zero bytes. It was as though B didn't have the light on upstairs: the MPSSE command processor was just accepting commands and rubber-stamping them (not doing anything with them), and reads would always return no data.

I ran a Google search and and found your question, and I noticed it was not answered. Here is how I resolved the problem.

In my case, changing an EEPROM setting fixed the issue. Being on Windows 10, I ran the FT_PROG utility to check the EEPROM settings. With the device loaded into FT_PROG, I expanded the settings tree on the left. Near the bottom, port A and port B are shown. The "driver" tab setting was marked D2XX on both ports (which is good), and the "Hardware" tab setting was set to OPTO Isolate on both. On a whim I changed both back to UART, and the odd behavior on B disappeared! When I re-ran my software, MPSSE on B was responding properly, I was getting nonzero counts out of FT_GetQueueStatus.

Moderator edit: New thread created from this.
 
Top