Having trouble with ftdi2232H Usb <--> Serial

Discussion in 'The Projects Forum' started by greenberet, Mar 28, 2010.

  1. greenberet

    Thread Starter New Member

    Nov 13, 2006
    9
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. #include <ftd2xx.h>
    3. #include <stdio.h>
    4. #include <stdlib.h>
    5. #include <iostream>
    6.  
    7. using namespace std;
    8.  
    9. int main()
    10. {
    11.  
    12. FT_STATUS ftStatus;
    13. FT_DEVICE_LIST_INFO_NODE *devInfo;
    14. DWORD numDevs;
    15. // create the device information list
    16. ftStatus = FT_CreateDeviceInfoList(&numDevs);
    17.  
    18. if (ftStatus == FT_OK) {        printf("Number of devices is %d\n",numDevs); }
    19.  
    20. if (numDevs > 0) {
    21.        // allocate storage for list based on numDevs
    22.        devInfo =
    23. (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
    24.        // get the device information list
    25.        ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs);
    26.        if (ftStatus == FT_OK) {
    27.               for (int i = 0; i < numDevs; i++) {
    28.                      printf("Dev %d:\n",i);
    29.                      printf(" Flags=0x%x\n",devInfo[i].Flags);
    30.                      printf(" Type=0x%x\n",devInfo[i].Type);
    31.                      printf(" ID=0x%x\n",devInfo[i].ID);
    32.                      printf(" LocId=0x%x\n",devInfo[i].LocId);
    33.                      printf(" SerialNumber=%s\n",devInfo[i].SerialNumber);
    34.                      printf(" Description=%s\n",devInfo[i].Description);
    35.                      printf(" ftHandle=0x%x\n",devInfo[i].ftHandle);
    36.               }
    37.        }
    38. }
    39.  
    40.  
    41. FT_HANDLE hdev1;
    42. ftStatus=FT_OpenEx(devInfo[1].SerialNumber, FT_OPEN_BY_SERIAL_NUMBER, &hdev1);
    43.  
    44. if(ftStatus!=FT_OK )
    45. {
    46. cout<<"Device Error"<<endl;
    47. exit(1);
    48. }
    49.  
    50. if(FT_ResetDevice(hdev1)!=FT_OK) cout<<"Error"<<endl;
    51. if(FT_SetUSBParameters(hdev1, 65535, 65535)!=FT_OK) cout<<"Error"<<endl;
    52. FT_SetChars(hdev1, false, 0, false, 0);
    53. if(FT_SetTimeouts(hdev1, 5000, 5000)!=FT_OK) cout<<"Error"<<endl;
    54. if(FT_SetBitMode(hdev1, 0, 0x00)!=FT_OK) cout<<"Error"<<endl;
    55.  
    56. sleep(2);
    57. UCHAR bitmode;
    58. if(FT_SetBitMode(hdev1, 0, 0x02)!=FT_OK) cout<<"Error"<<endl;
    59.  
    60.  
    61. DWORD BytesWritten=0;
    62. UCHAR command1[3];
    63. command1[0]=0xAB;
    64.  
    65. FT_Write(hdev1, command1, 1, &BytesWritten);
    66.  
    67. cout<<"Written "<<BytesWritten<<endl;
    68.  
    69. unsigned char readbuf[10];
    70. BytesWritten=0;
    71. FT_Read(hdev1, readbuf, 10, &BytesWritten);
    72. for(int i=0;i<BytesWritten;i++)
    73. printf("Read %x \n ", readbuf[i]);
    74.  
    75. FT_Close(hdev1);
    76.  
    77. return 0;
    78. }
    79.  
    80. [/i][/i][/i][/i][/i][/i][/i][/i]



    The output is:

    Code ( (Unknown Language)):
    1.  
    2. Number of devices is 2
    3. Dev 0:
    4.  Flags=0x2
    5.  Type=0x6
    6.  ID=0x4036010
    7.  LocId=0x0
    8.  SerialNumber=FTT3AMJI A
    9.  Description=USB <-> Serial Cable A
    10.  ftHandle=0x0
    11. Dev 1:
    12.  Flags=0x2
    13.  Type=0x6
    14.  ID=0x4036010
    15.  LocId=0x0
    16.  SerialNumber=FTT3AMJI B
    17.  Description=USB <-> Serial Cable B
    18.  ftHandle=0x0
    19. Written 1
    20.  
    21.  
    It works for channel A but not for B. Im using Fedora 12 and kernel 2.6.31-12

    Thanks,
    Srinivasan Iyer
    India
     
Loading...