FTDI Community

General Category => Discussion - Software => Topic started by: dania on August 02, 2021, 08:42:19 AM

Title: FT4232H I2C Library recommendations
Post by: dania on August 02, 2021, 08:42:19 AM
Hello,
for I2C are two libraryes: FTCI2C.dll and LibMPSSE.dll. Which library do you recommend? I didn't find how to work with GPIOL lines in libmpsse.

I2C and GPIOs at Port A:
ADBUS0 = SCL, ADBUS1 and ADBUS2 wired together = SDA, ADBUS4 - ADBUS6 = inputs, ADBUS7 = output (drive relay via transistor)
Title: Re: FT4232H I2C Library recommendations
Post by: FTDI Community on August 02, 2021, 11:47:16 AM
Hello,

The FTCI2C.dll is no longer supported so we would recommend using the LibMPSSE.dll for new projects. however unfortunately the LibMPSSE helper library only supports GPIO functionality on the GPIOH pins.

There are two options for programming the MPSSE on the device to act as a SPI/I2C bridge, the first being to utilise LibMPSSE
The second option is to use raw D2XX commands to issue opcodes and data to the device, please see the following for a list of MPSSE opcodes:
https://www.ftdichip.com/Support/Documents/AppNotes/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf (https://www.ftdichip.com/Support/Documents/AppNotes/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf)

You will need to utilise a D2XX approach if you wish to utilise the GPIOL pins in your application.

Please see the following for an example of using raw D2XX commands in an I2C MPSSE application:
https://ftdichip.com/wp-content/uploads/2020/08/AN_113_FTDI_Hi_Speed_USB_To_I2C_Example.pdf (https://ftdichip.com/wp-content/uploads/2020/08/AN_113_FTDI_Hi_Speed_USB_To_I2C_Example.pdf)

The MPSSE Basics application note may also be useful to you:
https://www.ftdichip.com/Support/Documents/AppNotes/AN_135_MPSSE_Basics.pdf (https://www.ftdichip.com/Support/Documents/AppNotes/AN_135_MPSSE_Basics.pdf)

Best Regards,
FTDI Community
Title: Re: FT4232H I2C Library recommendations
Post by: dania on August 02, 2021, 02:07:35 PM
I want to add to ftdi_mid.c:
Code: [Select]
FTDI_API FT_STATUS FT_WriteGPIOL(FT_HANDLE handle, uint8 dir, uint8 value)
{
FT_STATUS status;
uint8 buffer[3];
DWORD bytesWritten = 0;
uint32 bufIdx = 0;

FN_ENTER;
buffer[bufIdx++] = MPSSE_CMD_SET_DATA_BITS_LOWBYTE;
buffer[bufIdx++] = value;
buffer[bufIdx++] = dir;

status = varFunctionPtrLst.p_FT_Write(handle,buffer,bufIdx,&bytesWritten);
FN_EXIT;
return status;
}

FTDI_API FT_STATUS FT_ReadGPIO(FT_HANDLE handle,uint8 *value)
{
FT_STATUS status;
uint8 buffer[2];
DWORD bytesTransfered = 0;
DWORD bytesToTransfer = 0;
UCHAR readBuffer[10];

FN_ENTER;
buffer[bytesToTransfer++] = MPSSE_CMD_GET_DATA_BITS_LOWBYTE;
buffer[bytesToTransfer++] = MPSSE_CMD_SEND_IMMEDIATE;

status = varFunctionPtrLst.p_FT_Write(handle,buffer,bytesToTransfer,\
&bytesTransfered);
CHECK_STATUS(status);
DBG(MSG_DEBUG,"bytesToTransfer=0x%x bytesTransfered=0x%x\n",\
(unsigned)bytesToTransfer,(unsigned)bytesTransfered);
bytesToTransfer = 1;
bytesTransfered = 0;
status = varFunctionPtrLst.p_FT_Read(handle,readBuffer,bytesToTransfer,\
&bytesTransfered);
CHECK_STATUS(status);
DBG(MSG_DEBUG,"bytesToTransfer=0x%x bytesTransfered=0x%x\n",\
(unsigned)bytesToTransfer,(unsigned)bytesTransfered);
if(bytesToTransfer != bytesTransfered)
status = FT_IO_ERROR;
*value = readBuffer[0];

FN_EXIT;
return status;
}


and compile a new dll.
Title: Re: FT4232H I2C Library recommendations
Post by: FTDI Community on August 02, 2021, 03:41:20 PM
Hello,

The LibMPPSE library is essentially a wrapper library for standard D2XX API calls, the source is available is required, and it appears you already have access to this.
Please fell free to modify the LibMPSSE source code as required for your given application and produce a custom DLL.

Best Regards,
FTDI Community