• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
slaveready = False
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
            slaveready = True
              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:

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
Most Helpful Member
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?

Thanx in advance
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.
 

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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
I would use a serial uart in conjunction with one of the RB interrupt on change pins, That way you can wait for a start read the pin and flag an arrival.

The only downside is using a spare timer to clock in the data, this will keep you processor doing other things.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
I had already written a software serial using interrupts in C, so I have tried to convert to Oshon ( sooo limiting!! ) BUT!! it works
I had to dabble with the timings as basic takes its toll.. But I have managed a 9600 with a 20Mhz crystal using the INT0 pin and a timer to grab a byte.. I even put in over/underrun error.. I tested it and seems to be fine..
 

sagor1

Active Member
What are you initializing the timer to? Nothing in your code shows the prescaler or interval values, nor enabling the timer itself.
Post the whole code if you can.
With a 4Mhz CPU clock (crystal), the longest time interval you can get with TMR0 is about 65mS. If you have a higher clock speed, interval will be even less.
With TMR1, you can get just over 500mS at 4Mhz clock speed (and less time/period at higher clock rates)

In your code, once you get a character, you would normally reset the timer again to have a timeout for the next character.
EDIT: I see this thread is old, oh well, I tried...
 

EE World Online Articles

Loading

 
Top