To bring up the I2C Interface of the FTDI Chip in C#, it is necessary to import the dll attributes in your C# program:
[DllImportAttribute("libMPSSE.dll", EntryPoint = "I2C_GetNumChannels", CallingConvention = CallingConvention.Cdecl)] static extern uint I2C_GetNumChannels(ref uint NumChannels); [DllImportAttribute("libMPSSE.dll", EntryPoint = "I2C_OpenChannel", CallingConvention = CallingConvention.Cdecl)] static extern uint I2C_OpenChannel(uint index, ref IntPtr handler); [DllImportAttribute("libMPSSE.dll", EntryPoint = "I2C_CloseChannel", CallingConvention = CallingConvention.Cdecl)] static extern uint I2C_CloseChannel(IntPtr handler); [DllImportAttribute("libMPSSE.dll", EntryPoint = "I2C_InitChannel", CallingConvention = CallingConvention.Cdecl)] static extern uint I2C_InitChannel(IntPtr handler, ref ChannelCfg config); [DllImportAttribute("libMPSSE.dll", EntryPoint = "I2C_DeviceRead", CallingConvention = CallingConvention.Cdecl)] static extern uint I2C_DeviceRead(IntPtr handler, UInt32 deviceAddress, UInt32 sizeToTransfer, byte[] buffer, ref UInt32 sizeTransfered, UInt32 options); [DllImportAttribute("libMPSSE.dll", EntryPoint = "I2C_DeviceWrite", CallingConvention = CallingConvention.Cdecl)] static extern uint I2C_DeviceWrite(IntPtr handler, UInt32 deviceAddress, UInt32 sizeToTransfer, byte[] buffer, ref UInt32 sizeTransfered, UInt32 options); [DllImportAttribute("libMPSSE.dll", EntryPoint = "FT_WriteGPIO", CallingConvention = CallingConvention.Cdecl)] static extern uint FT_WriteGPIO(IntPtr handler, byte dir, byte value); [DllImportAttribute("libMPSSE.dll", EntryPoint = "FT_ReadGPIO", CallingConvention = CallingConvention.Cdecl)] static extern uint FT_ReadGPIO(IntPtr handler, ref byte value); [DllImportAttribute("libMPSSE.dll", EntryPoint = "Init_libMPSSE", CallingConvention = CallingConvention.Cdecl)] static extern void Init_libMPSSE();
For rapid start, download our quick example class FTDI.cs. Include the libMPSSE.dll in your project. Don’t forget to select the property “In Ausgabeverzeichnis kopieren = Immer kopieren” (Copy dll into release folder).
Open the FTDI by the Init method (select channel 0=A site or channel 1 = B site). Then use the I2C read/write methods or GPIO helper methods. For more details see in the libMPSSE application note(AN_177) pdf.
Note: don’t forget to connect the xDBUS1 with xDBUS2(!) = SDA