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 CCS Technical Support

Relaying serial data

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



Joined: 19 Jan 2006
Posts: 22

View user's profile Send private message

Relaying serial data
PostPosted: Wed Mar 22, 2006 5:14 pm     Reply with quote

Does anyone know of a way, ideally at the hardware level so that it can be done in the background, but if not a the software level, of forwarding all inputs to one pin to the output of another? In other words an echo server really...

I have a GPS system, and I would like to be able to divert all NMEA sentances directly to the PC if needed. I could read them in, store them ,then send them out again.

On the other hand, it might be as simple as having an infinite loop with the statement:

PC_RX_PIN = GPS_TX_PIN

Althouhg I'm not sure if I can equate input and output pins like that. Is there a way of asking the hardware USART to send all input to its output pin, leaving the softeare free to do other things?

Cheers,

Ben
C Turner



Joined: 10 Nov 2003
Posts: 40
Location: Utah

View user's profile Send private message

Relaying serial data
PostPosted: Wed Mar 22, 2006 6:56 pm     Reply with quote

One way to "relay" data is to connect the RX and TX data (from a MAX232 or similar) to the PIC's USART RX and TX pins in the normal way - but then connect a resistor (10k or so) across the two pins.

If you want the received data to simply be echoed on the output, set the "TX" pin to the INPUT mode - most easily done on many PICs with USARTS (in the 16F series, at least) setting the TXEN bit to zero. When you want it to stop, simply re-enable the TX pin as an output and the RX data signal will stop being looped through.

Of course remember, if you are using the software UART, that you'll simply need to do the "TRIS" thing to set the "TX" pin to input/output as appropriate - and you'll want to make sure that you set the state of the TX pin as the appropriate "idle" RS-232 state when it is set as output.

CT
Guest








PostPosted: Thu Mar 23, 2006 3:10 am     Reply with quote

That sounds very useful. Is the following correct then:

The PIC TX and RX lines are joined by a resistor
With the TX line set to an output, the line is tied high or low by the PIC
With the TX line set to an output, the PIC leaes the TX line floating, so we see the serial data appear on it.


Ben
C Turner



Joined: 10 Nov 2003
Posts: 40
Location: Utah

View user's profile Send private message

Relaying serial data
PostPosted: Thu Mar 23, 2006 11:24 am     Reply with quote

>The PIC TX and RX lines are joined by a resistor
>With the TX line set to an output, the line is tied high or low by the PIC
>With the TX line set to an output, the PIC leaes the TX line floating, so we see the serial data appear on it.

Correct - almost: I think that in the second instance you meant to say "input" rather than "output".

While doing this, If you feel brave, you even "look" at the serial data with the RX pin and "see" what that data is - or you could simply look for transititions to see if changing data is still present to decide when to "take over" the TX data again rather than simply passing it through.

CT
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Mar 23, 2006 1:24 pm     Reply with quote

Depending on the baud rate a 10k resistor may be a bit high. If you are running faster then 2400 baud try a 1k resistor.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Thu Mar 23, 2006 6:17 pm     Reply with quote

Quote:

Correct - almost: I think that in the second instance you meant to say "input" rather than "output".


So I did - for such a short post, my spelling was atrocious!

Thanks,

Ben
Guest








PostPosted: Thu Mar 23, 2006 6:31 pm     Reply with quote

Why the change in resistor value with baud rate? I think this ties into my other query, which relates to pull-ups. If the incoming serial data is not to be forwarded, the PIC changes from leaving the PC line floating, to actively driving it to a state - so the PIC and the GPS pull up/pull downs are in competition...? Is it assumed that the PIC can sink/source more current than the GPS unit so will always "get its way"?

I suspect I might be being silly here...

Cheers,

Ben
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Mar 24, 2006 8:15 am     Reply with quote

Anonymous wrote:
Why the change in resistor value with baud rate? I think this ties into my other query, which relates to pull-ups. If the incoming serial data is not to be forwarded, the PIC changes from leaving the PC line floating, to actively driving it to a state - so the PIC and the GPS pull up/pull downs are in competition...? Is it assumed that the PIC can sink/source more current than the GPS unit so will always "get its way"?

I suspect I might be being silly here...

Cheers,

Ben


The resistor will pull the line its way if no one else is driving the line, but it will do it slowly. a 10k resistor may be too slow depending on the baud rate and the capacitance of the line. (The old RC curve, won't it ever go away!)

When the PIC chooses to drive the line it only has to overpower the resistor we added, not the GPS. A PIC can easily overcome a 1k resistor, it just takes a little more battery power than a 10k.
_________________
The search for better is endless. Instead simply find very good and get the job done.
C Turner



Joined: 10 Nov 2003
Posts: 40
Location: Utah

View user's profile Send private message

Relaying serial data
PostPosted: Fri Mar 24, 2006 11:03 am     Reply with quote

The value of the resistor is largely dependant on the wiring/devices involved.

In one particular case, I do this scheme using a 27k resistor on an '877/A with the MAX232/A: It works perfectly in testing at 115 kbaud owing to the rather low capacitances involved and in 'scoping the waveform at the Hi-Z point, it doesn't look too worrying in terms of risetime (somewhat "rounded" - but minimal actual jitter owing to ISI) although 10k might have been better, and 1k would be have been overkill.

(FWIW, where C=1/(2PI*F*Z) and Z=27k, C=50pf when F=115kHz - or 57.6kbaud.)

Not knowing what was involved here in terms of interface devices, I stuck with 10k presuming reasonable baud rates - with 4800 baud being typical for NMEA interfaces.

How low in resistance can one go? It depends partly on the ability of the drivers involved: You won't want to pull so much current that you risk violating the logic thresholds of the deivces involved - plus you raise the quiescent current when the "TX" pin is in a state opposite that of the "RX Data" pin from the receive driver - a concern if you are running from battery.

CT
Guest








PostPosted: Fri Mar 24, 2006 7:41 pm     Reply with quote

Hi,

Apologies - I'm a bit rusty. Which capacitance are we talking about here? Ideally there would be none and response time would not be an issue. In the evrnt there is a parasitic capacitance from somewhere...

The reactance equation for a paralell RC network is given:

C=1/(2PI*F*Z) and Z=27k

Taking Z, the reactance, as 27K. I'm slightly confused, and very annoyed with myself at my confusion :-) Can someone help clarify?

Cheers,

Ben
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Mar 24, 2006 8:34 pm     Reply with quote

The capacitance in this case is the inevitable parasitic capacitance. You will have a few pF at every chip pin, plus a few more for PCB traces, and as much as a few hundred pF in a moderate cable length. Combine that with a 10k pullup resistor and high baud rates will be badly distorted.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Sat Mar 25, 2006 5:43 am     Reply with quote

Oh ok. So we have a paralell combintion of our resistor, R, and a parasitic capacitance to ground.

We eill get 3db rolloff when real = imaginary (as freq ncreases, more signal shorted to ground through cap)

This occurs when:

1 = 2*pi*f*R*C

that is when f= 1/2*Pi*R*C

Assuming C is fixed, and is due to the physical properties of the circuit, then our maximum baud rate is inversely proportional to the chose value of R.

Reducing C therefore to be hoped for by keeping PCB tracks as short as possible, and presumably if you're being very picky by taking care which tracks run close to which other tracks.

Thanks for your help,

Ben
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Mar 25, 2006 8:56 am     Reply with quote

That is right. But if you run the numbers you will find that the capacitance of any reasonable PCB will be small if your baud rates are 115K or less. Cable capacitance is what will cause problems. Also you can probably use resistor values as low as 220 or even 120 ohms if battery life is not a concern.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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