Now thankyou all for your feedback, I still don't know exactly how to use hserin yet, but I will most certainly use it later. However I was able to come up with a way of getting my method to work.
Now the biggest problem is that using the internal clocks on both the master and the slave makes errors pop up, but I came up with a way to check for errors and continue to retransmit, or request data until it is error free. And I came up with the solution to the original problem which was that I just needed to use STR message\12. What I was doing in the original code was converting multiple bytes into single bytes, and then attempting to transfer them in that form, which changed the data format causing it to be unreadable by the driver.
the simplest method to solve that problem is:
message VAR byte[12]
serin2 pcinpin, 16468, [STR message\12]
and then
serout2 picoutpin, 16468, [STR message\12]
the problem with the above code is the fact that during the process of recieving and transmitting twice its almost guarenteed you will get bad data at some point.
my solution :master code:
Code:
define OSC 8
OSCCON = %1111110 ' sets internal osc to run at 8MHZ
'----------turn analog on porta off, and use as digital input/output
'----------this is used to allow serial input on the A bus.
CMCON = 7 'Comparators OFF
ANSEL = 0 'A/D OFF -- Port pins all digital
'----------
'---**Pins
rsoutpin var porta.0
rsinpin var porta.1
picinpin var portb.4
picoutpin var portb.5
porta=0
portb=0
'---vars
'-------- transfer vars
'servonum var byte: rate var word:position var word:donecommanding var byte
'--------
message var byte[12]
message2 var byte[12]
'---main program
goto pcin
'----- retrieve next set of commands from pc.
pcin:
'----send serial request
serout2 rsoutpin, 16468, ["waiting!"] 'call for data
'----
serin2 rsinpin, 16468, [str message\12,str message2\12]
'compare both arrays
if message[0]=message2[0] and message[1]=message2[1] and _
message[2]=message2[2] and message[3]=message2[3] and _
message[4]=message2[4] and message[5]=message2[5] and _
message[6]=message2[6] and message[7]=message2[7] and _
message[8]=message2[8] and message[9]=message2[9] and _
message[10]=message2[10] and message[11]=message2[11] then
'arrays equal eachother then
serout2 rsoutpin, 16468, [str message\12]
goto picout
endif
serout2 rsoutpin, 16468, ["bad data!"]
goto pcin
'---- picout procedure waits for high on picinpin and then transmits data
picout:
input picinpin
while picinpin = 0
pause 1
wend
serout2 picoutpin, 16468, [str message\12,str message\12]
pause 6
if picinpin = 1 then 'checks if data was recieved
goto picout 're-send until recieved
endif
serout2 rsoutpin, 16468, ["|transmission succesful|"] 'tell computer
goto pcin
end
Here is the code for the slaves recieve portion:
Code:
recieve:
'----send high pic request, and get user input for motor drive
high picoutpin
'----
'--by using skip 1 rather then wait ("|") losing data is
'--prevented when wait is used if the data goes through
'--wrong the command is lost altogether.
serin2 picinpin, 16468,15,drivemotor, [dec2 servonum,skip 1,_
dec3 rate,skip 1,dec3 position,skip 1,donecommanding,_
dec2 servonum2,skip 1,dec3 rate2,skip 1,dec3 position2,skip 1,_
donecommanding2]
'---verify that the data matches
if servonum!=servonum2 or rate!=rate2 or position!=position2 or _
donecommanding!=donecommanding2 then
'data is bad recieve again
goto recieve 'try again
endif
low picoutpin
'-----end serial request
gosub setupservo
goto drivemotor 'return to main routine
I have one question, would using a lower baud rate decrease the frequency of errors? If you have any suggestions to improve this code, please feel free to through in your two cents. Thanks again!
Bookmarks