|
|
|
|
|
AN #179 - DEMO Vinculum VNC1L USB host controller and Atmega644 |
|
by F. Kaemper The Vinculum VDIP1 module is a module using the FTDI VNC1L USB host controller chip. It comes in a 24 pin DIP socket and provides UART, SPI and parallel FIFO interfaces to a microcontroller.
Sample schematic:
Sample code:
' DEMO Vinculum VNC1L USB host controller and Atmega644
' written by F. Kaemper
' The Vinculum VDIP1 module is a module using the FTDI VNC1L USB host controller
' chip. It comes in a 24 pin DIP socket and provides UART, SPI and parallel
' FIFO interfaces to a microcontroller.
' In this application note only the UART communication is being demonstrated.
' Download from www.ftdichip.com:
' Vinculum firmware customizer utility (V. 1.1b).
' latest VDAP disk and peripheral firmware reflash update file (FTD, version 3.68).
' Vinculum manual.
' The Vinculum has to be configured by setting the jumpers for UART mode (see manual).
' Push USB stick into your computer (be aware, some USB sticks might not work with the Vinculum, see manual),
' format the USB stick with FAT32 or FAT 16 and 512 byte sector size,
' copy the downloaded firmware FTD file into the root directory of the USB stick,
' run the firmware customizer utility,
' follow the program and open the firmware FTD file on the USB stick,
' set communication protocol to IPA (ASCII commands to use the Vinculum),
' set baudrate to 115200 8N1,
' keep CTS/RTS control (not used here),
' give a 3 character code to this firmware (these characters will be displayed when asking for the firmware version),
' save customized firmware to USB stick,
' rename firmware file to FTRFB.FTD (Vinculum expects this filename for updating its firmware),
' Configure your terminal program with 115200 baud 8N1, for direct communication to the Vinculum activate "local echo" under ASCII configuration.
' push USB stick into Vinculum,
' power up the AVR with this program loaded,
' the LED's flicker when updating the firmware and the Vinculum boot/update information will be displayed in the terminal.
' For this AVR program to work, the USB stick needs a file todo.txt in the root directory as described later.
' If you ever want to use a direct serial communication with the Vinculum
' without an AVR via a MAX232, then you need to configure Hyperterminal under
' "ASCII configuration" by checking "local echo of sent lines" and "add line
' feed when receiving data".
' hardware:
' hardware serial port for connection to terminal program
' define 2 pins as software serial ports for connection to Vinculum (do not forget to cross TXD and RXD lines),
' connect CTS of Vinculum (pin AD3) to GND (CTS/RTS handshake is not used in this program, this would need a buffered hardware UART),
' optional: connect RESET pin of Vinculum to RESET pin of AVR for easy resetting of both units
' DEMO functions of this program:
' check for USB stick present
' read data from a file on USB stick configuring this program, write measured data into a file and import this file later into Excel
' display DIRECTORY of USB stick
' display information about USB stick
' display firmware version of Vinculum
' direct connection from keyboard to Vinculum via AVR for entering of simple commands
$regfile = "m644def.dat"
$crystal = 16000000
$baud = 115200
Open "comd.7:115200,8,n,1" For Output As #1 ' pin 21
Open "comc.7:115200,8,n,1" For Input As #2 ' pin 29
Const Max_line_number = 15 ' defines array size and others
Dim I As Byte
Dim Ending_loop As Byte
Dim Usb_stick_present As Byte
Dim N As Integer
Dim Ad As Integer
Dim Samples As Word
Dim Delayms As Word
Dim Channels As Word
Dim Inp_str(max_line_number) As String * 26 ' max. lines answer from Vinculum with max. 26 characters each
Dim Command_str As String * 20
Dim Vinc_str As String * 20
Dim S As String * 80
Dim S_length As Byte
Start Adc
Echo Off
Do ' main DO ... LOOP
Command_str = "" ' send only ENTER to Vinculum, response should be D:\> if USB stick is connected
Gosub Execute_command ' starting the program and with USB stick present will also display Vinculum boot info (Version xxx, Device Detected P2, No Upgrade or with firmware upgrade)
If Usb_stick_present = 1 Then
Print "USB stick connected"
Gosub Commands
Else
Print "USB stick not connected"
End If
Wait 5
Loop
Close #2
Close #1
End
Commands:
' the file todo.txt in the root directory of the USB stick configues this program
' generate this file with a text editor, e.g.:
' 6 Enter (number of samples)
' 1000 Enter (waiting time between samples in ms)
' 8 Enter (number of channels to measure in each sample)
' and save this file as todo.txt on the USB stick
' this program reads the 3 lines from the file todo.txt and stores the data in variables
' the measured data will be appended to the file log.txt, the file can later be loaded into Excel (open txt file with blank as delimiter)
' read file and store data in variables
Print #1 , "RD todo.txt" + Chr(13); ' only add CR, no CR LF!
Input #2 , Samples ' Vinculum sends CR LF, because file todo.txt contains CR LF; Input ends with CR; Get captures LF
Get #2 , I
Input #2 , Delayms
Get #2 , I
Input #2 , Channels
Get #2 , I
Input #2 , Vinc_str ' expect prompt
' no GET #2 I here!, Vinculum sends no LF after the prompt!
Print Vinc_str ; " (file was read) " ; Samples ; " " ; Delayms ; " " ; Channels
Decr Channels ' internal channel numbers of analog inputs are from 0 to 7 = 8 channels
' open the file log.txt
Print #1 , "OPW log.txt" + Chr(13);
Input #2 , Vinc_str ' expect prompt
Print Vinc_str ; " (file was opened)"
'write data to file
For N = 1 To Samples
S = ""
For I = 0 To Channels
Ad = Getadc(i)
S = S + Str(ad)
If I < Channels Then S = S + Chr(32) Else S = S + Chr(13) + Chr(10) ' add blanks for later import into Excel or CR LF for new line
Next I
S_length = Len(s)
Print "Sample " ; N ; ": " ; S ; S_length ' gets printed on 2 lines, as S contains CR LF
Print #1 , "WRF " + Str(s_length) + Chr(13) + S; ' there is no answer from Vinculum after sending the length of the data, so everything can be written on 1 line
Input #2 , Vinc_str ' expect prompt
Print Vinc_str ; " (data line was sent)"
Waitms Delayms
Next N
' close file
Print #1 , "CLF log.txt" + Chr(13);
Input #2 , Vinc_str ' expect prompt
Print Vinc_str ; " (file was closed)"
' diplay DIRECTORY on USB stick
Command_str = "DIR"
Gosub Execute_command
' diplay USB stick information
Command_str = "IDD"
Gosub Execute_command
' display firmware version of Vinculum
Command_str = "FWV"
Gosub Execute_command
' this is the direct terminal communication part
' only for simple commands like "dir", "idd", "fwv" or "fs", more complicated commands require a more complicated answer treatment (see above)
' set terminal program to local echo!
Do
Print
Input "Enter direct command to Vinculum (type exit for leaving) : " , Command_str
If Command_str = "exit" Then
Print
Print "exiting ..."
Exit Do
End If
Gosub Execute_command
Loop
Return
Execute_command:
' at high baud rates of Vinculum you cannot read a line from vinculum and then print it because of timing problems
' therefore first read all lines from Vinculum in a Do Loop into an array and then print to terminal or evaluate the answers
I = 0
Ending_loop = 0
Print #1 , Command_str + Chr(13); ' send with CR, but not with LF
Do
Incr I ' this works with 115200 baud to terminal and 115200 baud to Vinculum
Input #2 , Inp_str(i)
If Inp_str(i) = "D:\>" Then Set Ending_loop
If Inp_str(i) = "No Disk" Then Set Ending_loop
If Inp_str(i) = "Bad Command" Then Set Ending_loop
Loop Until Ending_loop = 1
Print
Reset Usb_stick_present
For I = 1 To Max_line_number
If Inp_str(i) <> "" Then
If Inp_str(i) = "D:\>" Then Set Usb_stick_present
' other code can be placed here, now is sufficient time for this
' If input_str() = ....
Print Inp_str(i)
End If
Inp_str(i) = "" ' erase string array for next use
Next I
Return |
|
|
|
|
|
|