Electrical Solution - part 1
Here is proof of concept that you can detect serial data happening by hardwiring hserin to hint2 (or 1 or 0). Take a look at lots’o’code:
#picaxe28x2
#no_data
#no_table
symbol command = b1
hsersetup B38400_8, %111 ’ inverted signals and auto background serial comms
hintsetup %01000100 ’ setup rising edge trigger on hint2/B.2 hardwired to hserin/C.7
hserout 0, ("===== RESET =====", cr)
gosub interrupt
main:
toggle B.5 ’ invisibly fast blinking LED
goto main ’ how fast is that!
interrupt:
hserout 0, (“triggered with flags=”, #flags, cr)
’ notice how hserflag was raised by the picaxe, but it never triggered any interrupting
’ because I did not setintflags for it
if hserflag = 1 then
hserout 0, (“32.hserflag = serial data received and stored”, cr)
do while ptr != hserptr ’ BTW: ptr and hserptr loop around nicely when they reach the max (1023 on a 28X2)
command = @ptr
hserout 0,(“cmd(”, #ptr, “): “, command, " decimal: “, #command, cr)
inc ptr
loop
hserflag = 0
endif
if flag3 = 1 then
’ there was an interrupt on one or more of the three pins
hserout 0, (” 8.flag3 = any pin”, cr)
if flag2 = 1 then
’ there was an interrupt caused by an edge on B.2
hserout 0, (” 4.flag2 = hardwire hserin", cr)
flag2 = 0
endif
flag3 = 0
endif
hserout 0, (“exiting with flags=”, #flags, cr, cr)
’ NOTICE how I am NOT setting bit5 or hserflag in this byte:
setintflags %00001000, %00001000 ’ interrupt for flag3 only = portB-triggers (any one of 0, 1, 2)
return
’ [end of program]'
This program does not yet combine with the other triggers (bumper switches), but that seems trivial now. Below is the feedback from all the debugging code. After booting, I entered a capital U (aka the binary 01010101 aka “readyfreddyareyousteadyyesyouarebecausenowyouarewarmedup”). Sending multiple bytes “all at once” is not a problem, the background receiving continues to process and store them. But then the main loop will stay untouched for that much longer. This may or may not be bad for your robot.
===== RESET =====
triggered with flags=0
exiting with flags=0
triggered with flags=44
32.hserflag = serial data received and stored
cmd(0): U decimal: 85
8.flag3 = any pin
4.flag2 = hardwire hserin
exiting with flags=0
Flags = 44 corresponds beautifully with %00101100: hserflag, hint3flag and hint2flag. Notice how the sub was called at boot time. The flags were all zero. The routine did nothing but set the desired interrupt mask.