Can you use SHIFTIN/SHIFTOUT over RS-232/422/485?
Professor Chaos
Posts: 36
I have a sensor module that uses shift registers to 'serialize' 16 inputs. I read the registers using SHIFTIN with clock, load, and data lines.
I can read the shift registers from the BS2 over a few inches of cable, but not more than that.
So... if I use a serial protocol like RS232, 422 etc, can I just feed the clock, load, and data lines through RS transceivers/line drivers at each end and expect the synchronous serial comunications to work?
I can read the shift registers from the BS2 over a few inches of cable, but not more than that.
So... if I use a serial protocol like RS232, 422 etc, can I just feed the clock, load, and data lines through RS transceivers/line drivers at each end and expect the synchronous serial comunications to work?
Comments
First of all, the clock rate from a BS2 is fairly slow (clock pulse width 14us, clock period 46us ... see the PBasic manual). You should be able to do this over a foot or two at least. You may be picking up noise with longer cables. I suggest that you use either a twisted pairs cable or a controlled impedance ribbon cable with alternating signal / ground pairs.
RS232 signalling would work at this speed, but is probably overkill. You can't use an asynchronous serial protocol without a converter, but RS232 or RS423 signal levels and driver/receivers would work ... Keep in mind that these slow down signal transitions to limit noise, but would probably work fine at these speeds.
Mostly I am curious if the converter solution would work, which I take it it would at BS2 synchronous speeds. I guess I could use some sort of termination (AC?) and gating of logic lines instead, but it's not clear that's particularly easier than running the signals through a line driver.
It does make me wonder what the usual way of connecting sensors from long distances is, short of having some intelligence at the remote end to encode the data.
-Phil
As you get to longer cables, relative timing of multiple signals tends to become a problem and you either have to slow down the timing (and the clock) or go to an asynchronous signalling method or self-clocking system of some kind.
Also, be aware that for SHIFTIN, the BS2 provides the 'clock' for the 'slave' device. A long distance between the BS2 and the 'slave' could shift the clock -- but how long that distance is I couldn't say.
Really, the only reason for using SHIFTIN/SHIFTOUT in this way is if your 'slave' device is so simple it doesn't have a processor of any kind. Which happens, but is rare. I've seen a 3-wire interface for a parallel LCD that used 74HC595 and 74HC164 to accomplish this that used SHIFTIN/SHIFTOUT.
It seems like a more rational design would be to have a simple controller on the slave device that reads the optocouplers and packages the data for asynchronous transmission. But at the moment the BS2 is the only thing I've got (or understand).
Just to clarify for future postings the protocol and driver specifications are two different things. RS-232 is not a protocol but an electrical specification as is RS-485/RS-422 etc. The protocol would be the Serial, SPI, I2C, etc. So your question revolves around using a specific protocol on a specific line driver. Quite often RS-422/RS-485 use serial protocol but not necessarily. Standard network connections will use their own protocol which the BASIC Stamp cannot talk directly to. Just wanted to put that out there for those who sometimes confuse the protocol and electrical specification. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
You can make do with a dual tranceiver at each end, since at each end you need 2 Tx / 1 Rx or 2 Rx / 1 Tx. Since transceivers are cheap this seems like a decent solution.
The newer Max232 chips, which support the 115KBaud and above, produce shorter and faster rise and fall times than the old RS-232 spec -- which is a good thing. But that's what Mike is talking about. It would be a good idea to hang a logic analyzer (or even a storage Oscilloscope) off each end to see what signal degradation is happening, if any, just to check.
It would look like 'rounded' edges on clock signals, phase shift on clock signals, and perhaps even lower amplitude on the returned clock signal.
However, thanks for the update and I'm glad it worked for you!