View previous topic :: View next topic |
Author |
Message |
barkerben
Joined: 19 Jan 2006 Posts: 22
|
Relaying serial data |
Posted: Wed Mar 22, 2006 5:14 pm |
|
|
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
|
Relaying serial data |
Posted: Wed Mar 22, 2006 6:56 pm |
|
|
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
|
|
Posted: Thu Mar 23, 2006 3:10 am |
|
|
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
|
Relaying serial data |
Posted: Thu Mar 23, 2006 11:24 am |
|
|
>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
|
|
Posted: Thu Mar 23, 2006 1:24 pm |
|
|
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
|
|
Posted: Thu Mar 23, 2006 6:17 pm |
|
|
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
|
|
Posted: Thu Mar 23, 2006 6:31 pm |
|
|
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
|
|
Posted: Fri Mar 24, 2006 8:15 am |
|
|
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
|
Relaying serial data |
Posted: Fri Mar 24, 2006 11:03 am |
|
|
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
|
|
Posted: Fri Mar 24, 2006 7:41 pm |
|
|
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
|
|
Posted: Fri Mar 24, 2006 8:34 pm |
|
|
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
|
|
Posted: Sat Mar 25, 2006 5:43 am |
|
|
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
|
|
Posted: Sat Mar 25, 2006 8:56 am |
|
|
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. |
|
|
|