FTDI Community

General Category => Discussion - Software => Topic started by: Transformer-V on January 28, 2022, 05:00:35 PM

Title: FT232H Asynchronous Bit-Bang. Read data.
Post by: Transformer-V on January 28, 2022, 05:00:35 PM
Hello! :)
How to read AD bus data using the FT_Read(...) function in the  asynchronous bit-bang mode FT_BITMODE_ASYNC_BITBANG? :-\
Can I have a code example in C?
Title: Re: FT232H Asynchronous Bit-Bang. Read data.
Post by: FTDI Community on January 31, 2022, 09:41:32 AM
Hi,

The FT232H CBUS Bit-Bang mode is very similar to that of the FT232R device. This mode is useful as it provides up to 4 additional I/O lines in addition to the UART interface. In the FT232H, the four lines associated with this mode are ACBUS9, 8, 6 and 5. The FT_Prog utility should be used to configure the EEPROM to set these CBUS lines to the I/O mode. In the application, FT_SetBitMode can then be used to set the pin directions and values to be written onto the four lines:
 
FT_SetBitMode(FThandle, CBUS, 0x20)

Where 'CBUS' is an 8-bit value. The upper 4 bits specify the directions of the four pins ACBUS 9/8/6/5 (value 1 sets the pin as output). The lower 4 bits specify the value to be written to any pins set as output. The third parameter 0x20 is setting the device to CBUS Bit-Bang mode.

When in CBUS Bit-Bang mode, FT_GetBitMode can also be used to read the values of the four lines:

FT_GetBitMode(FThandle, PIN_VALUES)

Where 'PIN_VALUES' is an 8-bit value returned by the device. Only the lower 4 bits are used - these contain the values read from ACBUS 9/8/6/5.

Note: The CBUS Bit-Bang mode can only be used with the D2xx drivers and is not available through VCP drivers.

For further details, see the following application note:

http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf (http://url)


we have a number of software examples for C++ and C#.


https://ftdichip.com/software-examples/code-examples/visual-c-examples/ (http://url)
https://ftdichip.com/software-examples/code-examples/csharp-examples/ (http://url)
https://ftdichip.com/software-examples/code-examples/c-builder/ (http://url)

also, here is the D2xx programmers guide:

https://ftdichip.com/wp-content/uploads/2020/08/D2XX_Programmers_GuideFT_000071.pdf (http://url)

Best Regards,

FTDI Community
Title: Re: FT232H Asynchronous Bit-Bang. Read data.
Post by: Transformer-V on February 01, 2022, 03:36:33 AM
Thanks!
I bring the code:

Code: [Select]
FT_HANDLE ftGlobalHandle;
FT_STATUS ftRet;
DWORD ftRxBufferLen,ftReadRetByte,ftWriteRetByte;
unsigned char RxBuffer[65536];
int TestBufferLen,Steeps;
unsigned char TestBuffer[20485760]; //20 MB
char Dig[10];

ftRet=FT_SetBitMode(ftGlobalHandle,0x00,FT_BITMODE_RESET);  //Reset
if(ftRet!=FT_OK)
{
//Error
}

Sleep(50);

//ADBUS:  MSB 0 0 0 0 - in   1 1 1 1 - out LSB 
ftRet=FT_SetBitMode(ftGlobalHandle,0x0f,FT_BITMODE_ASYNC_BITBANG); //0x01 = Asynchronous Bit Bang

if(ftRet!=FT_OK)
{
//Error
}

TestBufferLen=0;
for(Steeps=0;Steeps<31744;Steeps++) //63488/2 = 31744  (65536 - ((65536/64)*2))   AN232B-03_D2XXDataThroughput
{
TestBuffer[TestBufferLen++]=0x0f;
TestBuffer[TestBufferLen++]=0x00;
}

ftWriteRetByte=0;
ftRet=FT_Write(ftGlobalHandle,TestBuffer,TestBufferLen,&ftWriteRetByte);
if(ftRet!=FT_OK)
{
//Error
}

do
{
ftRet=FT_GetQueueStatus(ftGlobalHandle,&ftRxBufferLen);
if(ftRet!=FT_OK)
{
//Error
}
wsprintfA(Dig,"RX_size=%d",ftRxBufferLen);
MessageBoxA(GetDesktopWindow(),Dig,"RX",MB_ICONINFORMATION);
}while(ftRxBufferLen!=65536);

ftRet=FT_Read(ftGlobalHandle,RxBuffer,ftRxBufferLen,&ftReadRetByte); 
if(ftRet!=FT_OK)
{
//Error
}

After reading FT_Read(ftGlobalHandle,RxBuffer.... there will be only zeros in the RxBuffer buffer 0x00 0x00 ...

Did I understand correctly that when writing FT_Write(...) asynchronously to the ADBUS bus, the previous state of the ADBUS bus bit is not saved, and it will not be possible to read them using FT_Read(...) ?
When writing FT_Write(...) asynchronously, the past state of the ADBUS7...0 bus bits is not saved?
In FT_BITMODE_ASYNC_BITBANG (0x01) mode, we either write or read ?

Why FT_GetQueueStatus(ftGlobalHandle,&ftRxBufferLen); returns length ftRxBufferLen = 65536? When recorded 63488
Title: Re: FT232H Asynchronous Bit-Bang. Read data.
Post by: FTDI Community on February 01, 2022, 01:04:01 PM
Hi,

when new data is written, the previous state is not saved. Have a look at the document I sent you:

https://ftdichip.com/wp-content/uploads/2020/08/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf (http://url). table 2.3 explains the D2XX commands.

Best regards

FTDI Community
Title: Re: FT232H Asynchronous Bit-Bang. Read data.
Post by: Transformer-V on February 09, 2022, 02:35:19 AM
Hi,
Thanks for the information provided.

Is it possible to disable the write timeout using the function FT_SetTimeouts(ftHandle, 0, 0) by setting the value of the dwWriteTimeout parameter to zero.

In the function FT_SetDivisor(FT_HANDLE ftHandle, USHORT usDivisor) the usDivisor parameter range can be set from 0 to 65535?

Title: Re: FT232H Asynchronous Bit-Bang. Read data.
Post by: FTDI Community on February 09, 2022, 01:53:24 PM
Hi,

Yes you can disable the timeout by setting it to 0.

the FT_SetDivisor function is no longer required because FT_SetBaudRate automatically calculates the divisor based on the baud rate set.

section 3 of this document https://ftdichip.com/wp-content/uploads/2020/08/AN_120_Aliasing_VCP_Baud_Rates.pdf (http://url) shows how to calculate the divisor for non-standard baud rates.

Best Regards

FTDI Community