VDrive2 Sample Code

BCJKiwi

Senior Member
#1
This is a rework of Technical's VMusic2 file from the old forum specifically for the VDrive2

Neither the DIRT or FS / FSE commands work properly. The firmware version I am working with is 03.54. Upgrade to 03.58 is not working at present (loops on initialisation and does not upgrade - in discussion with FTDI).

Note that to get a response with file commands testing for CR does not work as CR is returned in many places (eg in the DIR command, a CR is returned before any data) so the test needs to be for the DOS Prompt which comes at the end of most commands of this type. Hence the get_fileresponse subroutine which tests for the last char which is the > of the D:\> type Dos Prompt

Code:
; Interfacing a VDrive2 module to PICAXE-28X1
; Hardware Setup
; VDrive2        -  PICAXE-28X1
; 1 Black GND    -  0V               Leg 8,19
; 2 Brown RTS    -  CTS input4 C4    Leg 15 (not used)
; 3 Red V+       -  V+               Leg 20
; 4 Orange RXD   -  HTXD input6 C6   Leg 17  
; 5 Yellow TXD   -  HRXD input7 C7   Leg 18
; 6 Green CTS    -  RTS output0 B0   Leg 21 (not essential, can tie to 0V)
; 7
; 8 Blue RI      -  not connected
; Note RXD on VDrive2 connects to TXD on PICAXE etc.
 
; Tested with an Imation nano 1GB USB stick.
symbol first_byte = b0
symbol point = b1
symbol temp = b2
symbol loopcounter = b3
 
; set picaxe type
#picaxe 28x1
setfreq m8
 
; set COM port used for download
;#com 1
; open terminal after download
; This is to view the 'sertxd' debugging comments
#terminal 9600
 
setup:
; setup serial hardware 
; at 9600 with background receive
hsersetup b9600_8,%01
low 0 ; ensure CTS is low
 
init:
; Send Es until the unit responds correctly
sertxd ("<Sent> E",CR,LF)
hserout 0,("E",CR)
gosub get_response
if first_byte <> "E" then init
 
main:
; check to see if a drive is actually inserted
; response will start D for yes and N for no
sertxd ("<Sent> Check Drive",CR,LF)
hserout 0,(CR)
gosub get_response
if first_byte <> "D" then main 
 
;now interact with disk
Disk:
'Get firmware version 
sertxd ("<Sent> FWV",CR,LF)
hserout 0,("FWV",CR)
gosub get_fileresponse
 
'Get Directory information
sertxd ("<Sent> DIR",CR,LF)
hserout 0,("DIR",CR)
gosub get_fileresponse
 
'Get log file stamps 
sertxd ("<Sent> DIRT Log.txt",CR,LF)
hserout 0,("DIRT Log.txt",CR)
gosub get_fileresponse
 
'Get Directory listing 
sertxd ("<Sent> FSE <freespace>",CR,LF)
hserout 0,("FSE",CR)
gosub get_fileresponse
pause 2000
 
; create a log file called 'log.txt'
; if you send 11 chars as the file name the last three will become the extension
; the '.' is inserted automatically 
; Filename cannot include spaces
sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw Log.txt",CR)
gosub get_response
sertxd ("<Sent> write to file",CR,LF)
bintoascii loopcounter,b5,b6,b7 ; convert loopcounter byte to 3 ascii digits
      ; and write 8 bytes loop_xyz
 
hserout 0,("wrf ",$00,$00,$00,$08,CR,"loop_",b5,b6,b7,CR)
gosub get_response
sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf Log.txt",CR)
gosub get_response
inc loopcounter ; increment counter
goto Disk
 
; Sub procedure to receive background bytes
get_response:
   pause 2000 ; wait a while 
   sertxd ("<Response> ")
   point = 0 ; reset local pointer
   get point,first_byte ; Save the first reply byte
do
   get point,temp ; get returned byte
   sertxd (temp) ; transmit it
   inc point ; increment pointer
loop while temp <> CR ; if not CR loop
   sertxd (LF) ; Add a LF to the received CR
   sertxd (CR,LF) ; Do another blank line
   hserptr = 0 ; reset the background receive pointer 
return
 
get_fileresponse:
   pause 2000 ; wait a while 
   sertxd ("<Response> ")  
   point = 0 ; reset local pointer
   get point,first_byte ; Save the first reply byte
do
   get point,temp ; get returned byte
   sertxd (temp) ; transmit it
   inc point ; increment pointer
loop while temp <> ">" ; if not CR loop
   sertxd (LF) ; Add a LF to the received CR
   sertxd (CR,LF) ; Do another blank line
   hserptr = 0 ; reset the background receive pointer 
   pause 2000
return
 
; Other Useful Commands
; Pause hserout 0,("e") ; note no CR here
; Resume (after pause) hserout 0,(CR)
; Suspend disk hserout 0,("sud",CR)
; Wakeup disk hserout 0,("wkd",CR)
; Get firmware version hserout 0,("fwv",CR)
 
Last edited:
Top