View previous topic :: View next topic |
Author |
Message |
may26baf
Joined: 04 Oct 2006 Posts: 7
|
How to reset serial port |
Posted: Thu Jan 18, 2007 7:45 am |
|
|
I am developing an application for the 18f6722. I have configured it to use rs232 for PORT2, and have enabled the interrupt to detect incoming bytes.
The problem that I'm having is that sometimes, when I boot the device, I don't appear to get traffic on that port, but other times, it works. What I suspect is happening is that when I initially turn on the device, the component on the other end of the serial port sends a burst of traffic (at the wrong baud rate) and overflows the 3 character buffer in the PIC. I think that when this happens, the PIC stops accepting incoming bytes.
My question is: Is there a way to reset the serial port? I've tried disabling and re-enabling interrupts, but that didn't have any effect. I'm looking for some other means of re-initializing the serial port.
Thank you. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Jan 18, 2007 8:32 am |
|
|
Search the documentation for "rs232_errors". Also look at the datasheet for your part. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
may26baf
Joined: 04 Oct 2006 Posts: 7
|
|
Posted: Thu Jan 18, 2007 10:00 am |
|
|
In the spec sheet for the PIC, the lines are just GPIO lines, so there is nothing there about resetting the rs232.
In the help for the compiler, its suggestion is to trace the incoming data line. I know that the problem isn't there because I can receive data sometimes.
Furthermore, I can not find any topic in the compiler help for "rs232_errors".
If you could identify specific commands that are used to reset the serial port on a PIC I would appreciate it. |
|
|
nousername Guest
|
|
Posted: Thu Jan 18, 2007 10:06 am |
|
|
put the ERRORS option in your #use rs232 statement to record errors on the serial input and clear them when they occur |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Jan 18, 2007 10:09 am |
|
|
The "ERRORS" option has nothing to do with a software based serial com. "ERRORS" is only for a hardware USART.
I think it is closly tied to the OERR bit and then CREN bit used to clear OERR.
What is the pin/port you are using?
like RC6? or RA4??
Ignor this post,...See below.. This is the second hardware EUSART. You threw me by calling them GPIO lines.
Last edited by treitmey on Thu Jan 18, 2007 11:26 am; edited 3 times in total |
|
|
may26baf
Joined: 04 Oct 2006 Posts: 7
|
|
Posted: Thu Jan 18, 2007 10:24 am |
|
|
I see where your going.
To answer your question, the serial port is configured as
#use rs232 (baud=4800, xmit=PIN_G1, rcv=PIN_G2, stream=PORT2)
So, now a newbie type of question. How do I access the specific registers? I take it that I need to read RCSTAx and if check the OERR bit. Furthermore, my problem may be that I need to clear the CREN bit. How do I go about addressing specific registers like this? |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Jan 18, 2007 11:22 am |
|
|
OK. This is a HARDWARE EUSART implimentation.
(the second EUSART)
The ERRORS directive should work for this. But if you want to
you can access the bits with a #byte and/or #bit. |
|
|
may26baf
Joined: 04 Oct 2006 Posts: 7
|
Thanks |
Posted: Thu Jan 18, 2007 8:29 pm |
|
|
Thanks everyone for your answers. With your help I was able to read the RCSTAx register and verify that in fact the OERR bit was getting set. Once I determined that, I was able to go in and reset the CREN bit, to re-enable data on the port. |
|
|
Matias
Joined: 12 Sep 2005 Posts: 5
|
RS232_errors, do not disable it! |
Posted: Fri May 18, 2007 11:33 am |
|
|
From the CCS Manual:
Warning:
The PIC UART will shut down on overflow (3 characters received by the
hardware with a GETC() call). The "ERRORS" option prevents the shutdown by detecting the condition and resetting the UART.
It is a good idea to include always ERRORS in #use RS232 declaration, specially when you are developping plug&play devices, the bus may be running before you configure the UART |
|
|
|