Use an interrupt to prompt SERIN

PiX

New Member
I'm a bit stuck on this one and would appreciate any help the forum can give me please:

I have two Picaxes communicating via SEROUT and SERIN commands, hardwired together.
The SEROUT on chip A is prompted by an interrupt (a 'GO' switch) and this works just fine.
What I'm struggling with is making chip B react to the SEROUT on chip A (and execute a SERIN) via an interrupt on the same (SERIN) pin.
I want chip B to be doing other stuff whilst waiting for 'GO' from chip A so that it can then jump to a subroutine dependent on what is sent in the serial data.
I HAVE NO SPARE PINS TO USE ON EITHER CHIP.

I've tried the following but the result is intermittent:
Chip A
on interrupt execute a high on the SEROUT pin, then execute the SEROUT command
Chip B
interrupt when the SERIN pin goes high, then execute a SERIN command
I'm using N2400 as the baud rate if that helps.
 

rossko57

Senior Member
Timings are likely to be important. We've no idea what provision you might have made for that. Code snippets?
 

PiX

New Member
Sending:
#Picaxe 08M2
symbol STRT = C.1 ;INPUT start switch
symbol TX = C.2 ;OUTPUT serial out to 20M2
symbol LED = C.4 ;OUTPUT led

setup_pins:
let dirsC=%00010100
let pinsC=%00010000
pullup %000000000000000

checkstatus:
setint %00000010,%00000010 ;set interrupt for start switch
pause 500: low LED: pause 500: high LED ;flash led whilst waiting for interrupt
goto checkstatus

interrupt:
serout TX,N2400,(10)
pause 50
low LED ;turn led on to acknowledge that data has sent
wait 5
return

Receiving:
#Picaxe 20M2
symbol LED = C.0 ;OUTPUT led
symbol RX = C.3 ;INPUT serial in from 08M2

setup_pins:
let dirsC=%00000001
let pinsC=%00000001
pullup %000000000000000

checkstatus:
setint %00001000,%00001000 ;set interrupt for RX going high
pause 500: low LED: pause 500: high LED ;flash led whilst waiting for interrupt
goto checkstatus

interrupt:
low RX ;make pin low to receive data
pause 50
serin RX,N2400,b0
pause 50 ;time for variable to update
if b0=10 then low LED:endif ;turn led on to acknowledge that data has arrived
wait 5
return
 

Hemi345

Senior Member
Try this interrupt routine for your sender:
Code:
interrupt:
high TX : pause 100 : low TX	;blip comms line to interrupt 20M2
serout TX,N2400,("ABCD",10)	;use ABCD qualifier before data
low LED	;turn led on to acknowledge that data has sent
wait 5
return
and this interrupt routine for your receiver:
Code:
interrupt:
serin [1000],RX,N2400,("ABCD"),b0 ;use 1s timeout and ABCD qualifier
if b0=10 then low LED:endif	;turn led on to acknowledge that data has arrived
wait 5
return
 

PiX

New Member
Perfect, thank you. Why is it so obvious when you see it?
I'll use the qualifier but why is it necessary when I only have one 'receiver', I thought you used this if you had multiple 'receivers' so that each could recognise who the data was for?
 

hippy

Technical Support
Staff member
Qualifiers are not required for a hard-wired point-to-point link where comms are synchronised as here.

I also would not include any timeout on the SERIN command. If one is used then it is best to use it to skip the rest of the code or it can end up looking like data was received when it wasn't which will confuse things.

For the interrupt it is better in the sender to use -

High TX
Pause ...
SerOut TX, Txxxx, ( ... )
Low TX

And in the receiver ...

SerIn RxTX, Txxxx, ...
 

Hemi345

Senior Member
I never had success in hard-wired p2p comms without using either a timeout or a qualifier or both. Granted, my receiver had a lot more going on than in PiX's receiver code, but I usually missed the first few bytes or had junk stored in the few bytes and missed the last bytes when trying to trigger comms in an interrupt routine. But that could be because I was using Nxxxx baud mode. Using T makes a lot more sense!
 

oracacle

Senior Member
I have been using some serial comms similar that of hippys suggestion.
to recieve
Code:
            [color=Blue]pulsout casout[/color][color=Black], [/color][color=Navy]1000                                  [/color][color=Green]'send ready pulse
            [/color][color=Blue]serin cascserial[/color][color=Black], [/color][color=Blue]baud[/color][color=Black], [/color][color=Blue](qual)[/color][color=Black], [/color][color=Purple]instruct              [/color][color=Green]'recieve from line 80[/color]
to send
Code:
[color=Blue]low prevout
            do while [/color][color=Purple]previn [/color][color=DarkCyan]= [/color][color=Navy]0
            [/color][color=Blue]loop
      pause [/color][color=Navy]250
      [/color][color=Blue]serout prevout[/color][color=Black], [/color][color=Blue]baud[/color][color=Black], [/color][color=Blue](qual)                                [/color][color=Green]'now send qualifier and test instruction back to confirm working
      [/color][color=Blue]pause [/color][color=Navy]4
      [/color][color=Blue]serout prevout[/color][color=Black], [/color][color=Blue]baud[/color][color=Black], [/color][color=Blue]([/color][color=Purple]instruct[/color][color=Blue])[/color]
there is a holding loop that holds the sender until the receiver sends its pin high. the pause 250 ensures that the receiver has moved to the serin command before the sender send it data.

The nice thing is about the holding loop is that if the receiver either never becomes ready, or is not connected the sender can tell and can take action of needed.
 
Top