Author Topic: FTDI FT4232 Mini Module Bit Bang  (Read 29642 times)

Brownout

  • Member
  • ***
  • Posts: 14
FTDI FT4232 Mini Module Bit Bang
« on: September 29, 2013, 05:43:16 pm »
Hello all,

I've been researching this for a couple days, and I've looked over this forum for answers.  I'm using the FT4232 Mini-Module and attempting to get bit-bang mode working.  My code is adapted from Embedded USB Design By Eample by John Hyde.  The progrma successfully opens and configures the device, but I see on output on pin AD1 when I write to the device.  I know the examples are for a different FTDI device; I can not find examples specifically for the FT4232 device.  Any help is appreciated.  My code is shown below:

Code: [Select]
// ftdi_hello_world_led.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <math.h>
#include "ftd2xx.h"
//#include <ftdi.h>


int _tmain(int argc, _TCHAR* argv[])
{
unsigned char c = 0xff;
DWORD bytes;
FT_STATUS FT_Status;
    FT_HANDLE handle;
printf("FTDI Hello World\n");
DWORD DeviceCount;
FT_Status = FT_CreateDeviceInfoList(&DeviceCount);
if (FT_Status) return printf("FT_CreateDeviceInfoList failed (%d)", FT_Status);
if (DeviceCount == 0) return printf("No FTDI devices attached\n");
if(FT_Open(0, &handle) != FT_OK) {
printf("Cannot open device\n");
return 1;
}
FT_SetBaudRate(handle, 921600);
FT_SetBitMode(handle, 0xff, 0x4); //handle, mask, mode
FT_Write(handle, &c, 0xff, &bytes);
for(;;) {}
return 0;
}


Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #1 on: September 30, 2013, 04:15:34 am »
Quote
FT_SetBitMode(handle, 0xff, 0x4); //handle, mask, mode
FT_Write(handle, &c, 0xff, &bytes);
You are setting Synchronous bit-bang mode (mode 4) to the device.
In this mode, just single byte is supposed to be written at a time to the device.
This byte appears immediately at the device pins, which are set as output,
regardless of the baud rate setting (FT_SetBaudRate() is useless).
But you write 0xff bytes to the device, even beyond the buffer size.
Write just one byte.

Tsuneo

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #2 on: September 30, 2013, 08:12:51 pm »
Hi, Thanks for your prompt reply.

Writing more than one byte was a mistake on my part.  I intended to only change the data of 0xff, and not the count.  As for the baud rate it is used for timing the arrival of array data in synchronous bit-bang mode, and was used in the example.  Anyway, I tried the code with the suggested changes, but no dice:

Code: [Select]
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <math.h>
#include "ftd2xx.h"
//#include <ftdi.h>


int _tmain(int argc, _TCHAR* argv[])
{
unsigned char c = 0xff;
DWORD bytes;
FT_STATUS FT_Status;
    FT_HANDLE handle;
printf("FTDI Hello World\n");
DWORD DeviceCount;
FT_Status = FT_CreateDeviceInfoList(&DeviceCount);
if (FT_Status) return printf("FT_CreateDeviceInfoList failed (%d)", FT_Status);
if (DeviceCount == 0) return printf("No FTDI devices attached\n");
if(FT_Open(0, &handle) != FT_OK) {
printf("Cannot open device\n");
return 1;
}
FT_SetBitMode(handle, 0xff, 0x4); //handle, mask, mode
FT_Write(handle, &c, 1, &bytes);
for(;;) {}
return 0;
}

Seems I can comunicate just fine with the device, but cannot get any output from writing to it.  Am I doing something wrong?  Also, how do i know I'm writing to port A?  I can't find a function to select port A, so I'm assuming the software will write correctly.

Thanks again

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #3 on: September 30, 2013, 09:36:49 pm »
Which port are you monitoring?
The sent byte appears on these pins,
ADBUS0-ADBUS3 (pin 16-19)
ADBUS4-ADBUS7 (pin 21-24)

Quote
As for the baud rate it is used for timing the arrival of array data in synchronous bit-bang mode, and was used in the example.

I don't know about the original example, but it sounds like Asynchronous bit-bang mode (mode 1), in which the array data, sent to the device, is put to the ports one byte by one at the interval of the baudrate. If you would like to apply this mode, change the ucMode of FT_SetBitmode() to 1.

Tsuneo

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #4 on: October 01, 2013, 08:19:03 am »
I'm monitoring bit AD0, pin 16 of the device.  For the mini module, I have a resistor/LED connected between pin 7 (AD0) and pin 6 (ground).  I've tested the LED buy pulling out pin 7 and touching to VCC.  When I run my program, however, nothing happens.  I've also tried asynchronous mode, with and without setting up the baud rate.

How do you know which port is selected?  Do all I/O's just become a 32bit output register in bit bang?  In that case, how would I designate one port for bit bang and a different port for serial?

I've tried lookin up the answers, but haven't been able to come up with them yet.
« Last Edit: October 01, 2013, 08:20:46 am by Brownout »

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #5 on: October 01, 2013, 11:09:20 am »
Hi again,

I think I may have found an answer to part of my question.  To control which port is serial and which is bit bang, one of the serial mode must be chosen, and dll functions will be avaliable to set up GPIO.  At least that is the way I interpret some of the literature???

So, I'm guessing that in B-B mode, all 32 IO's are available as GPIO's at once, and 32-bit reads and writes are used to access the individual pins.  So, in essence, my code is correct, and there is another problem.

Please advise.

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #6 on: October 01, 2013, 01:25:38 pm »
Ah, FT4232H (VID/PID = 0x0403/0x6011) isn't included in the default VID/PID list of D2XX.

D2XX Programmer's Guide
http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer's_Guide(FT_000071).pdf

FT_SetVIDPID()
Remarks
By default, the driver will support a limited set of VID and PID matched devices (VID 0x0403 with PIDs 0x6001, 0x6010, 0x6006 only).
In order to use the driver with other VID and PID combinations the FT_SetVIDPID function must be used prior to calling FT_ListDevices, FT_Open, FT_OpenEx or FT_CreateDeviceInfoList.


FT_SetVIDPID() should be called as the first call of D2XX routines, to specify FT4232H
Code: [Select]
 FT_SetVIDPID( 0x0403, 0x6011 );    // specify FT4232H
  FT_Status = FT_CreateDeviceInfoList(&DeviceCount);
  ...

Quote
I think I may have found an answer to part of my question.  To control which port is serial and which is bit bang, one of the serial mode must be chosen, and dll functions will be avaliable to set up GPIO... So, I'm guessing that in B-B mode, all 32 IO's are available as GPIO's at once, and 32-bit reads and writes are used to access the individual pins.

Unfortunately, FT4232H doesn't work like you suppose.

Single FT4232H provides four UARTs or four (bit-bang) 8bits ports, which work independently each other. You may choose one 8bits port by FT_Open().

When just single FT4232H connects to your PC,
FT_Open(0, &handle_A) returns handle_A to channel A
FT_Open(1, &handle_B) : handle_B to channel B
FT_Open(2, &handle_C) : handle_C to channel C
FT_Open(3, &handle_D) : handle_D to channel D

Tsuneo
« Last Edit: October 01, 2013, 01:27:56 pm by Tsuneo »

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #7 on: October 02, 2013, 10:12:12 am »
Hi Tsuneo,

Thanks again for your efforts in helping me solve this issue.  I really apprecaite it.  What you've written about the 8-bit ports being opened and accessed individually makes sense.  I couldn't extract that from the documentaion.  The docs said that devices are specified in FT_Open, but now I know that devices=ports.

Last night, I was able to open the device and build an information table using FT_GetDeviceInfoList(), and display the list.  Communication with the driver is working, but I'm still not able to affect the output of the I/O.  I'm beginning to wonder if I should back up to a more mature product.  Or else, maybe I should try it on another computer.  Maybe the driver just isn't working properly on my old laptop.

Anyway, thanks again.  I'll post any updates when I have them. 

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #8 on: October 03, 2013, 05:36:15 am »
Hi, I tested your code on a FT4232H mini module on my side, and noticed this point ;)

Maybe, you don't yet connect VIO pins (CN2 - pin11/21) to VCC3V3 (CN2 - pin1/3/5) on the FT4232H mini module, which provides power rail to the port pins.

A couple of corrections of above my posts:

1) "FT_SetVIDPID( 0x0403, 0x6011 );" is not required.
D2XX library already has this VID/PID as the default.

2) FT_SetBitMode() determines the tick interval on port IN/OUT operation.

3) "Synchronous" bit-bang means that IN and OUT operation on the port synchronously occurs.
You may put an array data to the port, which appears one byte one at the interval corresponds to FT_SetBitMode()

Sorry, I hope my misunderstandings don't make you confused.

Tsuneo

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #9 on: October 03, 2013, 08:04:22 am »
Hi again,

So when you tested my code, did it work?  Here is how I connected the power on my board (from DS_FT4232H_Mini_Module datasheet:

Quote
USB Bus-powered:
1) Connect VBUS to VCC (CN3, pin 1 to CN3, pin 3). This connection takes the power from the USB bus (VBUS) and connects it to the voltage regulator input on the FT4232H Mini Module. The voltage regulator, in turn, provides V3V3, VPLL and VUSB power inputs to the FT4232H chip.
2) Connect V3V3 to VIO (CN2, pins 1, 3 & 5 to CN2, pins 11 & 21 and CN3, pins 12 & 22). This connection provides the correct 3.3VDC operating voltage for VCCIO on the FT4232H chip.

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #10 on: October 03, 2013, 08:33:26 am »
Quote
So when you tested my code, did it work?

Yah, worked.
I put a multi-meter at AD0 to see its voltage.
Your code was modified a little, to see voltage change by key-in.

Code: [Select]
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <math.h>
#include "ftd2xx.h"
//#include <ftdi.h>

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned char c = 0xff;
    DWORD bytes;
    FT_STATUS FT_Status;
    FT_HANDLE handle;
    printf("FTDI Hello World\n");
    DWORD DeviceCount;
    FT_Status = FT_CreateDeviceInfoList(&DeviceCount);
    if (FT_Status) return printf("FT_CreateDeviceInfoList failed (%d)", FT_Status);
    if (DeviceCount == 0) return printf("No FTDI devices attached\n");
    if(FT_Open(0, &handle) != FT_OK) {
        printf("Cannot open device\n");
        return 1;
    }
    FT_SetBaudRate(handle, 921600);
    FT_SetBitMode(handle, 0xff, 0x4); //handle, mask, mode

    FT_Write(handle, &c, 1, &bytes);
    getchar();

    c=0x00;
    FT_Write(handle, &c, 1, &bytes);
    getchar();

    FT_Close(handle);
    return 0;
}

Quote
Here is how I connected the power on my board

Fine.

Tsuneo

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #11 on: October 03, 2013, 09:35:02 am »
Code: [Select]
Yah, worked.
I put a multi-meter at AD0 to see its voltage.
Your code was modified a little, to see voltage change by key-in.


That's a tremendous help.  I'll try on a different computer and update when I have results.

Thanks!

Brownout

  • Member
  • ***
  • Posts: 14
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #12 on: February 10, 2014, 06:01:28 pm »
Well, at long last this is working.  I threw this in the back of the junk drawer in disgust.  But today I dug it out and went over everything I could think of.  Turns out I had a simple wiring error that I just couldn't see when I began this project, no matter how many times I checked it over.  Today, I spotted it right away.  Now I can turn LED's on and off using Bit Bang mode.  Now on to using the MPSSE.

Thanks again for the help!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: FTDI FT4232 Mini Module Bit Bang
« Reply #13 on: February 10, 2014, 06:11:49 pm »
Time is your friend! Glad you got it working.