Serin and the Stack
I am trying to run a serin command with a timeout from within a subroutine. However if the timeout occurs I still want to return to the command after the subroutine call. An example of what I want to do is below. The problem is that the variable gled1 never gets cleared in normal run mode if the timeout occurs. However if I uncomment the break and run it in debug mode it works fine. I am checking the pin status using a good scope.
From my understanding the timeout triggers a jmp to 'missed' so the original return address should still be at the top of the stack. The return in 'missed' or 'rs' should be accessing the same address, I think. If I replace the serin with 'goto missed' it also only works in debug mode. Anyone have any suggestions?
Also is there any way to empty the call stack?
Thanks a lot!
Amit
From my understanding the timeout triggers a jmp to 'missed' so the original return address should still be at the top of the stack. The return in 'missed' or 'rs' should be accessing the same address, I think. If I replace the serin with 'goto missed' it also only works in debug mode. Anyone have any suggestions?
Also is there any way to empty the call stack?
Thanks a lot!
Amit
DEVICE SX48, OSCHS2
FREQ 50_000_000
PROGRAM start
GLED1 var RC.2 'LED
RLED2 var RC.3 'LED
missed sub 'signal missed comm
rs sub 'receive serial comm
start:
temp = 0
output gled1
output rled2
goto mainloop
rs:
\clrb rled2
serin ra.0, T57600, temp, 1, missed
'goto missed
return
missed:
\setb rled2
return
MainLoop:
\setb gled1
rs
\clrb gled1
temp=6
' watch temp
' break
goto MainLoop

Comments
I would just set a bit variable.
DEVICE SX48, OSCHS2 FREQ 50_000_000 PROGRAM start GLED1 PIN RC.2 OUTPUT 'LED RLED2 PIN RC.3 OUTPUT 'LED temp VAR byte ' I assume ??? flag var bit rs sub 'receive serial comm start: temp = 0 ' Not really needed since SX/B clears all variables at startup goto mainloop rs: rled2 = 0 flag = 1 ' Assume we will miss it serin ra.0, T57600, temp, 1, missed flag = 0 ' Cool, we didn't miss it missed: rled2 = flag return MainLoop: gled1 = 1 rs gled1 = 0 temp = 6 goto MainLoopBean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Don't mistake experience for intelligence. And vis-vera.
·
Thanks,
Amit
I am wondering if there is a chance that the program is working as you expect but just too fast for you to observe the result with your current scope setting. Your gled1 is going to clear and then set very quickly so be sure to use a very fast sweep rate on your scope.
Including the break command and running the debugger allows the program to suspend while gled1 is clear. I suspect that including some form of a pause in place of the break statement would reveal whether or not gled1 is actually setting and clearing.
Just trying to help.