Receiving serial without interupt PIC18F25k50

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Visit site
Activity points
3,661
Hi guys,

I want to do a serial receiving without using the ISR in my PIC18F25k50. I will use my main() loop to do the receiving.
Anyone know how? I had searched the net but all are with interrupt.
 

hello,

If using pooling instead of interrupt you can loose some caracteres if all caracteres are collapsed,
no times between caracteres and big amount of data..
Even using polling , check error Overflow or Overun flags...
Good Result in pooling depends also of
- what is the link speed ? 1200 bauds .. 19200..more ?
- what is the FOSC speed ? 1MHZ..64Mhz
 

I'm writing something like this in main() loop:

Code:
		if (PIR1bits.RCIF==1)
		{
			rxbuf = RCREG;
			RS485RXDATA[n485RxDataPos++] = rxbuf;
		}

Is it ok?
Do we need to clear RCIF flag after reading RCREG?

My baudrate is 9600 and the crystal I use is 20MHz.
 

u need to clear
Code:
  PIR1bits.RCIF    =    0
this flag after reading RCREG .
 

u need to clear
Code:
  PIR1bits.RCIF    =    0
this flag after reading RCREG .
But I search online and found out that you no need to clear the RCIF. It will auto clear after reading RCREG.
 


This is ok. But with a big if!

Since you are using a 9600 baud rate, approximately 1 byte will arrived every 1 millisecond. If you can guarantee that your above code statements will execute every 1 msec, then it is ok.

But if your program loop does other things other than to wait for the received byte, then pure polling/looping may not be a good solution.

You have to use RX interrupts together with circular buffer to make sure that no received byte is lost.
 


Actually, my program loop still will have to do USB transmission.
The data that I received from serial will straightaway transmit using the USB port. I do notice some missing protocol from the USB port. Like for example if I got 20 protocols send to serial port, my USB port only manage to transmit out 7 protocols.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…