|
FT232RL
Been
busy with the FT232RL USB-to-serial interface chip and have some
information about this chip I would like to share.
Hardware:
Together with Theo
Kleijn (www.pa0kn.nl) have build a board
with a FT232RL and an
Atmega644 on it to monitor all I/O.
Software:
Downloaded MPROG.EXE
version 3.0 to change the settings of the FT232RL.
The I/O
controls C0, C1, C2 and C3 (right) can be controlled through the USB port.
So you can communicate with regular serial information and control extra
four lines.
Also you can
add a Product Description and can read that later on in a Visual Basic
program.
C4 is
put in a clock-out mode, 12 Mhz, and it is feeding the external clock of
the Atmega644.
A
program in Bascom-AVR to monitor the FT232RL on a Atmega644.
'FT232RL and Atmega644 board
$regfile = "m644def.dat"
$crystal = 12000000
'Four LED
Config Porta.7 = Output
Config Porta.6 = Output
Config Porta.5 = Output
Config Porta.4 = Output
'CBUS input van FT232RL
Monitor_cbus3 Alias Pina.3
Monitor_cbus2 Alias Pina.2
Monitor_cbus1 Alias Pina.1
Monitor_cbus0 Alias Pina.0
Monitor_dtr Alias Pinc.3
Monitor_rts Alias Pinc.5
'CBUS 3
Config Monitor_cbus3 = Input
'CBUS 2
Config Monitor_cbus2 = Input
'CBUS 1
Config Monitor_cbus1 = Input
'CBUS 0
Config Monitor_cbus0 = Input
'six LED
Config Portd.7 = Output
Config Portd.6 = Output
Config Portd.5 = Output
Config Portd.4 = Output
Config Portd.3 = Output
Config Portd.2 = Output
Config Monitor_rts = Input 'RTS
Config Monitor_dtr = Input 'DTR
'Leds OFF
Set Portd.7
Set Portd.6
Set Portd.5
Set Portd.4
Set Portd.3
Set Portd.2
Do
If Pina.3 = 0 Then
Porta.7 = 1
Else
Porta.7 = 0
End If
If Pina.2 = 0 Then
Porta.6 = 1
Else
Porta.6 = 0
End If
If Pina.1 = 0 Then
Porta.5 = 1
Else
Porta.5 = 0
End If
If Pina.0 = 0 Then
Porta.4 = 1
Else
Porta.4 = 0
End If
If Monitor_dtr = 1 Then 'DTR
Portd.7 = 1
Else
Portd.7 = 0
End If
If Monitor_rts = 1 Then 'RTS
Portd.6 = 1
Else
Portd.6 = 0
End If
Loop
End
Have
written a program to control the FT232RL in Visual Basic
Create a
module called Module1 in Visual Basic with these lines
'**************************************************************************
' Function declarations
'**************************************************************************
Public Declare Function FT_ListDevices Lib "FTD2XX.dll" (ByVal arg1 As Long, ByVal arg2 As
String,
ByVal dwFlags As Long) As Long
Public Declare Function FT_Open Lib "FTD2XX.dll" (ByVal intDeviceNumber As Integer,
ByRef lnghandle As Long) As Long
Public Declare Function FT_OpenEx Lib "FTD2XX.dll" (ByVal arg1 As String, ByVal arg2 As Long,
ByRef lnghandle As Long) As Long
Public Declare Function FT_Close Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_Read Lib "FTD2XX.dll" (ByVal lnghandle As Long, ByVal lpszBuffer As
String,
ByVal lngBufferSize As Long, ByRef lngBytesReturned As Long) As Long
Public Declare Function FT_Write Lib "FTD2XX.dll" (ByVal lnghandle As Long, ByVal lpszBuffer As
String,
ByVal lngBufferSize As Long, ByRef lngBytesWritten As Long) As Long
Public Declare Function FT_SetBaudRate Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal lngBaudRate As Long) As Long
Public Declare Function FT_SetDataCharacteristics Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal byWordLength As Byte, ByVal byStopBits As Byte, ByVal byParity As Byte) As Long
Public Declare Function FT_SetFlowControl Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal intFlowControl As Integer, ByVal byXonChar As Byte, ByVal byXoffChar As Byte) As Long
Public Declare Function FT_SetDtr Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_ClrDtr Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_SetRts Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_ClrRts Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_GetModemStatus Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByRef lngModemStatus As Long) As Long
Public Declare Function FT_SetChars Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal byEventChar As Byte, ByVal byEventCharEnabled As Byte, ByVal byErrorChar As Byte,
ByVal byErrorCharEnabled As Byte) As Long
Public Declare Function FT_Purge Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal lngMask As Long) As Long
Public Declare Function FT_SetTimeouts Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal lngReadTimeout As Long, ByVal lngWriteTimeout As Long) As Long
Public Declare Function FT_GetQueueStatus Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByRef lngRXBytes As Long) As Long
Public Declare Function FT_SetBreakOn Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_SetBreakOff Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_GetStatus Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByRef lngRXBytes As Long, ByRef lngTXBytes As Long, ByRef lngEventsDWord As Long) As Long
Public Declare Function FT_ResetDevice Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_SetBitMode Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal mask As Byte, ByVal enable As Byte) As Long
Public Declare Function FT_GetBitMode Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByRef pucdata As Long) As Long
' New Functions
Public Declare Function FT_GetEventStatus Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByRef lngEventsDWord As Long) As Long
Public Declare Function FT_SetEventNotification Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal dwEventMask As Long, ByVal Arg As Long) As Long
Public Declare Function FT_SetDivisor Lib "FTD2XX.dll"
(ByVal lnghandle As Long, ByVal Divisor As Single) As Long
Public Declare Function FT_ResetPort Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_RestartInTask Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_StopInTask Lib "FTD2XX.dll" (ByVal lnghandle As Long) As Long
Public Declare Function FT_SetResetPipeRetryCount Lib "FTD2XX.dll" (ByVal lnghandle As Long,
ByVal lngCount As Long) As Long
'************************************************************************
' EEPROM programming function declarations
'************************************************************************
'Public Declare Function FT_EE_Program Lib "FTD2XX.DLL" (ByVal lngHandle As Long,
ByRef lpData As PROGRAM_DATA) As Long
'Public Declare Function FT_EE_Read Lib "FTD2XX.DLL" (ByVal lngHandle As Long,
ByRef lpData As PROGRAM_DATA) As Long
'Public Declare Function FT_EE_UARead Lib "FTD2XX.DLL" (ByVal lngHandle As Long,
ByVal pucData As String, ByVal dwDataLen As Long, ByRef lpdwBytesRead As Long) As Long
'Public Declare Function FT_EE_UAWrite Lib "FTD2XX.DLL" (ByVal lngHandle As Long,
ByVal pucData As String, ByVal dwDataLen As Long) As Long
'Public Declare Function FT_EE_UASize Lib "FTD2XX.DLL" (ByVal lngHandle As Long,
ByRef lpdwSize As Long) As Long
'Public Declare Function FT_EraseEE Lib "FTD2XX.DLL" (ByVal lngHandle As Long) As Long
'***************************************************************************
' Supporting functions for conversion from C to Visual Basic
'***************************************************************************
' Used instead of FT_ListDevices to get the number of devices on the bus
Public Declare Function FT_GetNumDevices Lib "FTD2XX.dll" Alias "FT_ListDevices"
(ByRef arg1 As Long, ByVal arg2 As String, ByVal dwFlags As Long) As Long
'**************************************************************************
' Constant Declarations
'**************************************************************************
' Return codes
Public Const OK = 0
Public Const INVALID_HANDLE = 1
Public Const DEVICE_NOT_FOUND = 2
Public Const DEVICE_NOT_OPENED = 3
Public Const IO_ERROR = 4
Public Const INSUFFICIENT_RESOURCES = 5
Public Const INVALID_PARAMETER = 6
Public Const INVALID_BAUD_RATE = 7
Public Const DEVICE_NOT_OPENED_FOR_ERASE = 8
Public Const DEVICE_NOT_OPENED_FOR_WRITE = 9
Public Const FAILED_TO_WRITE_DEVICE = 10
Public Const EEPROM_READ_FAILED = 11
Public Const EEPROM_WRITE_FAILED = 12
Public Const EEPROM_ERASE_FAILED = 13
Public Const EEPROM_NOT_PRESENT = 14
Public Const EEPROM_NOT_PROGRAMMED = 15
Public Const INVALID_ARGS = 16
Public Const OTHER_ERROR = 17
' Flow Control
Public Const FLOW_NONE = &H0
Public Const FLOW_RTS_CTS = &H100
Public Const FLOW_DTR_DSR = &H200
Public Const FLOW_XON_XOFF = &H400
' Purge rx and tx buffers
Public Const PURGE_RX = 1
Public Const PURGE_TX = 2
' Flags for FT_OpenEx
Public Const OPEN_BY_SERIAL_NUMBER = 1
Public Const OPEN_BY_DESCRIPTION = 2
' Flags for FT_ListDevices
Public Const LIST_BY_NUMBER_ONLY = &H80000000
Public Const LIST_BY_INDEX = &H40000000
Public Const LIST_ALL = &H20000000
' Modem Status
Public Const MODEM_STATUS_CTS = &H10
Public Const MODEM_STATUS_DSR = &H20
Public Const MODEM_STATUS_RI = &H40
Public Const MODEM_STATUS_DCD = &H80
' Event masks
Public Const EVENT_RXCHAR = 1
Public Const EVENT_MODEM_STATUS = 2
' Baud Rates
Public Const BAUD_300 = 300
Public Const BAUD_600 = 600
Public Const BAUD_1200 = 1200
Public Const BAUD_2400 = 2400
Public Const BAUD_4800 = 4800
Public Const BAUD_9600 = 9600
Public Const BAUD_14400 = 14400
Public Const BAUD_19200 = 19200
Public Const BAUD_38400 = 38400
Public Const BAUD_57600 = 57600
Public Const BAUD_115200 = 115200
Public Const BAUD_230400 = 230400
Public Const BAUD_460800 = 460800
Public Const BAUD_921600 = 921600
' Word Lengths
Public Const BITS_8 = 8
Public Const BITS_7 = 7
Public Const BITS_6 = 6
Public Const BITS_5 = 5
' Stop Bits
Public Const STOP_BITS_1 = 0
Public Const STOP_BITS_1_5 = 1
Public Const STOP_BITS_2 = 2
' Parity
Public Const PARITY_NONE = 0
Public Const PARITY_ODD = 1
Public Const PARITY_EVEN = 2
Public Const PARITY_MARK = 3
Public Const PARITY_SPACE = 4
Create a
Form1 with these lines:
Dim lngretval As Long
Dim lnghandle As Long
Dim intindex As Long
Dim flFailed As Boolean
Dim flTimedout As Boolean
Dim flFatalError As Boolean
Dim ftStatus As Long
Dim lngNumDevices As Long
Dim strSerialNumber As String * 256
Dim strDescription As String * 256
Dim strSerialNumber2 As String * 256
Dim strDescription2 As String * 256
Const FT_OK = 0
Const FT_LIST_BY_NUMBER_ONLY = &H80000000
Const FT_LIST_ALL = &H20000000
Const FT_LIST_BY_INDEX = &H40000000
Const FT_OPEN_BY_DESCRIPTION = 2
Private Sub Command1_Click()
flFailed = True
intindex = 0
' Get device serial number
If FT_GetNumDevices(lngNumDevices, vbNullString, FT_LIST_BY_NUMBER_ONLY) <> FT_OK Then
loggerlist.AddItem ("FT_GetNumDevices failed")
Exit Sub
Else
loggerlist.AddItem ("NumDevices " & lngNumDevices)
End If
If FT_ListDevices(0, strDescription, FT_LIST_BY_INDEX Or FT_OPEN_BY_DESCRIPTION) <> FT_OK Then
loggerlist.AddItem ("ListDevices failed")
Exit Sub
Else
loggerlist.AddItem ("Device Description " & strDescription)
End If
If FT_ListDevices(0, strSerialNumber, FT_LIST_BY_INDEX Or FT_OPEN_BY_SERIAL_NUMBER) <> FT_OK Then
loggerlist.AddItem ("ListDevices failed")
Exit Sub
Else
loggerlist.AddItem ("Serial Number " & strSerialNumber)
End If
If FT_Open(0, lnghandle) = FT_OK Then
loggerlist.AddItem "Open OK"
Else
loggerlist.AddItem "Open Failed"
Exit Sub
End If
Me.Refresh
If FT_ResetDevice(lnghandle) = FT_OK Then
loggerlist.AddItem "Reset OK"
Else
loggerlist.AddItem "Reset Failed"
End If
Me.Refresh
If FT_SetDtr(lnghandle) = FT_OK Then
loggerlist.AddItem "FT_SetDTR OK"
Else
loggerlist.AddItem "FT_SetDTR failed"
End If
Me.Refresh
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
If FT_ClrDtr(lnghandle) = FT_OK Then
loggerlist.AddItem "FT_ClrDTR OK"
Else
loggerlist.AddItem "FT_ClrDTR failed"
End If
Me.Refresh
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
If FT_SetRts(lnghandle) = FT_OK Then
loggerlist.AddItem "FT_SetRTS OK"
Else
loggerlist.AddItem "FT_SetRTS failed"
End If
Me.Refresh
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
If FT_ClrRts(lnghandle) = FT_OK Then
loggerlist.AddItem "FT_ClrRTS OK"
Else
loggerlist.AddItem "FT_ClrRTS failed"
End If
Me.Refresh
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
'here the four bits are activated
'
loggerlist.AddItem "Clear all bit-led's"
Me.Refresh
lngretval = FT_SetBitMode(lnghandle, &HF0, &H20)
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
loggerlist.AddItem "Set bit-led 1"
Me.Refresh
lngretval = FT_SetBitMode(lnghandle, &HF1, &H20)
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
loggerlist.AddItem "Set bit-led 2"
Me.Refresh
lngretval = FT_SetBitMode(lnghandle, &HF2, &H20)
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
loggerlist.AddItem "Set bit-led 3"
Me.Refresh
lngretval = FT_SetBitMode(lnghandle, &HF4, &H20)
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
loggerlist.AddItem "Set bit-led 4"
Me.Refresh
lngretval = FT_SetBitMode(lnghandle, &HF8, &H20)
For x = 1 To 10000
For y = 1 To 1000
Next y
Next x
loggerlist.AddItem "Clear bit-led's"
Me.Refresh
lngretval = FT_SetBitMode(lnghandle, &HF0, &H20)
If FT_Close(lnghandle) = FT_OK Then
loggerlist.AddItem "Close OK"
Else
loggerlist.AddItem "Close Failed"
End If
Me.Refresh
End Sub
And here
the result...
Now you can control the
FT232RL-lines.
If you push the Activate FT232RL button the LEDs on the Atmega644 board will
go on and off.
And here
a link with some more information about the FT232RL (in German)
USB-LCD-2
https://www.dlpdesign.com/drivers/D2XXPG21.pdf
|