Shop OBEX P1 Docs P2 Docs Learn Events
Sharing a Serial output (logic level) to one device at a time. — Parallax Forums

Sharing a Serial output (logic level) to one device at a time.

RobotWorkshopRobotWorkshop Posts: 2,307
edited 2007-12-12 01:21 in General Discussion
I have a legacy device (Handyboard) with only one Serial port (logic level) that needs to talk to two separate serial devices. One of the target devices is going to be an SX48 based controller. Since there isn't any special protocol (like the appmod) one one device can listen in at once. I only need to transmit to each device and am not concerned with receiving any serial data back from them. My thought was to use something like a 4066 and an 74HC14 chip to handle the switching. With that I could have the Serial out goto the inputs on two of the 4066 switches and then use one of the inverter gates on the 74HC14 so that when the select line toggles only one will be active at once. I expect I may need some pull ups/downs but it should work.

Has anyone else had to do something similar and if so what did you use?

Robert

Post Edited (RobotWorkshop) : 12/7/2007 5:33:55 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2007-10-19 16:28
    What is going to control the 4066 ?

    The "legacy device" ?

    The SX48 could probably handle the switching (instead of using the 4066 & 74HC14).

    You could either receive and re-send to the other device, or use the comparitor to enable/disable the serial stream reaching the other device.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-10-19 18:10
    Hello Bean,

    The legacy device is an older 68hc11 based system (Handyboard) with a single serial port. I can easily send whatever I want to the serial port and it can easily control a digital I/O port which it can use to specify what serial device should be hearing what it has to say. Adding an extra UART or trying to bit bang out the Serial data on another line would be much more complicated that just toggling an I/O line high or low to select the target device. I had thought about just sending everything to the SX48 and let it forward on things not meant for it but the way things are falling into place it may be easier to keep everything on the host. Besides, I think this may come up again and want to get this working as an alternate method of sharing a port. It should also work for sharing other things too.

    So, the Serial out from the host would go to pins 1 and 3 on the 4066, Pin 2 (4066) would go to the Serial in on target device #1, Pin 4 (4066) would go to the Serial in on target device #2 (sx48 in this case). One digital line from the host would go pin 13 on the 4066. That same control line would be connected to one of the inverters on a 74HC14 and then goto pin 5 on the 4066. In theory it should only let the host talk to one of the serial target devices and the other will hear nothing.

    This post isn't about if the Serial port should be shared in this example. That's not the point. It is more of a question that if it does need to be done, what is the best way to share the line and are there better choices than using a 4066 chip. I've seen some examples on using a 74hc157 so that the host could selectively listen to two separate target devices but that was the opposite of what I wanted to do.

    Anyway, if you know of any examples or urls that may reference something like this or have any suggestions let me know.

    Best Regards,

    Robert

    Post Edited (RobotWorkshop) : 12/7/2007 5:34:26 PM GMT
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-10-19 19:37
    Robert,

    It sounds like your approach should work. If you like it, use it! There are other methods to accomplish the same result. Spending much time trying to identify the “best” method is probably not worth the effort.

    If my recollection is correct, I have created a similar signal-sharing scheme with a single quad-NAND-gate chip. However, unless board space or shaving pennies off of the final cost is of great concern I would not say it is significantly better than what you have proposed.

    I understand your desire not to want to code another UART. If you find it easier for your control signal to come from someplace other than the SX, a hardware solution seems like a good option. However, if you can allow the SX to handle the control of the serial port, Bean’s suggestion to use the built-in comparator is elegant in its simplicity! Basically, he is suggesting using the comparator as a switch that either passes or blocks the serial data stream to the 680x controller.

    To accomplish this just use resistors to feed a 2.5V reference signal to one input of the comparator. The output will simply reflect whether the serial signal into the other input is above or below the reference signal. It will therefore copy (or invert, depending on the configuration) the serial signal from the input to the output. When you no longer want the serial signal to pass, simply disable the comparator and set the output pin to the appropriate state. It should be very simple.

    Of course, you still have to know when to switch the serial signal!

    - Sparks
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-12-07 17:31
    I've got this partially working but there are still some bugs to work out. An old Handyboard is the host in this case and it is using one of the optional libraries "pa7_9600.icb" to send out serial data to either a SpeakJet chip or an SX48 chip used as a slave processor. It is using the method described above using a 4066 to switch which chip the Handyboard will be connected and send data to. These are all logic level signals and i'm not using any drivers like the MAX232, etc on the line. The first time through I forgot to add pullup/pulldown resistors on the line so that the input to the device not currently selected would float (not a good thing). Even so, I could send data to the SpeakJet ok and also send data to the SX48 chip. As a test the SX48 would just display whatever byte was sent to it on a set of 8 LEDs. Most of the time the SpeakJet and SX48 would perfectly receive what was sent. However, I noticed that when the SX48 wasn't selected the pattern of LEDs could and would change sometimes on their own. That goes back to the lack of any pullup/pulldown resistors. So, I added pullup resistors on both the serial in on the SpeakJet and the SX48 chip. The SpeakJet worked fine but the SX48 always received 255 (all bits on). Just for the heck of it (it is a prototype after all) I made both resistors pulldowns. In that case the SX48 would display the proper patterns on the LED but this caused another issue. Switching between the two devices caused some random characters to appear on the LEDs and send odd codes to the SpeakJet. I'm sure that was caused because the default state should have been high and when switching between the two devices the pulldown caused a transition which looked like the start of a new byte coming in. This didn't happen when the pullups were used or there wasn't any on the line.

    I'm going to have to go back to the pullup resistors but have to figure out why the SpeakJet seems to get the data ok yet the SX48 always receives 255. Either that or look at a whole different method for sharing out a single serial (output only) port to multiple devices. I'm going to review the whole thing again and double check all the wiring but perhaps someone will notice something I may have missed.

    After doing a couple searches online I found a link with an example but it is a bit more than I need:

    www.netadmintools.com/art40.html

    This one has a good example at the bottom but unfortunately it is the opposite direction...

    www.freewebs.com/maheshwankhede/rs232.html

    A couple chips that might work that I just found is:

    www.onsemi.com/pub/Collateral/NLAS1053-D.PDF
    or
    www.onsemi.com/pub/Collateral/NL7SZ19-D.PDF

    I'd like to see if the original circuit using the 4066 can work as it will save a lot of re-wiring on the protoboard.

    If you have any suggestions i'd appreciate it.

    Robert

    Post Edited (RobotWorkshop) : 12/8/2007 3:35:18 PM GMT
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-12-11 21:10
    Well, this issue seems to be resolved now and should bring closure to this thread. After reading the MAXIM IC app note # AN638 "Selecting the Right CMOS Analog switch" it occurred to me that the right Analog switch was that didn't seem to exist and the best option was just not to use one. I had taken another look at the status of the Serial lines while working and also when idle. It does make more sense to go with a 74HC00 quad NAND gate as Sparks had mentioned. It worked out well since both the 4066 and 74hc14 are both 14-pin DIP chips and the power connections are the same. Just had to rewire a few connections to that IC socket and now everything seems to behave well.

    The only issue (which isn't a problem) is that the SX48 is ready to start working so fast that it is up and ready to receive data before the main board comes up. Whenever the HandyBoard is reset it sees a single glitch on the line which Jon's Interrupt based Serial code sees as a start bit. The remaining bits are all high and this byte is always a 255. In all the testing done so far this happens during power up or a reset of the HandyBoard. All the other odd behavior and random garbage that would occational appear is now gone.

    At first I was thinking about adding a flag to the Serial ISR on the SX48 to disable it when first powered up and then after a slight delay enable the ISR via the flag. That wouldn't fix any of the 255 character sent if the HandyBoard was reset after a powerup. Since the first byte sent to the SX48 should always be some sort of command (not a 255) the invaild character will just get discarded. With that I don't have to add the flag to disable the ISR and it also gets around the issue of the odd character being sent if the HandyBoard is reset.

    Now I can finally get working on the rest of the SX48 program and keep going on the rest of the project.

    Robert
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-12 01:21
    Robert,

    On my latest board, I use a dual 4x1 multiplexer CD4052 to share·SPI and serial devices.
    The X channel is used as input to read one of 4 outputs, the Y channel is used
    as output to send a signal to one of 4 inputs. The Yn pins have all pullups, as has the X pin.
    In addition, there are 1k series resistors in front of the X and Y pin (so Ron has little to no effect).
    The two select inputs A and B are connected to my SDA and SCL lines.
    This means, when I need to select a device, I must first lower SCL, then set SDA and SCL.
    Before using the the I2C bus, I must set the Y pin high, because with I2C the·channels are selected
    randomly, but due to the high·Y, and the pulups on Yn pins, the devices consistently only see
    a high input. This works very well.

    regards peter
Sign In or Register to comment.