Finally I'm getting the Send vpw subroutine to work.
I wrote a separate source to act as vpw sender, to send bytes to the previous vpw receiver. I get messed adjusting the timings for the sending routine as the loop itself added some uC cycle time making the output pulses wider, but now it is working ok.
So far this is the subs code in Bascom:
Dim Snd_str As String * 30
Snd_str = "6A7C3B35FF"
Gosub J1850_send
Wait 1
End
Sub J1850_send
Gosub Preparebytestosend
For I = 1 To Nbytes
If I = 1 Then
Gosub Send_sof
End If
Tmpbyte = Txarray(i)
Gosub Tx_data
Next I
Gosub Send_eof
End Sub
'Fill The Array with the Bytes to shorten waste time..
Sub Preparebytestosend
Snd_qty = Len(snd_str) : Snd_qty = Snd_qty / 2 'Every Byte is represented by 2 characters
If Snd_qty > 12 Then
Print "Error: more than 12 bytes!"
Waitms 500
Exit Sub
End If
Print "Bytes Qty: " ; Snd_qty
Nbytes = Snd_qty
Print ""
Print "Sending: ";
Str_index = 1
For I = 1 To Snd_qty
Sbyte = Mid(snd_str , Str_index , 2)
Tmpbyte = Hexval(sbyte)
' Tmps = Bin(tmpbyte)
Print "$" ; Hex(tmpbyte) ; " " ;
Txarray(i) = Tmpbyte
'Gosub Tx_data
Str_index = Str_index + 2
Next I
'Gosub Send_eof
End Sub
Sub Tx_data
For J = 7 To 0 Step -1
If Tmpbyte.j = 1 Then
If Last = 1 Then
Gosub 1_low
Else
Gosub 1_high
End If
Else
If Last = 1 Then
Gosub 0_low
Else
Gosub 0_high
End If
End If
Next J
End Sub
Project advance at:
http://www.diyprojects.zobyhost.com/