I'm trying to make several modules that configure themselves automatically as master and slaves all pics being programed with the exact same code. I'm using serin with a timeout and serout. I only have 4 modules built. and it recognizes properly about 70% of the time with 4. I need it to recognize properly every time up to 16 modules. Also I am sending serout 4 times more that I would like. After master is set it sits and waits for ground pluses from each slave so the master knows how many slaves there are. I am sending serin and out on same wire as I am sending the ground pulses back to the master but the ground pulse back happens after serout is complete. Any help would be greatly appreciated. Also just a question how does PBP know on serin when you use a time out that it just isn't more bytes to be sent.(head scratcher since documentation in PBP3 book is kind of vague. just commas) also using onboard oscillators, and B.0 for serin commands and B.1 for serout commands. and the problem I seem to be having when it doesn't sync properly is that serin times out. because down the communication line the 2nd or 3rd module with say its the master also with slaves.
here is my code.
Initial: if ign=1 then
goto initial
else
Initiall: if x=0 then
serin ign, 2, 600, setmaster, ["~"], module
goto setmaster
else
pause 50
seroutrpt: if a<=5 then 'sends serout command 5 times
serout OUT, 2,["~",module]
a=a+1
goto seroutrpt
endif
trisb.1=1 'makes out and input temporarly
trisb.0=0 'makes ign and output temporarly
ign=0 'sends ground pulse to previous slave for slave count
pause 50
ign=1 'idles pulse
goto waitcnt
endif
endif
setmaster: Write 1, module
OUT=0 'wakes next slave to get ready for serin
pause 50
out=1 'gets exsisting ready for serout
x=1 'been through one cycle for serin now will serout
module=module+1
goto Initiall
waitcnt: read 1, master1
if master1=0 then
temp=0
count out, 4000, temp 'counts how many pulses on masters out pin in 4 sec
write 5, temp 'writes how many slaves in series
trisb.0=1 'sets ign back to input
trisb.1=0 'sets out back to output
goto begin
else
keeploop: ign=1 'counts loop for when passthrough is not active
if temp < 255 then 'sets delay loop to keep checking for inputs
if out=0 then
while out=0
ign=0
wend
goto keeploop
else
temp=temp+1
pause 15
goto keeploop
endif
else
trisb.0= 1 'resets b.0 to input
trisb.1= 0 'resets b.1 to output
temp=0
goto begin
endif
endif
thank you,
Joe
Bookmarks