Vdrive3 so many "E"

johnlong

Senior Member
Hi Hippy
Have rejigged it after your comments split the response into 3 segments
and addressed them as per the sample code in circuit creator so I belive that
the return bytes are those from the vdrive
Did'nt realise that I was just reading back the scratchpad go giddy with the result in excel
of the stick
Here is a screen shot of excel from the stick without serial download cable attached straight from chip to stick
vdrive4.jpg
and here is the reworking of the code
Code:
#picaxe 28x2
#no_data
#no_table

symbol temp =b6
symbol S_B = b7

symbol WD=b12
symbol point =b8



b5 = "," 

wd=0
b1=0

setfreq em32 

ptr=200
b1=0
ABC:
	ptr=200
	b1=0 
	do
 	 inc b1
  	bintoascii b1,b2,b3,b4 ; convert b1 to ascii  
  	  @ptr=b1   'dummy adc scratchpad block 200 - 344
 	ptr=ptr+1
  	@ptr=b5     'puts "," comma to seperate the data for excel to read
	ptr=ptr+1
 	if ptr = 344 then:goto BCA:endif
		
	 loop
BCA:
	ptr =360
	b10=10
	 do
	 inc b10
	bintoascii b10,b2,b3,b4 ; convert b10 to ascii
	 @ptr=b10   ' dummy adc scratchpad block 360 - 504
  	ptr=ptr+1
	@ptr=b5
	ptr=ptr+1
		
 	if ptr= 504 then:ptr=0:wd=0:goto init_vdrive3:endif 'Trigger for data write
	
	loop	
	

init_vdrive3:
	
	hsersetup B9600_32, %1 
	pause 3000		'send Es until Vdrive3 responds correctly
  	hserout 0,("E",CR) 
 	pause 300
	sertxd ("E requested ")
 	
 	gosub response
		  
 	if S_B <> "E" then init_vdrive3     
	   
	sertxd ("bytes returned",#s_b)   
	pause 300
	hserout 0,("OPW DAT.CSV",CR)	 	 
	pause 300
	gosub response
	sertxd ("<Sent> Open file",CR,LF)
	wd=1
	goto main
main:
	
	if wd =1 then:ptr =200:goto daat ' Trigger PTR pointer manipulation 1st block 
	
	elseif wd =2 then: ptr= 360:goto daat:endif  ' trigger for 2nd scratchpad block    
	
	gosub shutdown  'stop write sequance 
	gosub Clr1
	pause 300
 	gosub Clr2
 	pause 300
 	sertxd ("SAFE TO REMOVE")
	end
 daat:	


	
	hserout 0,("wrf ",$00,$00,$00,$14,CR) 
	hserout 0,("Col1,Col2,Col3,Col4",CR)
	
	pause 300
	hserout 0,("wrf ",0,0,0,236,CR)
	pause 300
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'1
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'2
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'3
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'4
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'5
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'6
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'7
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'8
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'9
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'10
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'11
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'12
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'13
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'14
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'15
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'16
	
 	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'17
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'18
	
	hserout 0,($00,$00,$00,$00,$00,$00,$0a,$0d,cr)'19 Added this to form a break between data
	
			
		
	hserout 0,($00,$00,$0D,$0A,CR)' To tell drive data write ended
	 sertxd ("<sent> write",cr,lf)
	 gosub response1 
	 pause 500
	 
	inc wd  ' used for addressing ptr
	
	goto main
	
	 
 response:   
 
 	sertxd ("<Response> ")
	  point=0
	 
	 
	get point, s_b
		
	hserptr = 0
	
	 return 
	 
response1:
	point =0	' Data transfer to USB
	do
	get point,temp	
 	inc point	
	loop until temp <> CR
		
	hserptr = 0
	
	 return 
 	
Clr1:     'Reset 1st scratchpad data block
 	
 	ptr = 200 		
         do
	@ptr=0
	ptr=ptr+1
	if ptr =345 then:exit:endif
         loop 
         
         return
         
Clr2:     'Reset 2nd block   
	ptr = 360
	 do
	@ptr=0
	ptr=ptr+1
	if ptr =505 then:exit:endif
         loop 
         
         
         return
         
shutdown:  ' file close

	hserout 0,("CLF DAT.CSV",CR) 
	
	pause 300
	
	hserptr=0
	return
have simplified the main: so as not to chase variable wd about, and moved it so that it is just addressing the location of PTR so I believe that what I get back is now from the vdrive
thanks for the feed back
regards
john
 

hippy

Technical Support
Staff member
So does it work now ?

It's all too confusing for me to figure out. In some places you are using one set of magic numbers which are different to those used in other places (344 versus 345, 504 versus 505), you have coding structures which aren't exactly obvious at first glance, you seem to be clearing data which is only going to get written over later which only adds to the clutter.

Poking bytes of data plus commas into scratchpad, then a wall of HSEROUT to output that is hard to analyse, and I don't even know if the two match. If you have to indicate how many bytes are going to be written I don't see how you can know that when you are using #'s in the HSEROUT which will generate varying number of bytes.

You are still writing CR to the fiel when that should be CR, LF and I have no idea what all those NULL ($00) characters being emitted to the file are for but they could easily confuse Excel.

That 'wd' flag handling is hard to figure out; it would be much better done with subroutines.

There doesn't even seem to be a check for a response in the 'response:' routine now.

I think you need to get some better structure to the code, and probably need to define exactly what data you want to have in the blocks in scratchpad which you will then be writing to the file, need to start with something simpler to start with as previously suggested.

Get writing directly to the file working first. Then expand that to writing the data you want to write.
 

hippy

Technical Support
Staff member
I would start with the following which fills two block of Scratchpad with 16-bit / 4-digit decimal 'brrc' values, where 'b' is block number (1 or 2), 'rr' is row number (1-99) and 'c' is column number (1-9), and dumps what should be in a resultant file via the terminal.

Code:
#Picaxe 28X2
#Terminal 9600

Symbol reserveW0 = w0 ; b1:b0
Symbol reserveW1 = w1 ; b3:b2
Symbol w1.lsb    = b2
Symbol w1.msb    = b3
Symbol row       = b4
Symbol col       = b5

Symbol ROWS      = 18
Symbol COLS      = 4
Symbol ENTRIES   = ROWS * COLS
Symbol BYTES     = ENTRIES * 2

Symbol BLOCK1    = 200
Symbol BLOCK2    = BLOCK1 + BYTES 

Main:
  Pause 2000
  Gosub ReportBlockInfo
  Gosub FillBlock1
  Gosub FillBlock2
  SerTxd( "Contents of file ...", CR, LF )
  Gosub DumpHeader
  Gosub DumpBlock1
  Gosub DumpBlock2
  SerTxd( "End of file", CR, LF )
  End

ReportBlockInfo:
  w0 = BLOCK1 : w1 = BLOCK1 + BYTES - 1
  SerTxd( "Block 1 at ", #w0, " to ", #w1, CR, LF )
  w0 = BLOCK2 : w1 = BLOCK2 + BYTES - 1
  SerTxd( "Block 2 at ", #w0, " to ", #w1, CR, LF )
  If w1 >= 1024 Then
    SerTxd( "Blocks are too big", CR, LF )
    End
  End If
  Return

FillBlock1:
  ptr = BLOCK1 : w0 = 1000 : Goto FillBlock

FillBlock2:
  ptr = BLOCK2 : w0 = 2000 : Goto FillBlock

FillBlock:
  For row = 1 To ROWS
    For col = 1 To COLS
      w1 = row * 10 + col + w0
      @ptrInc = w1.lsb
      @ptrInc = w1.msb
    Next
  Next
  Return

DumpHeader:
  For col = 1 To COLS
    If col < COLS Then
      SerTxd( "Col", #col, "," )
    Else
      SerTxd( "Col", #col, CR, LF )
    End If
  Next
  Return

DumpBlock1:
  ptr = BLOCK1 : Goto DumpBlock

DumpBlock2:
  ptr = BLOCK2 : Goto DumpBlock

DumpBlock:
  For row = 1 To ROWS
    For col = 1 To COLS
      w1.lsb = @ptrInc
      w1.msb = @ptrInc
      If col < COLS Then
        SerTxd( #w1, "," )
      Else
        SerTxd( #w1, CR, LF )
      End If
    Next
  Next
  Return
 

johnlong

Senior Member
Hi All
After A lot more reading and thinking about the concerns expressed by you all I have come
up with the following I have restructed the code to simplify it and added more explinations in it
I have removed the external ressinator and have had continious sucessful writes to an 8Mb,8Gb and 32Gb usb sticks

Code:
'PROGRAM TO CREATE A ONCE A DAILY SCRATCHPAD DATA DUMP FILE ONTO THE VDRIVE3
'28X2             VDRIVE3
' C.7(hserin)<---->yellow TXD
' C.6(hserout)<--->orange RXD
'                 green CTS to ground
'                 red +v
'                 black to ground
'USB TESTED OK Maxell 8Mb formated FAT 32 (via vista) sector size 512
' Scandisk Cruzer Blade 8Gb formatted FAT 32 sector size 2048
'Scandisk Cruzer Blade 32Gb formatted FAT 32 sector size 8192
'The formate has being chosen so that the addition of extra or removale of ADC in future can be
'achived with the minimal code rewriting
'********************** SECTION ONE *******************************************
'THIS SECTION IS ONLY HERE TO CREATE DUMMY ADC VALUES IN SCRATCHPAD FOR TESTING
 #picaxe 28x2
#no_data
#no_table

symbol temp =b6 
symbol S_B = b7
symbol F_B= b8
symbol T_B= b9

symbol WD=b12
symbol point =b11
symbol HF=b14
symbol wrtb=b15

b5 = "," 

	setfreq m8
	 
	


ABC: 
	ptr=200
	b1=0 
	do
 	 inc b1
  	bintoascii b1,b2,b3,b4 ; convert b1 to ascii  
  	  @ptr=b1   'dummy adc scratchpad block 200 - 344
 	ptr=ptr+1
  	@ptr=b5     'puts "," comma to seperate the data for excel to read
	ptr=ptr+1
 	if ptr = 344 then:goto BCA:endif
		
 	 loop 
BCA:
	ptr =360
	b10=10
	 do
	 inc b10
	bintoascii b10,b2,b3,b4 ; convert b10 to ascii
	 @ptr=b10   ' dummy adc scratchpad block 360 - 504
  	ptr=ptr+1
	@ptr=b5
	ptr=ptr+1
		
 	if ptr= 504 then:ptr=0:wd=0:exit:endif 'Trigger for data write
	
	loop
	
'************************* SECTION TWO ************************************	
' LINES FOLLOWED BY ** ARE ONLY FOR TEST PURPOSES AND WILL BE REMOVED FOR FINISHED PRODJECT	
	hsersetup B9600_8, %1 'set to recieve background data
	pause 3000	
	

init_vdrive3:
	
			'send Es until Vdrive3 responds correctly
  	hserout 0,("E",CR) 
 	pause 300 	
	sertxd ("E requested ")'** 	
 	gosub response
 	sertxd ("inti returned",#f_b)'**
 	'debug
 	pause 3000		  
 	if F_B <> "E" then init_vdrive3
 	inc hserptr
 smalle:
 	hserout 0,("e",CR) 
 	pause 300 	
	sertxd ("e requested ")'** 	
 	gosub response
 	sertxd ("small returned",#s_b)'**
 	'debug
 	pause 3000		  
 	if F_B <> "e" then smalle
 	inc hserptr
 check:
 	 hserout 0,(CR)
 	 pause 300
 	 gosub response
 	 'debug 	 
 	 sertxd ("check byte",#F_B)'**
 	 pause 3000
 	 if F_B <> "D" then check
 	 pause 300
 	     
	 bintoascii b19,b20,b21,b22  
	
	
main:
	
	if wd<=3 then
	on wd gosub HF0,HF1,HF2,HF3
	goto main
	elseif wd =4 then: gosub Clr1
	endif	
	pause 300
 	gosub Clr2
 	pause 300
 	'RUN,0  the return back to slot 0 after data dump in finished prodject
 	if b24=2 then:sertxd ("safe to remove"): end'**
 	elseif b24<2 then:inc b19:goto ABC'**
 	endif
 	
 	
 HF0:	
 
 	hserout 0,("OPW DAT.CSV",CR)'Header for block 1 results from ADC1 in slot0	 	 
	pause 300                   'To be altered in finished for collum headers and date stamp
	gosub response
	pause 300
	sertxd ("<Sent> Open file",CR,LF)'**
	
	hserout 0,("WRF ",0,0,0,40,CR)'Tells vdrive numder of bytes to write
	pause 300
	hserout 0,("loop",b20,b21,b22,",",CR)'8bytes
	pause 300
	hserout 0, (F_B,",",S_B,",",T_B,",",F_B,",",CR)'8bytes the vdrive responses for test purposes only
	 pause 300
	hserout 0,("Col1,Col2,Col3,Col4",CR)'20 bytes	
	pause 300
	hserout 0,(0,0,13,10,CR)'4bytes write end
	gosub response1
	sertxd ("<sent> Header1")'**
	WD=1
	 return
 HF1:      
 	ptr =200 'Data location for ADC1 obtained from slot0
 	wrtb=228  'Tells vdrive number of bytes to write for the First block
 	gosub block'it was nessecery to alter wrtb to accomadate the diffrent block sizes
 	WD =2       'due to block 1 having single didgit values in it
 	sertxd ("<sent> write1",cr,lf)'**
 	gosub shutdown	
	return
HF2:

	hserout 0,("OPW DAT.CSV",CR)	 	 
	pause 300
	gosub response
	pause 300
	sertxd ("<Sent> Open file",CR,LF)'**
	
	hserout 0,("WRF ",0,0,0,40,CR)
	pause 300	
	hserout 0,("loop",b20,b21,b22,",",CR)
	pause 300
	hserout 0, (F_B,",",S_B,",",T_B,",",F_B,",",CR)'shows the responses from the vdrive
	 pause 300                                     'displays in xl the following D,:,\,D the command returns
	hserout 0,("Col1,Col2,Col3,Col4",CR)	
	pause 300
	hserout 0,(0,0,13,10,CR)
	gosub response1
	sertxd ("<sent> Header2")'**
	WD=3
	 return
HF3:
	ptr =360 'Data location for block 2
	wrtb=236  ' see above
	gosub block	
 	WD=4
 	sertxd ("<sent> write2",cr,lf)'** 	
 	gosub shutdown
 		
	return	
	'SEE JMANSONS excelent explination of how vdrive likes to get its byte
	'In Vdrive so many E's POSTS #21 and #25
Block:	
	hserout 0,("wrf ",0,0,0,wrtb,CR)  'tells vdrive number of bytes to send
	pause 300
	'without the # in for some reason xl produces only displays charictors you may have more
	'knowloge of its workings than me and are able to remove them
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'1
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'2
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'3
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'4
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'5
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'6
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'7
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'8
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'9
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'10
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'11
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'12
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'13
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'14
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'15
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'16
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'17
	
	hserout 0,(#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,#@ptrinc,@ptrinc,cr)'18			
		
	hserout 0,(0,0,13,10,CR)' To tell drive data write ended
	 
	 gosub response1 
	 pause 500
	return 
 response:  'conection to vdrive 
 
 	sertxd ("<Response> ")'**
 	get 0,F_B 	
	get 1, S_B 	 
	get 2, T_B	
	'pushes bytes up until the if statement is met
	pause 300
	if f_b = "D" and s_b = ":" and t_b = 92 then: gosub ok'used 92 as editor would not pass "\"
	else gosub fail
	endif
	hserptr = 0
	
	 return 
	 
response1:
	point =0	' Data transfer to USB
	do
	get point,temp	
 	inc point	
	loop until temp <> CR 
		
	hserptr = 0
	
	 return 
 	
Clr1:     'Reset 1st scratchpad data block to zeros as its easier to see zeros if there is an error later
 	'than trying to determine if a value is correct or an error when looked at in xl from over writing
 	ptr = 200 		
         do
	@ptr=0
	ptr=ptr+1
	if ptr =345 then:exit:endif'1 extra just incase
         loop 
         
         return
         
Clr2:     'Reset 2nd block   
	ptr = 360
	 do
	@ptr=0
	ptr=ptr+1
	if ptr =505 then:exit:endif'1 extra just in case
         loop 
          
          inc b24       
         sertxd ("B24=",#b24,"**")
         
         return
         
shutdown:  ' file close

	hserout 0,("CLF DAT.CSV",CR)	
	pause 300	
	hserptr=0	
	return
	
Ok:
	
	sertxd ("Drive open")
return

fail:
	
	sertxd ("Drive fail")
return
The following is an XL screen shot of the write to the 8Gb stick the 2nd image is what is obtained if I remove the # from
@#ptrinc I do not know why it will take somebody with more brains than me to fathom it out
xlscreenshot.jpg
I would like to thank all the contributers for there comments without which I was going of course
regards
john
 

Attachments

Top