About USB


Closed Thread
Results 1 to 7 of 7

Thread: About USB

  1. #1
    Join Date
    Sep 2009
    Posts
    8

    Default About USB

    Hi everyone.

    I have made some projects in the past, using Pic Basic Pro in order to collect data and transfer them computer using rs232 port.


    Id like to ask how we can connect a pic (eg 16f877A) in order to transfer data to pc using USB connection.

    I find than we need a usb controller like FT232RL ( http://www.ftdichip.com/Documents/Da.../DS_FT232R.pdf )

    Do you have any suggestions ?

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

  3. #3
    Join Date
    Sep 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Thanks rsocor01

    Thanks rsocor01

    Its really helpful..

  4. #4
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Pic usb

    I've just got the FTDI product VDrive2 working after a weeken of fiddling about updating the firmware and learning the disk/file commands.

    Works well - the data is recorded on a USB memory stick in a '.csv' file (commer separated variable) file that can be easily read into an Xl spreadsheet.

    Cost about $30. After the difficulty of packing data into EEPROM the almost unlimited storage is great.

    Regards Bill legge

    Code:
    ' -----[ Program Description ]---------------------------------------
    '
    ' Name: WVL Vdrive_03		File write test                                
    ' Program stores two 8-bit readings to USB thumb drive using a Vdrive2
    ' 
    ' Vdrive jumper in UART MODE (UART/SPI pulled up datasheet V.99 is correct)
    ' Pin        Name    Description
    ' 
    ' 1          GND     5V common
    ' 2          RTS     Request to Send
    ' 3          Vdd     Connects to +5V
    ' 4          RXD     Receive Data
    ' 5          TXD     Transmit Data
    ' 6          CTS     Clear to Send (connect to common or make low)
    ' 7          NC      No Connection
    ' 8          RI      Ring Indicator (not used)
    ' 
    ' PIC18F8722 on BIGPIC5
    ' DEBUG used for PC comms and SERIN/SEROUT for VDrive2 comms all at 9600 Baud
    '
    ' -----[ DEFINES ]---------------------------------------------------
    '
    clear
    DEFINE OSC 40						' Compile as HS
    
    DEFINE LCD_DREG	PORTD	    ' Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT	4		    ' Define first pin of data nibble
    DEFINE LCD_RSREG PORTD	    ' Define PIC port used for R/S line
    DEFINE LCD_RSBIT 2		    ' Define Portb pin used for R/S
    DEFINE LCD_EREG	PORTD   	' Define PIC prot used for E line
    DEFINE LCD_EBIT	3		    ' Define PortB pin used for E connection
    DEFINE LCD_BITS	4		    ' Define the 4 bit communication mode
    DEFINE LCD_LINES 4		    ' Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 1500	' Define delay time between sending commands
    DEFINE LCD_DATAUS 45	    ' Define delay time between data sent
    lcdout $fe,$1
    pause 2000
    FLAGS=0
    
    INCLUDE "modedefs.bas"				' Include serial modes
    
    DEFINE DEBUG_REG  PORTC
    DEFINE DEBUG_BIT  6
    DEFINE DEBUG_BAUD 9600				' VDrive2 default speed
    DEFINE DEBUG_MODE 0
    
    DEFINE DEBUGIN_REG  PORTC
    DEFINE DEBUGIN_BIT  7
    DEFINE DEBUGIN_BAUD 9600
    DEFINE DEBUGIN_MODE 0
    
    define	ADC_BITS 8
    '
    ' -----[ VARIABLES ]-----------------------------------------------------------
    '
    X			VAR	byte
    Y           var	byte
    Z			var	byte
    A			var	byte
    B			var	byte
    C			var	byte
    D			var	byte
    E			var	byte
    F			var	byte
    G			var	word
    DataIn		var	byte[50]
    Echo		var	byte
    Rx          VAR PORTC.0		' Data in from VDrive	[Yellow]   
    Tx          VAR PORTC.1 	' Data out to VDrive	[Orange]
    Heartbeat	var	PORTD.0 
    
    Number		VAR	BYTE[10]
    '
    ' -----[ INITIALISE ]----------------------------------------------------------
    '
    ADCON1 	= %00001111			' All digital
    TRISA	= %00000011			' A0 and A1 inputs
    TRISB	= %00000000
    TRISC	= %00000001			' C0 is data in, C1 is data out
    TRISD	= %00000000
    TRISE	= %00000000
    TRISF	= %00000000
    TRISG	= %00000000
    TRISH	= %00000000
    TRISJ	= %00000000
    '
    ' -----[ IDENTIFY ]------------------------------------------------------------
    '
    	lcdout $fe,$80, "WVL Vdrive_03"
    	lcdout $fe,$c0, "PIC18F8722"
    	pause 3000
    	lcdout $fe,1
    
    ' *****************************************************************************
    ' *                                                                           *
    ' *                         ESTABLISH COMMS WITH VDRIVE                       *
    ' *                                                                           *
    ' *****************************************************************************
    
    Begin:
    	Debug "VDrive2 Starting",13   
    	Pause 200
    	Debug "Attempting synchronisation:"
         
    Syncro:
    	Pause 200 
    	toggle Heartbeat
    	X=X+1
    	debug " ",dec3 X
    	SerOut2 TX,84,["E",13]    			' Send sync command folowed by CR               
        SerIn2 RX,84,200,Toolong,[Echo]		' Wait 200mS for reply 'E'
    	if Echo = "E" then Comms_Good
        
    Toolong:       
    	GoTo Syncro
        
    Comms_Good:
    	Debug 13,"Disk synchronised",10,13	   	' Show SUD has been sent
    	pause 500
    
    ' *****************************************************************************
    ' *                                                                           *
    ' *                             M A I N  C O D E                              *
    ' *                                                                           *
    ' *****************************************************************************
    
    	gosub Check_disk
    	gosub Get_version
    	gosub File_list
    	gosub File_name_size						' File size & name before FOR...NEXT loop
    	gosub Free_space
    	gosub File_delete
    	pause 100
    	gosub File_open								' Create the file   "TestFile.csv" (XL type)
    												' When read becomes "TESTFILE.CSV"	
    	for X=1 to 17
    		toggle Heartbeat		
    		debug "Writing to file X: ",dec3 X,13		
    		SerOut2 TX,84,["WRF ",0,0,0,4,13]		' 32 bit number of bytes
    		serout2 Tx,84,[dec3 x,10,13]			' Number of bytes must be exact
    	next X										' Additional CR puts XL numbers into a column
    	
    	gosub File_close
    	
    	gosub File_size								' File size after FOR...NEXT loop	
    
    												' Read the file size and send first byte to LCD			
    	serout2 Tx,84,["IPA",13]					' Switch to ASCII characters for display of HEX digits
    	pause 100									' Essential to wait after o/p switch
    	serout2 Tx,84,["DIR TestFile.csv",13]		' Issue the command
    	serin2  Rx,84,[Wait ("TESTFILE.CSV $"),_
    		hex2 A,skip 2,hex2 B,skip 2,hex2 C,skip 2,hex2 D]
    	lcdout $fe,$80, "$: ",hex2 A," ",HEX2 B," ",HEX2 C," ",HEX2 D
    	pause 100
    			
    	debug "All done",10,13	
    	end
    	
    ' *****************************************************************************
    ' *                                                                           *
    ' *                         S U B R O U T I N E S                             *
    ' *                                                                           *
    ' *****************************************************************************	
    
    Check_disk:
    	for X=0 to 49 : DataIn[X]=0 : NEXT X		' Clear the array
    	serout2 tx,84,[13]							' Issue the command. "D"= Disk Ok, "N"=no disk
    	serin2  Rx,84,[str DataIn\1]				' Read  1 character												
    	If DataIn[0] = "N" then 
    		debug "No disk detected "
    		pause 500
    		goto Check_disk
    		else
    		debug "Disk found OK",10,13
    	endif
    	pause 100									' These pauses are essential
    	return
    
    Get_version:
    	debug "Firmware version:"
    	for X=0 to 49 : DataIn[X]=0 : NEXT X		' Clear the array
    	serout2 tx,84,["FWV",13]					' Issue the command
    	serin2  Rx,84,[str DataIn\50\">"]			' Read characters until ">" is found												
    	debug str DataIn\50							' Send data to the PC
    	pause 100									' These pauses are essential
    	return
    	
    File_list:
    	debug 13,10,10,"List all files:"
    	for X=0 to 49 : DataIn[X]=0 : NEXT X		' Clear the array
    	serout2 Tx,84,["DIR",13]					' Issue the command
    	serin2  Rx,84,[str DataIn\50\">"]			' Read up to max of 50 chrs
    	debug str DataIn\50
    	pause 100
    	return
    	
    File_name_size:
    	debug 13,10,10,"File name & size:"
    	serout2 Tx,84,["IPA",13]					' Switch to ASCII characters for display of HEX digits
    	pause 10									' Essential to wait after o/p switch
    	for X=0 to 49 : DataIn[X]=0 : NEXT X		' Clear the array
    	serout2 Tx,84,["DIR TestFile.csv",13]		' Issue the command
    	serin2  Rx,84,2000,Jump2,[str DataIn\50\">"]' Read up to max of 50 chrs
    Jump2:											' Needed in case there is no file on the drive		
    	debug str DataIn\50	
    	pause 100
    	return
    	
    File_size:
    	debug 13,10,10,"File size:",13
    	serout2 Tx,84,["IPA",13]					' Switch to ASCII characters for display of HEX digits
    	pause 10									' Essential to wait after o/p switch
    	for X=0 to 49 : DataIn[X]=0 : NEXT X		' Clear the array
    	serout2 Tx,84,["DIR TestFile.csv",13]		' Issue the command
    	serin2  Rx,84,2000,Jump3,[Wait ("TESTFILE.CSV "), str DataIn\50\">"]
    												' Read up to max of 50 chrs
    Jump3:											' Needed in case there is no file on the drive		
    	debug str DataIn\50,10,13	
    	serout2 Tx,84,["IPH",13]					' Switch to HEX characters
    	pause 100
    	return	
    	
    		
    Free_space
    	debug 13,10,10,"Free space:",13
    	serout2 Tx,84,["IPA",13]					' Switch to ASCII characters for display of HEX digits
    	pause 10									' Essential to wait after o/p switch
    	for X=0 to 49 : DataIn[X]=0 : NEXT X		' Clear the array
    	serout2 Tx,84,["FS",13]						' Return 4 bytes
    	serin2  Rx,84,[str DataIn\50\">"]			' Read up to max of 50 chrs		
    	debug str DataIn\50	
    	serout2 Tx,84,["IPH",13]					' Switch to HEX characters
    	pause 100
    	return	
    			
    File_open:
    	debug "Opening file",10,13
    	serout2 Tx,84,["OPW TestFile.csv",13]		' Issue the command
    	return
    
    File_close:
    	debug 10,"Closing file",10,13
    	SerOut2 TX,84,["CLF TestFile.csv",13]		' Issue the command
    	return
    	
    File_delete:
    	debug 13,10,10,"Deleting file",10,13	
    	serout2 tx,84,["DLF TestFile.csv",13]		' Issue the command
    	return

  5. #5
    Join Date
    Sep 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default FTDI product VDrive2

    Dear Bill


    Can you pass a link about FTDI product VDrive2. I cant find it.

    Chris

  6. #6
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Usb pic

    The FTDI site whilst visually neat is a logical mess and the Vdreive2 product is hiding under the 'Web Shop' button:

    http://apple.clickandbuild.com/cnb/s...ts+and+Modules

    The web shop uses the name 'Vinculum' but there is no explanation if this is the name of the shop, product group or whatever. It's amazing that a company with a good range of products and obviously of considerable technical expertise has names and parts probably designated by the mad hatter on one of his 'off' days.

    If this link does not work the way to find it is:

    1. FTDI site.
    2. Select Web Shop.
    3. Select 'modules'
    4. And there you are, I hope.

    When you get the module it will probably have outdated firmware loaded into it. My advice on dealing with this is:

    1. Don't update it initially.
    2. Write a test program to open files, write to the file, close, get file size and so on. All easy using RS232 at 9600 Baude without CTS/RTS control.
    3. After gaining confidence that the thing works, have a go at updating the firmware. I spent a whole day trying to do it by the 'memory stick method' and failed. I then had a go at update by using the RS232 link - and it worked fine.

    Updating by using RS232 needs the CTS/RTS lines to be used. There is a good circuit diagram and details on how to do it in the 'Firmware' support document. Don't bother asking questions from the tech support link - one does get a reply but, it's not of much value.

    If you go along this path and run into difficulties - let me know. i've just got a 2 Gigabyte stick and all works OK. It's odd writing data logging routines where there is no restriction on record lengths or the frequency of sampling!

    Regards Bill Legge

  7. #7
    Join Date
    Sep 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Dear Bill

    Thanks for your reply and your comments. Ill let you know about my progess.


    Thanks again
    Chris

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. USB Bootloader.
    By HenrikOlsson in forum USB
    Replies: 22
    Last Post: - 2nd May 2013, 02:46
  3. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  4. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 00:04
  5. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts