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 ?
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..
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.
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.
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.
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..
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...