View previous topic :: View next topic |
Author |
Message |
wanli
Joined: 20 Aug 2004 Posts: 5
|
UART flow control of PIC18F6720 |
Posted: Mon Aug 30, 2004 2:50 am |
|
|
Hi folks,
I am using the UART 1 (RC6, RC7, GND) of PIC18F6720 for a serial communication. But there is some problem.
If PIC received data, the data is correct. But when the sender transmitt more bytes continuiously, without delay between each bytes, after some byte, the PIC stops receiving, and does not react the serial event any more. When I insert some delay between each byte (e.g. 50ms), all data could be received correctly, and the PIC stays in a normal status. When I send data from PIC to the other device, all data are correctly received. Because the device I used to communicate with PIC has a higher working frequenz (PIC's osc is 20MHz, the other is 73.7MHz), so I thought it should be a problem of flow control.
Someone could tell me, how could I make a flow control on UART with only 3 pins (RC6, RC7, GND), and how can turn the PIC from the overflow status back to work?
Any tip is appreciate!
Wanli |
|
|
alexbilo
Joined: 01 Jun 2004 Posts: 39 Location: Trois-Rivières
|
|
Posted: Mon Aug 30, 2004 5:24 am |
|
|
Hi,
Your problem looks effectively as a flow control problem. However, hardware flow control needs two more pins to be implemented. If you need fast communication and prefer to avoid adding delays to make things work right, you can use the serial port interrupts. This way, instead of checking on the serial port data once in a while (as in a loop), you'll read the data as soon as it arrives, avoiding most of overflow problems.
Good luck, _________________ Alex |
|
|
wanli
Joined: 20 Aug 2004 Posts: 5
|
|
Posted: Mon Aug 30, 2004 6:20 am |
|
|
Hi,
Thank you for your reply.
But problem is, I do use Interrupt routine to handle with the Serial Event. But the PIC stops receiving still, and It cannot react any other coming data.
The code is as following:
#use rs232(baud = 115200, XMIT = PIN_C6, RCV = PIN_C7, BITS = 8, PARITY = N)
#int_RDA
RDA_isr()
{
char buff;
buff = getc();
putc(buff);
}
void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(global);
......
}
Is there something wrong?
Wanli |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
Add the ERRORS keyword |
Posted: Mon Aug 30, 2004 9:37 am |
|
|
The UART is hanging when it encounters a receive error. You need to add the ERRORS keyword to the USE RS232 statement so it will clear serial receive errors. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Aug 30, 2004 10:20 am |
|
|
The putc also probably wait until the character is transmit which is the cause of your problem. It takes just as long to receive the char as it does to send it. You should receive the chars into a buffer and transmit them out of the buffer. The speed of the processors is not a factor in the code that you posted. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
|
|