Problem with Serin from basicstamp

fretei

New Member
Hi.
Im strugelin connecting a bs2P to a picaxe18, the bs sending and the picaxe
receiving the data, Im hoping to use it as a port expander.

I have been reading up on the subject and have found this code on the axe side

poweronreset:
setint 1,1
mainloop:
goto mainloop
interrupt:
high 7
serin 0,T2400,b0 ' also tried the N2400 version
debug b0
gosub handledata
setint 1,1
low 7
return

handledata:
if b0 = "A" then
high 0
endif
.... and so on with B, C, D ...

And it works perfect if you coment out the gosub handledata, it receives
and debugs ok.
But if I trie to use the handledata it seems to hang, afther 1-3 received
bytes.
I have tried to pause 5000 between the bytes to let it 'rest' but still
no go..

I can see that the led on p7 flashes, so the program is running, but
nothing is debuged....
Can someone please explain ????, and perhaps come with a solution to
the problem ??

Thanks.

Tore
 

MPep

Senior Member
Tore,

You will get a faster reply if posted in the general forum. This section is for finished projects.

Maybe try SEROUT instead of DEBUG B0.

MPep
 

hippy

Ex-Staff (retired)
[ Posts moved to active forum ]

And it works perfect if you coment out the gosub handledata, it receives and debugs ok. But if I trie to use the handledata it seems to hang, afther 1-3 received bytes.
That suggests a problem with the handledata routine. Although you partly describe it, it would be better if you could post the complete code for that routine. Is it ending with a RETURN ?
 

fretei

New Member
[ Posts moved to active forum ]



That suggests a problem with the handledata routine. Although you partly describe it, it would be better if you could post the complete code for that routine. Is it ending with a RETURN ?
Hi here is the complete code, just added high/low on 6 and 7 to see what the prog is doing.

poweronreset:
setint 1,1
high 6
low 7

mainloop:
goto mainloop



interrupt:
high 7
low 6
serin 0,T2400,b0
debug b0
gosub handledata
setint 1,1
return


handledata:
if b0 = "A" then
high 0
endif

if b0 = "B" then
high 1
endif

if b0 = "C" then
high 2
endif



if b0 = "X" then
LOW 0,1,2
endif

return
 

moxhamj

New Member
I'm trying to get my head around the logic here. If you are reading serial data in, leave out all the interrupts and just run the serin and wait for it to receive something. Then process the input.

If you are using interrupts, I'm guessing you are waiting for a pin to change, then trying to read the input from that pin (or a different pin - what is generating the interrupt signal and what is the timing on that?) There might not be enough time

So maybe just rewrite the code with no setint and no interrupt, do a serin and let the picaxe wait till some data comes in. Maybe get that working and build it up from there.

And I presume the BS is only sending one byte? Might need the code on that too. I've found that with inter-picaxe or picaxe-to-other comms you need a bit more of a protocol than one single byte - eg a header like ABC, then a byte, then a checksum.
 
Last edited:

Technical

Technical Support
Staff member
You can't use one byte to reliably trigger an interrupt and then be valid for the serin command, due to the internal processing time.

There also seems to be no point in using an interrupt here. The following is more compact and efficient.
We would also suggest using a qualifier with serin, e.g. serin 0,T2400,("?"),b0

The master then has to send ?A etc.

Code:
[/FONT]
[FONT=Arial]poweronreset:
high 6
low 7[/FONT]
 
[FONT=Arial]mainloop:[/FONT]
[FONT=Arial]high 7
low 6
serin 0,T2400,b0
debug b0[/FONT]
[FONT=Arial]
if b0 = "A" then 
high 0
endif
if b0 = "B" then 
high 1
endif
if b0 = "C" then 
high 2
endif
if b0 = "X" then
LOW 0,1,2
endif

goto mainloop
 
Last edited:
Top