# Need help with SERIN timeout

#### mastero

##### Member
Hello friends,

Need help with the below code.

Code:
Define SERIN_TIMEOUT_REG = INTCON
Define SERIN_TIMEOUT_BIT = TMR0IF

slave:
i = 0
Serout PORTB.0, 9600, "A", CrLf

loop:

Serin PORTB.1, 9600, serdata  'GETS STUCK HERE WHEN NOTHING RECEIVED

If serdata > 0 Then
If serdata = "K" Then
Return
Endif
Endif

i = i + 1
If i = 1000 Then Return

Goto loop
Return
The timeout occurs very soon, is there a way to slow it ?

Cheers
Mastero

Last edited by a moderator:

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Even in Oshonsoft you can check the RCIF flag..

while TIMEOUT < 1000
if RCIF then serget PORTB.1, 9600, serdata
TIMEOUT = TIMEOUT + 1
wend

I haven't tested this code so puppy steps...

#### mastero

##### Member
No the above code will not work in Osho....

solution was

Define SERIN_TIMEOUT_REG = PORTB
Define SERIN_TIMEOUT_BIT = 1

Timeout Bit was tied to serin pin works perfectly.

Thanx

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
So why ask for help if it works....

I have stopped using Oshonsoft, and the timeout bit is a newer feature... However... My way will also work as serget doesn't wait, I only call when something is there..

#### mastero

##### Member
Hello Ian,

When i asked for help it was night here (India) trail and test whole night and found solution before bed time
morning saw your post and replied SORRY

Neways the serget does not exist in Osho.

Hserget is there but i am already using it for GSM module communication.

I am looking for Soft Uart routine which waits for a say 50ms and returns "0" if nothing on serin port..... have anything in mind ?

Define SERIN_TIMEOUT_REG = PORTB
Define SERIN_TIMEOUT_BIT = 1

Is also very fast as i am using 20mhz external with 18f2520 have to put a 10000 check then exit

Any ideas?

Mastero

Last edited:

#### mauried

##### New Member
I havnt used Oshonsoft for quite a while, but one way to solve the blocking problem with serin is to only run the command when there is serial data coming in.
This can be detected by configuring a state change interrupt on the serial input pin so that when the state changes from a high to a low , which signifies the beginning of a start bit , the interrupt executes the serin command and the incoming character is read.
How this is done depends a bit on the PIC , but most can do this.
The only minor problem is that the interrupt routine then hangs for the period of time that it takes to read the incoming character, so can be detrimental if other functions also rely on using interrupts.

#### Pommie

##### Well-Known Member
Can you use one of the newer pics with dual UART?

Mike.

#### mauried

##### New Member
If Serin isnt waiting long enuf, then simply prescale whatever timer you are using so that the timer counts slower.
eg if using timer0, this is an 8 bit timer which can only count to 255, so it will overflow very quickly.
This timer can normally be prescaled by 8 , thus increasing the wait time by 8.
If this still is too short, then use Timer1 which is a 16 bit timer and can also be prescaled, which will get you into many seconds before it overflows.

Forum Supporter