I modified an example of the serial software routines to be able to insert a well-defined and calculated timeout time according to the clock with a very simple script, from some tests it seems tests everything seems to work. I wanted your opinion.
Also I tried to use a function to pass a value that is not considered in the manual, is all this working?
' CALL functionifser_tout(300)="r"thenser1print"Ok"' legge seriale (300mS timeout)' ---functionser_tout(RxTimeOutasword)' time out in mS
#scriptIfPICThenSerTime=int(chipMHZ*100/5)' (8Mhz)160 = 1mS circaendif
#endscriptDoRepeatserTime'large inner loop to get delays of some secondsIf!SER1_RXPINThen'if falling edge of startbit detectedser_tout=Ser1Receive'... get byteExitSub'exit sub after byte is storedEndIfEndRepeatRxTimeOut--'count down the delayloopLoopWhileRxTimeOut'exit if is down to 0endfunction
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The function works as designed but as scripts are essentially all run at the start of compilation the script is not executed as you have it.
So, changed to conditional test as follows:
' CALL functionifser_tout(300)="r"thenser1print"Ok"' legge seriale (300mS timeout)' ---functionser_tout(_RxTimeOutasword)asbyte' parameter as time out in mS returns ... a default of 0....when times outDim_SerTimeasWord
#IfdefPICThenSerTime=int(chipMHZ*100/5)' (8Mhz)160 = 1mS circa
#endif
#IfdefAVRThenSerTime=Stuff??
#endifDoRepeatserTime'large inner loop to get delays of some secondsIfSER1_RXPIN=0Then'if falling edge of startbit detectedser_tout=Ser1Receive'... get byteExitFunction'exit sub after byte is storedEndIfEndRepeat_RxTimeOut--'count down the delayloopLoopWhile_RxTimeOut'exit if is down to 0ser_tout=0'or the default value when it times outendfunction
~~~
Last edit: Anobium 2020-05-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The initialization of the ser_tout variable is missing.
Better this way:
functionser_tout(RxTimeOutasword)' time out in mS
#scriptIfPICThenSerTime=int(chipMHZ*100/5)' (8Mhz)160 = 1mS circaendif
#endscriptser_tout=0DoRepeatserTime'large inner loop to get delays of some secondsIf!SER1_RXPINThen'if falling edge of startbit detectedser_tout=Ser1Receive'... get byteExitSub'exit sub after byte is storedEndIfEndRepeatRxTimeOut--'count down the delayloopLoopWhileRxTimeOut'exit if is down to 0endfunction
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have copied the code down from my previous post.
' CALL functionifser_tout(300)="r"thenser1print"Ok"' legge seriale (300mS timeout)' ---functionser_tout(_RxTimeOutasword)asbyte' parameter as time out in mS returns ... a default of 0....when times outDim_SerTimeasWord
#IfdefPICThenSerTime=int(chipMHZ*100/5)' (8Mhz)160 = 1mS circa
#endif
#IfdefAVRThenSerTime=Stuff??
#endifDoRepeatserTime'large inner loop to get delays of some secondsIfSER1_RXPIN=0Then'if falling edge of startbit detectedser_tout=Ser1Receive'... get byteExitFunction'exit sub after byte is storedEndIfEndRepeat_RxTimeOut--'count down the delayloopLoopWhile_RxTimeOut'exit if is down to 0ser_tout=0'or the default value when it times outendfunction
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I fixed the routine, the function does not pass any value, you have to define it first. I have done many tests and it seems to work well.
#defineRxTimeOut500'time_out 500 mS
#defineRx_serPORTB.6'define pin serial' CALL functionifser_tout="r"thenser1print"Ok"'read seriale con TimeOut functionser_timeout' time out in mS
#scriptIfPICThenSerTout=int(chipMHZ*400/5)' (8Mhz)640 = 1mS circaendif
#endscriptser_timeout=0repeatRxTimeOutRepeatSerTout'large inner loop to get delays of some secondsifRx_ser=0thenser_timeout=Ser1Receive'... get byteExitfunctionendifEndRepeatEndRepeat'Endfunction
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Anobium
Thanks for the help to better understand, now the function passes a value correctly, the script has been removed I simply put a definition to get the delay calculation.
Note that the name of the polling pin was originally incorrect.
Yes, if no data is received it returns zero, this could be a problem, it would be to return the flag but it further complicates the routine.
I have done many tests and everything seems to be working well.
' CALL functionifser_timeout(500)="r"thenser1print"Ok"'read seriale TimeOut ' ----functionser_timeout(_RxTimeOutasword)asbyte' time out in mS
#defineSerToutchipMHZ*400/5' (8Mhz)640 = 1mS circaRepeat_RxTimeOutRepeatSerTout'large inner loop to get delays of some secondsifSER1_RXPORT.SER1_RXPIN=0thenser_timeout=Ser1Receive'... get byteExitfunctionendifEndRepeatEndrepeat'ser_timeout=0Endfunction
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I modified an example of the serial software routines to be able to insert a well-defined and calculated timeout time according to the clock with a very simple script, from some tests it seems tests everything seems to work. I wanted your opinion.
Also I tried to use a function to pass a value that is not considered in the manual, is all this working?
@Gigi. With respect to this code. I will explain.
The function works as designed but as scripts are essentially all run at the start of compilation the script is not executed as you have it.
So, changed to conditional test as follows:
~~~
Last edit: Anobium 2020-05-03
The initialization of the ser_tout variable is missing.
Better this way:
@Gigi. Regarding this code. Look at this guide https://github.com/Anobium/Great-Cow-BASIC-Help/blob/master/source/DeveloperGuide.adoc
I have copied the code down from my previous post.
I fixed the routine, the function does not pass any value, you have to define it first. I have done many tests and it seems to work well.
@Gigi. Which library as this looks good code.
And @Gigi....
Surely this function would be called.. SerNReceiveTimedOut where N is port.
This is hardcoded to Ser1Receive.
May need a little more thiking, and, I am not sure what happens with
AVRs?
The default value of a timed out value is 0?
@Anobium
Thanks for the help to better understand, now the function passes a value correctly, the script has been removed I simply put a definition to get the delay calculation.
Note that the name of the polling pin was originally incorrect.
Yes, if no data is received it returns zero, this could be a problem, it would be to return the flag but it further complicates the routine.
I have done many tests and everything seems to be working well.