I2C and UART Protocol with FT2232D chip

Thread Starter

mainevent

Joined Dec 7, 2009
11
Hi, I need help..I am new to programming and I have been trying to run the I2C and UART protocol in turns using the FT2232D chip. with examples from the FTDI site.. I was able to put a few things together but I am just a little bit confused. I downloaded all the programming manuals from the site but I am having problems with the GPIOs. I an using GPIOL2 and GPIOL3 to control an analog switch and a power mosfet butthe programming manual is a bit confusing because it suggests that I will be unable to control that of the FT2232D chip but I can control that of the FT..H chip.

This is d bit of code i was able to put together;

Dim ftStatus As Integer
Dim ftHandle As Integer = 0
Dim TimerValue As Byte = 0
Dim ClkFrequencyDivisor As Integer = I2C_Driver.MIN_FREQ_CLOCK_DIVISOR 'Default at 400KHz
Dim HighInputOutputPinsData As I2C_Driver.FTC_INPUT_OUTPUT_PINS = New I2C_Driver.FTC_INPUT_OUTPUT_PINS
Dim HighPinsInputData As I2C_Driver.FTC_LOW_HIGH_PINS = New I2C_Driver.FTC_LOW_HIGH_PINS
Dim WriteControlBuffer() As Byte = New Byte((256 - 1)) {}
Dim ReadData() As Byte = New Byte((65536 - 1)) {}
Dim ReadDataByteAddress As Integer = 0
Dim DataReadType As Integer = 0
Dim NumDataBytesToRead As Long = 0
Dim ReadDataBuffer() As Byte = New Byte((65536 - 1)) {}
Dim ReadDataIndex As Integer = 0
Dim DeviceChipSize As Integer = I2C_Driver.MAX_I2C_24C64_CHIP_SIZE_IN_BYTES 'Default at 8192Bytes

'Disable UART button
UART_button.Enabled = False
DisC_button.Enabled = True

ftStatus = I2C_Driver.I2C_Open(ftHandle)

' Check the device type
If I2C_Control.drp_DeviceList.SelectedIndex <> -1 Then
If I2C_Control.drp_DeviceList.SelectedText = "24C16" Then
DeviceChipSize = I2C_Driver.MAX_I2C_24C16_CHIP_SIZE_IN_BYTES
ElseIf I2C_Control.drp_DeviceList.SelectedText = "24C32" Then
DeviceChipSize = I2C_Driver.MAX_I2C_24C32_CHIP_SIZE_IN_BYTES
ElseIf I2C_Control.drp_DeviceList.SelectedText = "24C64" Then
DeviceChipSize = I2C_Driver.MAX_I2C_24C64_CHIP_SIZE_IN_BYTES
ElseIf I2C_Control.drp_DeviceList.SelectedText = "24C128" Then
DeviceChipSize = I2C_Driver.MAX_I2C_24C128_CHIP_SIZE_IN_BYTES
ElseIf I2C_Control.drp_DeviceList.SelectedText = "24C256" Then
DeviceChipSize = I2C_Driver.MAX_I2C_24C256_CHIP_SIZE_IN_BYTES
End If
End If

' Choose between 100KHz and 400KHz
If I2C_Control.drp_ClockList.SelectedIndex <> -1 Then
If I2C_Control.drp_ClockList.SelectedText = "100KHz" Then
ClkFrequencyDivisor = I2C_Driver.MAX_FREQ_CLOCK_DIVISOR
ElseIf I2C_Control.drp_DeviceList.SelectedText = "400KHz" Then
ClkFrequencyDivisor = I2C_Driver.MIN_FREQ_CLOCK_DIVISOR
End If
End If
If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
ftStatus = I2C_Driver.I2C_InitDevice(ftHandle, ClkFrequencyDivisor)

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then

End If

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
ftStatus = I2C_Driver.I2C_GetDeviceLatencyTimer(ftHandle, TimerValue)

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
ftStatus = I2C_Driver.I2C_SetDeviceLatencyTimer(ftHandle, 50)

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
ftStatus = I2C_Driver.I2C_GetDeviceLatencyTimer(ftHandle, TimerValue)

ftStatus = I2C_Driver.I2C_SetDeviceLatencyTimer(ftHandle, 16)

ftStatus = I2C_Driver.I2C_GetDeviceLatencyTimer(ftHandle, TimerValue)
End If
End If
End If
End If

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
ftStatus = I2C_Driver.I2C_SetLoopback(ftHandle, False)
End If

If (ftStatus = I2C_Driver.FTC_SUCCESS) And _
ClkFrequencyDivisor = I2C_Driver.MAX_FREQ_CLOCK_DIVISOR Then
ftStatus = I2C_Driver.I2C_SetMode(ftHandle, I2C_Driver.FAST_MODE)
ElseIf ClkFrequencyDivisor = I2C_Driver.MIN_FREQ_CLOCK_DIVISOR Then
ftStatus = I2C_Driver.I2C_SetMode(ftHandle, I2C_Driver.STANDARD_MODE)
End If

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
HighInputOutputPinsData.bPin1InputOutputState = True
HighInputOutputPinsData.bPin1LowHighState = True
HighInputOutputPinsData.bPin2InputOutputState = True
HighInputOutputPinsData.bPin2LowHighState = True
ftStatus = I2C_Driver.I2C_SetGPIOs(ftHandle, HighInputOutputPinsData)
ftStatus = I2C_Driver.I2C_GetGPIOs(ftHandle, HighPinsInputData)
MsgBox(" Current Source Analog Switch is ON")
Else
Exit Sub
End If

' Random Address read to confirm if external EEPROM can be accessed and is detected.

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
Do
WriteControlBuffer(0) = &HA1
For ReadDataIndex = 0 To (DeviceChipSize - 8191)
ReadData(ReadDataIndex) = 0
Next

ReadDataByteAddress = 0
DataReadType = I2C_Driver.BYTE_READ_TYPE

If (DataReadType = I2C_Driver.BYTE_READ_TYPE) Then
NumDataBytesToRead = I2C_Driver.BYTE_READ_TYPE
End If
Loop
End If

ftStatus = I2C_Driver.I2C_Read(ftHandle, WriteControlBuffer, 3, True, 20, DataReadType, ReadDataBuffer, NumDataBytesToRead)

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
If (DataReadType = I2C_Driver.BYTE_READ_TYPE) Then
ReadData(&H0) = ReadDataBuffer(0)
READ_box.Items.Add(ftHandle.ToString)
READ_box.Items.Add("External EEPROM detected!")

'Enable Relevant buttons
WRITE_button.Enabled = True
READ_button.Enabled = True

'Set Global Variable to true
Me.ConnStatus = True

Else
READ_box.Items.Add("External EEPROM not detected!")
WRITE_button.Enabled = False
READ_button.Enabled = False

End If
End If

If (ftStatus = I2C_Driver.FTC_SUCCESS) Then
I2C_Driver.Sleep(100)
Exit Sub
End If



please help!!
 
Top