Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,148
Helped
14,386
Reputation
29,036
Reaction score
13,140
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,276
If you don't use an ISR you'll poll the UART receive interrupt flag (RCIF).
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,454
Helped
295
Reputation
590
Reaction score
278
Trophy points
1,363
Location
France 01800
Activity points
10,301
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
 

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
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.
 

nick703

Advanced Member level 1
Joined
Oct 17, 2011
Messages
414
Helped
21
Reputation
44
Reaction score
22
Trophy points
1,298
Location
surat
Activity points
3,872
u need to clear
Code:
  PIR1bits.RCIF    =    0
this flag after reading RCREG .
 

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
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.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,148
Helped
14,386
Reputation
29,036
Reaction score
13,140
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,276
u need to clear PIR1bits.RCIF = 0 this flag after reading RCREG.
Reading the manual helps. RCIF is cleared automatically when reading RCREG.
 

themask

Member level 4
Joined
Mar 5, 2008
Messages
79
Helped
12
Reputation
26
Reaction score
12
Trophy points
1,288
Location
Philippines
Activity points
1,687
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.

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.
 

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top