CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

De-energized UART issue

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








De-energized UART issue
PostPosted: Tue Aug 23, 2005 3:34 pm     Reply with quote

I am using a PIC 16F88 for UART-to-UART serial communications. The external UART will be powered up and down while the PIC stays powered up. When the external UART is powered down, the PIC will see a clear signal level (0 volts) on its RX line. The PIC will see this as a start bit and then read 8 bits worth of zeros into the RSR. I am concerned that this condition will cause the PIC to read a lot of spurious data.

The only brake on this seems to be the stop bit (set signal level or high voltage), but the manual isn't clear. The manual mentions the PIC transfers data to the RCREG "after sampling the stop bit". Then it mentions the framing error flag, "FERR is set if a STOP bit is detected as clear".

Anyone know if a clear stop bit will inhibit loading the RSR into the RCREG? Is there some hardware trick like using a large value resistor to pull the RX line high to keep the PIC from seeing the low voltage condition caused by the de-energized external UART?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 23, 2005 3:46 pm     Reply with quote

Are you using a MAX232-type chip ? They have pull-down resistors
on their RS-232 input pins. If there's no signal driving the input
pin, it will be held at zero volts. After the inversion inside the MAX232,
the PIC will see a high level, which is a stop bit.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Aug 23, 2005 5:52 pm     Reply with quote

Don't forget to ensure that the PIC does not drive any lines high to the powered down uart as this could a) destroy the UART or b) keep the UART powered up via the input protection diodes.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Guest








PostPosted: Wed Aug 24, 2005 4:04 pm     Reply with quote

No MAX232. This is a direct hardwire from the UART output to the PIC. I am using only the TX from the UART into the RX of the PIC.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 24, 2005 4:10 pm     Reply with quote

Are you using the hardware UART in the PIC ?

If so, add a 10K pullup to the Rx input on the PIC.
(The pullup is to the same Vdd that runs the PIC).


Are you using a software UART with the INVERT option in the PIC ?

If so, then add a 10K pull-down to the Rx input on the PIC.
(The pull-down is to Ground).
Guest








PostPosted: Thu Aug 25, 2005 10:20 am     Reply with quote

Yes, I am using the PIC hardware UART. The pull up resistor sounds like a good idea. I am also interested in a technical discussion of how the PIC UART works. For example if the stop bit is low, will it still load the data into the RCREG?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 25, 2005 10:42 am     Reply with quote

Quote:
For example if the stop bit is low, will it still load the data into the RCREG?

Yes, but you will get a Framing Error from the USART. This won't lock
up the USART. If you allow the USART fifos to fill up and don't read them
then you'll get a Overrun Error which will lock up the USART. If you add
the ERRORS parameter to your #use rs232 statement, the compiler will
add code to check for an overrun and automatically clear it, if it occurs.
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

Microchip reference manual for the Pic16 USART:
http://ww1.microchip.com/downloads/en/DeviceDoc/31018a.pdf

For the Pic18 USART:
http://ww1.microchip.com/downloads/en/DeviceDoc/39521.pdf

Reference manual page:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1956
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 25, 2005 11:13 am     Reply with quote

Quote:
Yes, but you will get a Framing Error from the USART. This won't lock up the USART.


Unless you don't read the value in which case you will eventually get the buffer overflow which as PCM pointed out will lock up unless you handle the error.
Guest








PostPosted: Thu Aug 25, 2005 1:00 pm     Reply with quote

I modified my code to run an experiement to determine if the UART would transfer data from the RSR to the RCREG if the stop bit was low. The results indicate it does not.

The TX output of the external UART is low when the UART is deentergized. It goes high when energized. A second or so after power up the external UART starts transmitting a fixed data stream.

I am using the PIC hardware UART with the ERRORS parameter and a INT_RDA handler. Since I am interrupt driven on RDA, I presume I am clearing out the FIFO.

In the experiment I release the PIC and several seconds later energize the external UART. This give the PIC plenty of time to sample the low signal from the external UART TX. I capture the first 64 bytes in a RAM buffer then transfer to EEPROM so I can see exactly what the PIC saw. The data shows a single <NULL> character followed by the expected fixed data stream. Based on this I surmise that the single positive transistion caused by power up is read as a high stop bit. The data prior all had low stop bits and presumably were not validated and therefore not transferred to the RCREG. This is why there is only a single <NULL> instead of a bunch of them. Seem reasonable, or is there another explanation?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Aug 26, 2005 7:18 am     Reply with quote

Don't presume your clearing the fifo/RCREG.
At startup. AND I TAKE THIS FROM THE MANUAL

In PIC18F452 manual page 176 section 16.2.2
step 1..6
setp 7 read rcsta
step 8 read RCREG <--- This clears the fifo
step ...9...
then turn on IRQ.

This ensures you startup clean.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

Re: De-energized UART issue
PostPosted: Fri Aug 26, 2005 8:10 am     Reply with quote

So wait - you're not using an external RS232 interface level converter at all? Just the 2 PICs of which one powers off? Why not have a "dtr" line?

Then you'd have a means of "handshaking" unless it's too many lines.

If you used a chip like the MAX221 which has an ~INVALID output and features like auto-shutdown, then you can hook the ~INVALID to something like RC5 (typical in some of my application) and use is as a DTR line as when the receive signal to the MAX221 is non-existant, ~INVALID goes active and you know the other end is either missing or asleep.

Just a thought...

-Ben
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group