Shop OBEX P1 Docs P2 Docs Learn Events
Networking microprosessors — Parallax Forums

Networking microprosessors

noobydoobnoobydoob Posts: 14
edited 2014-04-29 14:53 in General Discussion
What is the preferred method for networking microprocessors? I'm building a robot with Stamps, Ardunio's, and Raspberry Pi processors, and need to network them. The Raspberry will server as a master. Should I go for async serial, or should I consider SPI, i2c or even other methods? One problem I'm facing is that the Raspberry only has one UART. Can I share the line between all the slaves? How?

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-04-29 00:44
    There are many kinds of networks. What you desire is a bit unclear.

    If you mean connection to the internet, the Raspberry Pi is likely the least expensive internet portal. And it is small enough to be included in a robot. You might even find the means to have a wifi dongle make the internet connection wireless.

    The Raspberry Pi can set up a serial port to link with a BS2, but you would have a lot more power and resources if a Propeller was your microprocessor. If you used Forth on the Propeller (PropForth, Tacyhon, or pfth); the serial interface could be an easy means of real time control and immediate reconfiguration. (Not sure of the status of Forth on an Arduino, but it might be done.)

    Other software for microcontrollers is compile and load, not interactive. I actually prefer having an interpreted language as I can re-program and immediately observe the success or failure of what I have done.

    +++++++++++
    Network in the generic sense can mean a lot of alternatives.

    CANbus is a very useful one for a microcontroller network that is independent of routers and internet portals and such. It just requires a twisted pair of wires that can easily go distances up to 1000 feet without noise problems. But CANbus is a big topic in its own right.
    It uses RS422 async serial.

    +++++++++++
    A wireless small scale network might use asynch serial and XBee technology.

    A wired small scale network (ideal for stations, not roaming robots) could use RS422 for asynch serial full duplex on its own, and avoid the complexity of CANbus packets.
  • Martin_HMartin_H Posts: 4,051
    edited 2014-04-29 03:07
    Yes you can share a line with one master and multiple slaves. The master uses asynchronous to transmit a start byte, a device ID, and then a command byte or bytes. All the slaves listen for the start byte, but only their specific device ID. When a slave hears their device ID they process the command and respond with an acknowledgement. The master waits for the acknowledgement and then transmits the next command.

    This scheme should work pretty well for the Arduino because their UART can receive bytes while they're doing something else. The Stamp can either listen or do work due to its single threaded nature, so keep that in mind. The speed is probably something that you would need to use some trial and error to find, although 9600 is a good guess.
  • noobydoobnoobydoob Posts: 14
    edited 2014-04-29 03:24
    To clarify: The network needs to be async, do to the single-threaded nature of BS2. The network will be wired, not wireless.

    Martin_H: You imply that start byte and device ID are software implemented, right? This is not part of RS232?

    I need to do logic level conversion from 5 to 3.3 volts also, but that's pretty easy with a chip.

    Do I need to worry about using resistors and such when using RS232, or just connect the Rx/Tx lines directly?

    What about flow control? I know BS2 supports hardware flow control, but I doubt Arduino and Raspberry does.

    I am thinking of having a separate control pin pulled high/low for each slave to tell it to transmit data to the master.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-04-29 05:45
    RS232 is really a hardware standard for asynch serial, it is intended to take TTL and convert it to voltage levels that will work over longer wire.

    The BS2 has a TX and RX pin that have an RS232 interface, but many other devices merely provide the TTL signals to be adapted by the user. I believe that is the situation with the Raspberry Pi. I don't know what the Arduino provides.. but I suspect the signals are TTL.

    So you have to be aware of both contexts. The RS232 signals are inverted from what the TTL signals are. You cannot mix by wiring directly the TTL level signals with RS232 level signals as you will damage microprocessor i/o ports by the higher voltages. Even if there is no damage, the processors won't commlunicate as levels will be the opposite of what is expected.

    ++++++
    You can also have TTL asynch serial on other BS2 io pins. There is a big advantage to this as you can use RS485 transceivers which have better noisy immunity and can run one twisted wire pair for everything over much longer distances.

    Or you can go with all RS232 driver chips, such as the MAX3232 (3.3 volt powered) and the MAX232 (5 volt powered).

    ++++++++++
    You will have to create an identity for each processor and have a good idea of which is the Master and all others are slaves. The slaves will listen and wait for an identifying call to take action or to give a reply, otherwise they will remain silent to avoid collisions from having more than one device trying to transmit at the same time.

    It is not hard to do.

    Flow control and parity are not necessary and should be avoided unless you have an obvious need for them. Since the slaves are just listening for an indentifying call, that is all the flow control you need.
  • noobydoobnoobydoob Posts: 14
    edited 2014-04-29 06:33
    Pretty sure I can find libraries for software TTL/CMOS async for both Raspberry and Ardunio, so I can choose pins to use instead of the dedicated UART pins.

    I'm thinking about going TTL async, and using a separate pin on each slave that is pulled high to tell it to transmit to the master.Then I can share the lines between all the slaves.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-04-29 07:15
    There is a pair (#55 & 56) of Nuts and Volts Columns on networking multiple Stamps together. There's nothing magic about connecting an RS485 transceiver to a Stamp. You'd use a half-duplex connection (see Figure 5 here). DI is the I/O pin you're using for transmitting (SEROUT) and RO is the I/O pin you're using for receiving (SERIN). /RE would be connected to ground so the receiver is always on and DE would be controlled by another I/O pin (high to transmit, low to receive). Look at other application notes and datasheets for Maxim's RS485 devices for more examples and suggestions.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-04-29 07:23
    I guess what you are saying is that you want to connect everything together at the TTL/CMOS levels. It will work fine over short distances, inches as opposed to feet.

    If you wanted to use RS485, you need one at each end.

    Here is one device that is available (these come in 3.3v and 5.00v chips depending on your power source.

    The sn75179 chip requires two twisted pairs, but there are other transceiver chips in 8 pin dip that require only one twisted pair in a Master/Slave setup... a kind of two-wire party line.

    http://www.omega.com/techref/das/rs-232-422-485.html
    1000 x 1390 - 310K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-04-29 07:35
    If you are only running several feet (even 20ft) you can do it at logic levels, you only need RS485 if you are connecting across noisy environment or longer distances. Also there is no need for full duplex, it's a complete waste which also means that you only need a single I/O line both for transmit and receive. If you do use RS485 then that would make it two I/O altogether as you need one to switch the TE/RE.

    My guess is that logic level is all you need but I would also use a series resistor from the I/O line just for a little current limiting in case of a bus conflict and also so that 3.3V logic can handle 5V signals. On the software side you can keep it very simple by using async and transmitting "select codes" which is just another way of addressing slaves. That way you can transmit data normally to the slaves but you just select beforehand which ones should listen up. All slaves should always interpret these select codes which include deselect and broadcast codes etc. It really is quite simple as long as you keep it simple. This assumes that you are not trying to transmit 8-bit binary data but even if you were there are simple mechanisms such as character gaps etc to help validate select codes.
  • noobydoobnoobydoob Posts: 14
    edited 2014-04-29 09:04
    Nice approach! Although I'm going for a proper TTL/CMOS level shifter. Call me paranoid.

    What is the purpose of deselect? After a slave is selected, it will transmit it's data, then start listening again (going into deselected mode automagically).
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-04-29 09:39
    The select/deselect allows the RS485 transciever to switch between recieve and transmit. Yes, it allows you to use only one twisted pair.
    I had overlooked this as a 'flow control issue'. You can just code an i/o pin to default to recieve except when you desire to send. You do this select first whenever you want to send a message and release it when finished.

    With RS422, you have NO select and two twisted pairs... full duplex.

    " A proper TTL/CMOS Level shiffer' is either RS422 or RS485. RS232 is an archaic junk level shift that costs more in chip form, requires more to wire up, and doesn't work anywhere near as well. But the perception is that it is what one is supposed to use.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-04-29 09:45
    noobydoob wrote: »
    Nice approach! Although I'm going for a proper TTL/CMOS level shifter. Call me paranoid.

    What is the purpose of deselect? After a slave is selected, it will transmit it's data, then start listening again (going into deselected mode automagically).

    Proper TTL/CMOS level shifter???? IMO most of these "propers" and "just to be safe" measures are a load of nonsense. If you know what you are doing then very rarely would you ever need these shifters. Being paranoid is no excuse, the more parts you have, the more things that can wrong, so don't put parts in that don't need to be there, simple.

    The Stamp has TTL level inputs which means it accepts anything that is 2V or more as a high so therefore a 3.3V from the Prop will do just fine whereas a 5V from a Stamp will go through the current limit resistor no problem, whereas the RPi's I/O is 3.3V too.

    The deselect is if you are in multiple select mode where you can broadcast to a group all at once but just remember these codes are just a bit of a guide, your implementation depends upon your needs.

    Sometimes if you need to make sure a message got through you can also use the simple "repeat n times always" format that does not need acks and naks but simply sends a code to indicate the start of a message, and a sequential message number, an optional data count and then the message and checksum/CRC. Any receiver that finds an error simply rejects the message and hopefully gets a good message after which it rejects any more messages if they have the same message number. This method works well for broadcasts to multiple slaves, it's one I used in high-rise lift displays many many years ago using RS485 over miles of non-twisted pair fire proof cable (ran it at 19.2k baud).

    But try to keep it simple and funtional, at least first off, then you can see if you need to do more.

    BTW, if you do use RS485 then make sure you add a pull-down resistor from TE/RE to ground as this will keep the transciever in receive mode even during power-up etc until you tell it to transmit. RS422 is not multidrop and not recommended whereas RS485 can disconnect it's transmitter from the bus etc.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-29 10:45
    The Stamp has TTL level inputs which means it accepts anything that is 2V or more as a high so therefore a 3.3V from the Prop will do just fine whereas a 5V from a Stamp will go through the current limit resistor no problem, whereas the RPi's I/O is 3.3V too.

    I know the Prop can handle 5V with a series resistor but I don't think the RPi is 5V tolerant. I think a nonsensical level shifter might be in order. :smile:

    BTW, No mention of a Prop in the original question (which of course is a shame).
  • Martin_HMartin_H Posts: 4,051
    edited 2014-04-29 12:14
    noobydoob wrote: »
    Martin_H: You imply that start byte and device ID are software implemented, right? This is not part of RS232?

    In networking you separate the media from the protocol. RS232 is a media through which information is transmitted. The start byte and device ID are part of the software implemented protocol.
    noobydoob wrote: »
    I need to do logic level conversion from 5 to 3.3 volts also, but that's pretty easy with a chip.

    If you directly connect the pins together you definitely need to protect the 3.3 volt devices from 5 volts. You can buy a level shifter (SparkFun sells them), or build one from a voltage divider. 5 volt devices can usually handle 3.3 volt logic signals.
    noobydoob wrote: »
    Do I need to worry about using resistors and such when using RS232, or just connect the Rx/Tx lines directly?

    RS232 is a media type. You would use line drivers to boost the chips TTL levels to the RS232 voltages. As others have said I would probably use TTL rather than RS232.
    noobydoob wrote: »
    What about flow control? I know BS2 supports hardware flow control, but I doubt Arduino and Raspberry does.

    Good question. The protocol I described has the master transmit while slaves listens, followed by master listening while the slave processes and then acknowledges. It has flow control built in. There are schemes such as I2C which use the pattern I described.
  • noobydoobnoobydoob Posts: 14
    edited 2014-04-29 14:53
    Thanks for great advice, Peter. I like simplicity. I think I read somewhere that you need to protect the Raspberry pins from 5V, and I take no chances. Three days ago I burnt a BS2px, one 74HC595, a DS1302, and 10 PING sensors!!! by accidentially putting 12V to Vin. So yes, I'm paranoid, and if that makes me solder for an hour, so be it. I like soldering!
Sign In or Register to comment.