1
\$\begingroup\$

I am working on an application where I have part of an embedded linux system transferring some data to a PC utilizing PySerial (a Python module). My question is: is there an alternative to finding a PC with an RS232 connector in order to establish two way communication between the PC and embedded system? Thanks.

\$\endgroup\$
  • 1
    \$\begingroup\$ Other than a USB-UART bridge? \$\endgroup\$ – Ignacio Vazquez-Abrams Aug 30 '17 at 17:18
  • \$\begingroup\$ Does the embedded Linux device have a device or OTG USB port? \$\endgroup\$ – filo Aug 30 '17 at 19:22
  • \$\begingroup\$ Do both devices have Ethernet? You could run a DCHP server on the Linux device. For example "apt-get install isc-dhcp-server" if using Debian. \$\endgroup\$ – Vince Patron Aug 31 '17 at 5:43
2
\$\begingroup\$

A USB-Serial adapter will do what you want, they're available and cheap. However they will most likely come with a RS232 SUB-D connector and output RS232 voltage levels, which then need conversion.

You can also find USB-Serial cables with pin headers and nice easy 3.3V levels, much simpler to use in your application.

EDIT

So you want to link your two devices via USB. Since you say the embedded device uses Linux, it must have Python. Depending on throughput and complexity, there are many solutions..

  • If your embedded board has Ethernet... just use that!
  • Two USB-Serial adapters back to back (speed is limited though)
  • The "USB to USB file transfer cable" which actually emulates an Ethernet port for each USB ports, so both devices are networked together.
  • Program the embedded board to act as a USB device, there are libraries to do this on Linux, I tried to google a bit and found this and this for example.

I've programmed a USB device on a Cortex-M4, it isn't rocket science but it does take a while. So if you need lowest possible cost, this would be the best, as all you need is a cable. If this is a one-off or personal project, I'd rather recommend the other solutions.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks for your reply, peufeu; I have used USB-Serial adapters in past projects but am having a hard time figuring out whether or not the proposed arrangement will work for some reason. Because the only available ports on both ends are USB ports, would I need a mixture of USB-Serial cables (one coming out from the embedded system and one going into the PC)? \$\endgroup\$ – NewToArduino Aug 30 '17 at 17:53
  • \$\begingroup\$ OK, i hadn't got that you had only USB on both ends. See edit ;) \$\endgroup\$ – peufeu Aug 30 '17 at 19:20
  • \$\begingroup\$ You would need to connect the two USB-to-RS232 adapters through a "null modem" cable so that the TX of one goes to the RX of the other. It also routes the handshaking signals, e.g. RTS (request to send) routes to CTS (clear to send), etc. I can flesh out an alternate answer but lots of articles on Google I'm sure. \$\endgroup\$ – Vince Patron Aug 31 '17 at 5:50
  • \$\begingroup\$ Also OP needs to specify the bandwidth required. \$\endgroup\$ – peufeu Aug 31 '17 at 13:08
  • \$\begingroup\$ Hey Vince, I wanted to know if you could help expand on the answer that you gave. Here is a link to two cables I am thinking about purchasing based on your answer: amazon.com/StarTech-com-USB-Serial-Adapter-Modem/dp/B008634VJY To clarify, I am considering purchasing one "Null Modem" and one "DB9" cable to complete this project. Does this look correct? \$\endgroup\$ – NewToArduino Aug 31 '17 at 14:00
0
\$\begingroup\$

@peufeu is on the right track with using two USB-to-Serial adapters. But there's a very important thing missing: You will need a "null modem" adapter between them.

For a particular connector type (either 9-pin or 25-pin) there are two types of RS-232 wiring: "DTE" (Data Terminal Equipment) which is typically a PC, and "DCE" (Data Communications Equipment) which can be a telephone modem or similar gear. (If you're young you'll say what the heck is a telephone modem!)

So a DTE (PC) will transmit data on pin 3 and receive data on pin 2, while a DCE (modem) receives data on pin 3 and transmits on pin 2.

The problem is the USB-to-Serial adapter is typically wired as a DTE so if you just wire them straight, they both try to send data to the same pin 3 and receive on the same pin 2.

So a null modem is either a cable or back-to-back connectors where the RX and TX pins are swapped around so they transmit and receive data on the correct pins.

Additionally, the handshaking pins are swapped around so they appear correct.

So, bottom line, it makes the DTE on the other side look just like a DCE and the two computers can talk to each other and handshake works correctly.

Here's an image from Wikipedia that helps visualize what's going on:

The full entry is here: https://en.wikipedia.org/wiki/Null_modem

You can cut off the connectors and wire them together yourself. The bare minimum setup would be to ignore all the handshaking lines and just connect 3 wires: wire GND pin 5 together, and wire pins 2 and 3 swapped (2 of one goes to 3 of the other and vice versa). That's it.

Here's a snippet of handshaking: The DTE raises RTS (request to send) high and the modem if it is ready to get data should raise CTS (clear to send) high. When the modem is busy and cannot accept data at the time it lowers CTS.

So in the minimum setup none of those wires are connected so you'd have to disable handshaking in your SW and assume the other guy is ready to receive whenever you transmit.

Null Modem wiring from Wikipedia

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.