reuben38121
New Member
How do you do this? Any suggestions/code snippets. I am using the code and setup which BCJKiwi has designed, but I cannot work out how to read from the VDrive. Any help would be appreciated
; 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
symbol adcvalue = b8
; 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 4800
setup:
; setup serial hardware
; at 9600 with background receive
hsersetup b9600_4,%01
low 0 ; ensure CTS is low
pause 2000
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
high 2
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
; 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
for loopcounter = 1 to 100
gosub openfile1:
readadc 0,adcvalue
sertxd (#adcvalue," ",#loopcounter,CR,LF)
bintoascii adcvalue,b5,b6,b7 ; convert loopcounter byte to 3 ascii digits
; and write 8 bytes loop_xyz
hserout 0,("wrf ",$00,$00,$00,$04,CR,b5,b6,b7,";",CR)
pause 200
'sertxd (#loopcounter," loopcounter",CR,LF)
'next
gosub closefile1
'high 1 ' turns on led to indicate finish
'b9,b10,b11,";"
'stop
pause 200
gosub openfile2
bintoascii loopcounter,b9,b10,b11
hserout 0,("wrf ",$00,$00,$00,$04,CR,b9,b10,b11,";",CR)
'pause 100
'sertxd (#loopcounter," loopcounter",CR,LF)
gosub closefile2
pause 200
next
high 1 ' turns on led to indicate finish
low 2 'b9,b10,b11,";"
stop
; Sub procedure to receive background bytes
get_response:
pause 1000 ; wait a while
'sertxd ("<Response> ")
point = 0 ; reset local pointer
get point,first_byte ; Save the first reply byte
' sertxd (#point," ",#first_byte,13,10)
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
openfile1:
'sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw Log.txt",CR)
gosub get_response
'sertxd ("<Sent> write to file",CR,LF)
return
closefile1:
'sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf Log.txt",CR)
return
openfile2:
'sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw Num.txt",CR)
gosub get_response
'sertxd ("<Sent> write to file",CR,LF)
return
closefile2:
'sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf Num.txt",CR)
return
get_fileresponse:
pause 1000 ; 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 1000
return