Continue to Site

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.

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

Serin loop of death

Status
Not open for further replies.

cybersky

Member
Hi All

I have been building small pic networks using the rs232 interface, hardware (16f874) or software version (16f84). PROBLEM. If you use serin it will wait for the amount of bytes specified, forever. IS there a timeout available ?
 
Hi All

I have been building small pic networks using the rs232 interface, hardware (16f874) or software version (16f84). PROBLEM. If you use serin it will wait for the amount of bytes specified, forever. IS there a timeout available ?

You could consider using a timer interrupt, start it when you use the Serin command.
 
so if i use the timer i could just chk for predefined timeout value then simply goto next code block? rxif is that for software or hardware only ? so if rxif bit is xx goto chkdata something to that effect ?
 
The bit PIR1.RXIF gets set when a byte is received. The received byte is in RCREG, reading this register clears RXIF. This is for hardware only.

Edit, how do you check a timer in a continuous loop?

Mike.
 
Last edited:
The OP mentioned both hardware and software. However, even software serial can be written to mimic hardware by using interrupts.

And, to repeat myself, how do you check for a timer timeout in a library routine? Plus, how do you stop a library routine from an interrupt?

Mike.
 
an example for 16F84 shown below
Code:
Define CONF_WORD = 0x3ff2

Dim x As Bit
Dim y As Byte

init:
AllDigital
x = 1

main:
Serout RB0, 9600, "Hello world!", CrLf
While x = 1
		Call serin_timeout(100)
Wend
End                                               
Proc serin_timeout(t As Byte)
	Dim serin_flag As Bit
	serin_flag = 0
	'enable prescaler for tmr0
	OPTION.PSA = 0
	'set tmr0 prescaler for 8
	OPTION.PS2 = 0
	OPTION.PS1 = 1
	OPTION.PS0 = 0
	'enable tmr0
	OPTION.T0CS = 0
	'clear tmr0
	TMR0 = 0
	While TMR0 < t
		If PORTB.1 = 0 Then
			Serin RB1, 9600, y
			Serout RB0, 9600, y, CrLf
			serin_flag = 1
		Endif
	Wend
	If serin_flag = 0 Then
		Serout RB0, 9600, "TIMEOUT", CrLf
	Endif
	'clear tmr0
	TMR0 = 0
	'disable TMR0
	OPTION.T0CS = 1
End Proc
 
hi all - thanks for the replies. too busy at work to even chk email let alone my fav forum. I will try code languer and give feedback asap. Thanks again
 
If you use serin it will wait for the amount of bytes specified, forever. IS there a timeout available ?
Can't you use the WDT?
 
Status
Not open for further replies.

Latest threads

Back
Top