PDA

View Full Version : weird data



chriroz
- 12th November 2006, 16:13
I'm working on a local positioning system. I have one robot that sends a soundpulse and 3 receiver ("satalites") that receive that pulse and send all the timing data back to the robot.

I have one master receiver that has the wireless connection to the robot AND is connected (wired) to both other slave receivers. The master sends a signal to all devices (robot, and 2 slaves) to send a sound pulse or to start counting so this starts synchrome.

I have a problem with receiving the data from the slaves:

-If I give both slaves the "right" (serout2) code then the master will receive nothing and times out when trying to receive the data from the slaves

-if I give one slave(doesn't mater witch one) a "wrong" code (serout) THEN the master will time out ONLY when trying to receive the data from the bad slave and it will receive the data from the other slave

-if i give both slaves the wrong (serout) code then it will time out on both again

why doesn't it work when i give both slaves the right code? and how do i fix it?

this is my full code:

Master:


define OSC 20
ANSEL = 0
TRISC=%00000100
POKE $19, 7
'dEFINE CHAR_PACING 10
INCLUDE "modedefs.bas"

S_In var PORTC.1 'data line to PORTC.1 on both slave receivers
S_Out var PORTC.4 'data line to wireless transmitter and
'PORTC.0 on both slave receivers
Led var PORTC.3
Pin Var PORTC.2 'Soundpulse In
Cnt var byte
ResM var word
ResS1 var word
ResS2 var word

init:

gosub Startblink
input pin
resM = 0
resS1 = 0
resS2 = 0

Main:
SEROUT s_out, N2400,["1234rt"] 'give a signal to start a soundpulse
rctime Pin, 0, resM 'record time for sound to reach this receiver
pause 300
Serout2 S_Out, 17197, ["SA"] 'Give signal to slave 1 to send data
SERIN2 S_in, 17197, 200, TimeOut1, [WAIT ("A"), ResS1.LOWBYTE, ResS1.HIGHBYTE]
'receive data from slave 1
S2_In:
PAUSE 100
Serout2 S_out, 17197, ["SB"] 'Give signal to slave 2 to send data
SERIN2 S_in, 17197, 200, TimeOut2, [WAIT ("B"), ResS2.LOWBYTE, ResS2.HIGHBYTE]
'receive data from slave 2
Dat_Send:
gosub blink
SEROUT s_out, N2400,["1234ul", resM.lowbyte, resM.highbyte, resS1.lowbyte, resS1.highbyte , resS2.lowbyte, resS2.highbyte]
'send all data back to robot
pause 20
goto main





Timeout1:
resS1 = 11111 'error code for slave 1
goto S2_in

Timeout2: 'error code for slave 2
resS2 = 22222
goto Dat_Send




Blink: 'blink
high led
pause 3
low led
return

Startblink: 'nice blink to show the device is started
for cnt = 1 to 10
high led
pause 5 * (16-cnt)
low led
pause 5 * (16-cnt)
next
return


slaves (this is the code for the slaves. there are 2 small differences between the code from slave1 and slave2 (the "A" changes in "B"))


define OSC 20
ANSEL = 0
TRISC=%00000100
POKE $19, 7
'dEFINE CHAR_PACING 10
INCLUDE "modedefs.bas"

S_In var PORTC.0 'dataline to PORTC.4 on master receiver
S_Out var PORTC.1 'dataline to PORTC.1 on master receiver
Led var PORTC.3
Pin Var PORTC.2 'Soundpulse In
Cnt var byte
Res var word


init:
gosub Startblink
input pin
res = 0

Main:

serin2 S_in, 16780, [wait("t")] 'wait counting untill soundpulse is sent
rctime Pin, 0, res 'record time for sound to reach this receiver
serin2 S_in, 17197, [wait("A")] 'wait to send data
'serin2 S_in, 17197, [wait("B")] this is the other code for the second slave
gosub blink


SEROUT2 s_out, 17197,["A",res.lowbyte,res.highbyte]'send data back to master
'SEROUT2 s_out, 17197,["B",res.lowbyte,res.highbyte] this is the other code for the second slave
'if i change this SEROUT2 to SEROUT and leave the other slave at SEROUT2 then the OTHER slave works (see post)


goto main



Blink: 'blink
high led
pause 10
low led
return

Startblink: 'nice blink to show the device is started
for cnt = 1 to 10
high led
pause 5 * (16-cnt)
low led
pause 5 * (16-cnt)
next
return