Having trouble with ftdi2232H Usb <--> Serial

Thread Starter

greenberet

Joined Nov 13, 2006
9
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
 
Top