Serial Interrupt Problem

iGull

New Member
Hi All

Having a bad morning here :))
I've attached a wee bit of minimalist code to illustrate the problem. All I want it to do is on receipt of some non-synchronous serial data, fire the beeper every time that some serial data is received - I'm only sending ONE character for test purposes - not a string of chars and would expect it to fire once every time I send it a char.
What happens is that on receipt of the data, it interrupts, fires the beeper, waits a second (I've purposely put in a 1S pause), fires the beeper - ad nauseam !
I can't for the life of me see what's wrong with this :)
I can remove the setintflags (resetting the int flag for bit 5) from the interrupt - it fires once then remains silent for any subsequent serial reception as you would expect - replacing the setintflags causes the interrupt code to fire forever.

No doubt I've missed some important point in the proceedings LOL

TIA

Neil

#picaxe 28x2

symbol beeper = b.6
symbol nextButton = pinA.2 'Leg 4

init: hsersetup B9600_8, %001 '9600,8,N,1 - background receive on
setintflags %00100000,%00100000 'interrupt on receipt of data
low beeper

main: gosub waitButton
goto main
end

beep1: high beeper
pause 70
low beeper
return

waitButton: if nextButton = 0 then 'no debouncing - just wait ...
gosub beep1
return
else
goto waitButton
endif

interrupt: gosub beep1
pause 1000
setintflags %00100000,%00100000 're-enable the interrupt flag
return
 

BeanieBots

Moderator
you need to clear flag after the it's interrupted. Otherwise the flag is still set and will cause another interrupt.

Try adding "flags=0" after your pause in the interrupt routine.
 

kranenborg

Senior Member
Hi,

According to the description of HSERSETUP in the manual the hserflag (flag5 in the flag byte, see p17 in the BASIC commands manual) is set after a byte has been received (and this will trigger the interrupt) and you will have to reset it yourself (in the interrupt routine). Not doing this will retrigger the interrupt endlessly and this is probably what you experience.
Thus LET flag5 = 0 included in the interrupt routine should do the job I assume ...

/Jurjen

PS: Ah, BB was faster ...
 

iGull

New Member
"No doubt I've missed some important point in the proceedings LOL"

You see, I was right :)

Setting flags to 0 did the trick - many thanks for all the replies.

I did RTFM too :)

Cheers

Neil
 
Top