Shop OBEX P1 Docs P2 Docs Learn Events
Multiple BS2s on a Single Serial Line? — Parallax Forums

Multiple BS2s on a Single Serial Line?

CRussellCRussell Posts: 15
edited 2008-12-02 17:37 in BASIC Stamp
Have a project I'm working on that would potentially require me to use up to 4 BS2's at once, each one controlling it's own set of logic, memory, inputs, etc.· Programming the chips independently I can do in the design.· However, the question is, can I wire the serial lines (0/1) to each chip together in parallel (ie all the BS2s see the same serial data coming over the serial port from the computer)?· No chip will be transmitting information at first, they'll only be receiving instructions which they'll be storing in external memory.· I plan on making a flag in the serial data being sent to identify which chip should be listening to the instruction, but the question remains, will the chips function properly if they're all listening to the exact same serial line?· And potentially, if it was setup properly, could they all transmit with SEROUT on the same serial port line if its ensured that no 2 BS2s will be talking at the same time?

Any insight would be greatly appreciated!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-30 17:42
    The programming port lines are setup to be RS-232 compatible. In order for multiple BASIC Stamps to talk on the same serial lines you need to use an Open Baud mode. That could be set up using another I/O pin, but not the programming ports. Besides that, if you tie the programming ports together you also would no longer be able to program any of the BASIC Stamps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • CRussellCRussell Posts: 15
    edited 2008-11-30 17:45
    Ah that's the trick I had in mind. I plan on placing jumpers in the path of the serial port so that I can cut the connection to each BS2 seperately. Not very elegant, but it would allow me to isolate one BS2 to listening on the serial programming line during programming, one at a time. After that, all the jumpers would be reinstated so they would all be listening on the same line for instructions from the program I'll create and thats the step I need confirmation on.
  • CRussellCRussell Posts: 15
    edited 2008-11-30 17:50
    Bah..found what you meant by Open Baud in the documentation. Thank you, that answers the question!
  • CRussellCRussell Posts: 15
    edited 2008-11-30 17:57
    Smile..must learn to think before posting, sigh. If it's setup so that no chip will talk (therefore, no need for SEROUT), and I only use SERIN on the programming line for communications to the chips (I can live without the SEROUT, would be for debugging only), will the original plan still work? I noticed the Open Baud segment only is usable for SEROUT, but not SERIN. Now, on the other hand, if I DID want a SEROUT for some reason, is there any external IC's I need to make this function? I remember something vaguely about the voltages not being kosure when using a pin other then the dedicated programming lines. Is that the case with SEROUT, and therefore, I need an additional IC somewhere to handle that? Sorry for the ring-around of questions, I'm just trying to wrap my head around this more before I start into the schematic much farther.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-30 18:23
    There's a two part Nuts and Volts Column on a multi-Stamp network (columns 55 and 56) www.parallax.com/Resources/NutsVoltsColumns/tabid/272/Default.aspx

    This uses RS485 for the network because it's multi-drop and fairly noise resistant over significant distances.
  • $WMc%$WMc% Posts: 1,884
    edited 2008-12-01 02:42
    AzHole

    Your post will help a lot of other Users understand;What to do. and what not to do.
    I think this is A good thing

    Have You looked at a "ONE WIRE" setup???. This might work for You and it might not.just A thought

    _______________$WMc%______________out____
  • CRussellCRussell Posts: 15
    edited 2008-12-01 05:02
    I'm rethinking the entire setup right now. It became painfully obvious after reviewing more documentation and posts that doing what I had originally intended (tieing all the serial lines in parallel together between the individual BS2s) is a bad, bad idea, which can only lead to small explosions inside the BS2s. There's a better solution to this, and 1 wire is a possibility I'm looking into, as well as a few others. Thank you all for your time thus far.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-01 05:27
    Actually, using open mode with SEROUT and a pullup resistor is a "time honored" way to build a short distance network cheaply. A 1K resistor to +5V at one end of the network or a 2.2K resistor to +5V at each end would work just fine. An RS485 network works better because it's balanced, is more noise resistant, and works reliably over longer distances, but my suggestion here works fine over distances on the order of 20 to 100 feet at speeds up to 9600 Baud.
  • CRussellCRussell Posts: 15
    edited 2008-12-01 05:55
    The distance we're talkin about is more like, 3-4", not feet. The 4 BS2s in question would be housed in the same enclosure as each other, even on the same board. Each one has a specific role to play, but they need to have some minor form of communications in order to get their instructions. Option A was to daisy-chain the signal (ie U1 gets a message, its not for him, he passes it on U2, he checks, nope..pass on to U3..yep its mine, interpret and execute), option B was to simply wire the serial lines all together and each BS2 would get the exact same message at the same time, but only 1 would react to it (the first digit, letter, etc, of the data being sent would be, for instance, 1 2 3 or 4 to specify which BS2 it was intended for). So, technically from what you're saying, I could enact the Open Baud system (as described in the documentation) to get data OUT of them, but do i need to do anything special to get the data INTO them? That's what I'm trying to wrap my head around.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-01 06:41
    The trick with a party line is the sharing. SEROUT in open mode will work for transmitting and SERIN will work for receiving. One Stamp needs to be in charge at any one time. That Stamp can pass on the control to another Stamp with a message. No Stamp should send data unless it is in control or it's been asked to do so by the controlling Stamp (with a command or to acknowledge reception of a command). I suggest that any transmission begin with a "sync" character used nowhere else, like "!" or something like it. Other Stamps use the WAIT prefix to look for this and they use a timeout for error recovery. If the "master" doesn't hear a reply back in some period of time, it resends the command.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-12-01 16:14
    A solution that works to 20 feet will work even better to 4", so that's not a problem.

    The "OpenBaud" mode is designed for a "party line" approach. In other words, you have several BS2's connected to the same party line. This works as long as you never have two BS2's trying to talk at the same time -- if you do, in the OpenBaud mode, they'll 'collide' and the messges will be garbled, but no damage will be done.

    And the "party line" does need a pull-up resistor, since the "OpenBaud" mode implements a "drive low, float high" approach for the I/O pins. This insures you never have two BS2's where one "drives high" while one "drives low", which results in a dead short which can burn out I/O pins.

    Another way to implement this approach is to have a "master" BS2, which has a "talk" party line and a separate "listen" party line. The others are "slave" BS2's, which listen on the 'talk' line, and talk on the 'listen' line. Then it's up to the "Master" BS2 to 'ask' for input from particular 'slave' BS2's, and make sure only one 'slave' BS2 talks at a time.
  • CRussellCRussell Posts: 15
    edited 2008-12-01 16:36
    YES! That's what I've been looking for. The communication system will be pretty simplistic on the party lines but I think it'll do what I want. The PC will broadcast a message down the SERIN party line via the serial port with a character identifying which stamp the message is intended for. If the message is not for a specific stamp, it simply ignores it and waits for the next message. The messages will always be the same length and the same format, so from previous experiments, I should be able to filter those out with the WAIT prefix as you mentioned Mike. When the message is processed, only that stamp will respond with another specified message code on the SEROUT party line. That should, in theory, prevent any 2 stamps from talking at the same time. That should work shouldn't it? And I did think about the master/slave system you mentioned allan, but in this design I think the PC itself will be the master and all the stamps will be the slaves. Should work in the same rough fashion though.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-12-01 21:50
    AzHole -

    If you implement this EXACTLY as you said, I sense there may be a synchronization problem. If there is, I suspect someone here, me included, will have an almost immediate answer for you. We'll wait though to see if it occurs. This is just a forewarning, NOT an assessment of what may actually happen.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2008-12-02 02:02
    AzHole--
    The messages will always be the same length

    How long will they be?

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-12-02 14:30
    Sadly, you can't have the PC being a "master", because the PC doesn't HAVE an 'OpenBaud' mode. In fact, the PC's signalling voltage is like +- 3 to +-10 volts. Now, the BS2 programming port has a couple of transistors to handle this voltage, but none of the I/O pins do. And if you try to 'parallel' more than one BS2 onto the PC's serial line, they absolutly WILL "collide" with each other.

    The typical solution to this dilemma is to have a 'master' BS2 (here we go again) which 'talks' to the PC over its programming port. That BS2 then is the 'master' BS2 for the BS2 "party lines".

    Note "classic" RS-232 ports, as used by the PC, ARE "Point to point" connections, NOT "Party Lines", and can't really be used as "Party Lines".· The BS2 "OpenBaud" approach only works between BS2's, and any other microprocessor that supports "Float-high, drive-low" signalling.· The PC absolutely does NOT support this approach.

    Post Edited (allanlane5) : 12/2/2008 2:35:42 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-02 14:50
    On the other hand, you can easily add a couple of switching transistors to make any RS232 to serial or USB to serial adapter do open mode and thus use a PC for this kind of party line.
  • CRussellCRussell Posts: 15
    edited 2008-12-02 16:11
    Note: Nickname has been changed by request, so it's still me though!

    Thank you Allan. As soon as I posted that and looked at my diagrams the memory of the documentation saying 'Open Buad mode does not work if fpin is 16' came to mind. I kicked myself and quickly went back to reading docs again. Adding the switching transistors as Mike has suggested is an idea, but if I can get away with doing this with less hardware and more software, then that's a solution I can live with (my background is much heavier in software programming, then it is in hardware design). So at this point it looks like the solution will be for the PC to communicate with the first stamp (the new master) and if the message isn't for him, he'll broadcast it along the internal party line on a different pin for the other stamps to chew over. Thats if nothing else goes wrong in my memory. And Bill, the messages will always be 4 bytes in length.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-12-02 17:37
    CRussell, I think your simple scheme as you originally proposed it should work just fine. No need to complicate it.

    The serial input lines (pin 3 on each of the 4 BS2-IC modules) can be tied together and will listen (SERIN) for the incoming 4-byte message from the PC.

    For SEROUT, you can also tie together pin 4 on all 4 of the BS2-ICs. You have to understand how the p16 port is wired in the module. It is intrinsically "open" baud mode, because the transistor that drives the output is in what is called a wired-OR configuration. The wired-OR requires a pulldown resistor and that too is provided inside the BS2-IC, and in this case the 4 pulldown resistors in the 4 BS2-ICs will be in parallel. Not a problem. (The pulldown goes to the serial input, pin 3 on the BS2IC.) You propose to have only one BS2 talking (SEROUT) at a time. Great. Only the one that executes a SEROUT will pull the line high to transmit a signal. If two happen to talk at the same time by mistake, the message will be garbled, but there will be no danger of burning anything out.

    You can either leave ATN open, or tie it to ground, or there might be some other scheme such as multiple reset/wakeup. But as you know, you will have to separate them when you need to reprogram the individual Stamps.

    I've used the this parallel connection of multiple Stamps via p16, and it works fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.