Connecting Arduino directly to the serial port of an old PC (not USB)

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry about making yet another post about UART communication.

 

I'm trying to send a single character from my Arduino Uno to my PC using UART.

 

I'm not using a USB to Serial converter and instead i've connected the TX pin of my Arduino directly to RX port of my old PC's serial port like this:

https://www.virtual-serial-port....

Ground of Arduino is also connected to the gourd of serial PC port, I' have left out the RX pin on Arduino for now.

 

The code is pretty much copied from the datasheet, let me know if you need to see i.

(I'm not using Arduino dev toolset, i'm just using avr-gcc, refer to this post: https://www.avrfreaks.net/forum/...)

 

On my PC i'm trying to read the channel with screen:

screen /dev/ttyS0 115200

Same baud rate is used in my code:

#define USART_BAUDRATE  115200

I have read there are voltage differences between TTL UART on MCUs and 16550 UART on my old PC. Is that why I get garbage results? am I lucky the board isn't fried?

Or is this setup correct and my code could be wrong?

 

I have used various baud rates, different codes from googling, but I keep seeing garbage.

This topic has a solution.
Last Edited: Thu. Jan 20, 2022 - 04:09 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Welcome to AVRFreaks!

RS-232 voltage levels are +- 9v to +-15v, connecting that directly to your PC serial port will blow up your UNO as it's expecting only +5v - 0v!!!

Serial comms idle high, so for your UNO's ttl level that is VCC or 5v, while a high for RS-232 is -volts, so the signal is inverted as well as way out of range....

You will need a RS-232 to TTL serial adapter between your PC and your micro.    Other then that, it should just work!

 

So go buy another UNO and an RS-232 shield and you can try again.

 

Jim

edit: added link to shield

https://www.dfrobot.com/product-...

or similar

 

FF = PI > S.E.T

 

Last Edited: Thu. Jan 20, 2022 - 04:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avruser1523 wrote:
I have used various baud rates, different codes from googling, but I keep seeing garbage.

And you will continue to see garbage until you use a RS-232 interface converter. The chip-of-the-day was MAX232 but there are modern equivalents.

 

BTW: Don't connect TX from the PC directly to Arduino or the magic smoke will be released.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
connecting that directly to your PC serial port will blow up your UNO

Welp I knew something was wrong :D

 

Fortunately I didn't connect the Tx port from PC to Uno so I think it should be fine?! it's still working.

 

@N.Winterbottom I haven't encountered the magic smoke yet.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Once you have the correct interface, then you can have all the fun of finding out about DTE (Data Terminal Equipment, terminals, pc's etc) and DCE (Data Carrier Equipment,modems,pc's emulating modems, etc) and how to make the combination of

DTE <-> DTE  connections vs

DTE <-> DCE or

DCE <-> DCE work, using modem cables, or null modem cables, male/female vs male/male vs female/female cables, adapters, gender changers, etc.....   Lots of fun back in the day!

That's why we all use USB to ttl cables now and skip all the RS-232 stuff unless we need to talk to legacy equipment.

 

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tutorial here on RS232: https://www.sparkfun.com/tutorials/215

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Once you get the RS232 voltage levels that are coming out of your PC's Serial port to the levels of your AVR, then switch your lines so that the RX of the PC serial port goes to the TX of the AVR UART, (and TX from the PC goes to RX of the AVR).

 

The serial port of the PC puts out -9 to -15 volts  in serial-port idle mode (logic high__no data being sent), and +9 to +15 for logic low.  This is a legacy from 50 years ago called the RS232 standard.  A chip of the family called the MAX232 was the most common way to convert RS232 to normal logic that went into the peripheral's UART.    The AVR does have internal diodes on the UART pins that *MAY* have protected your AVR chip from the RS232 levels put out by the PC, especially since the RX of the PC was not connected to the AVR UART.  But the PC will not receive data correctly from the AVR.

 

Modern USB ports use normal (+5 to 3.3V) non-inverted logic for data transmission.  In USB, the two signal lines are bidirectional, have always opposing logic values (when one line is high, the other is low), and are designed to work much faster than serial ports based on UARTs.   Modern PC/USB-to-serial devices use the 25-cent CH340 chip instead of the $15 FTDI chip, which does the same thing. But USB-to-serial devices are still called "FTDIs" and sell for a dollar or two on eBay.  I recommend that you get a few and use them instead of the PC serial port.  The PC serial port is really only good for specialized equipment from the 1980s and 90s that use the RS232 standard and still need to be in service.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
I recommend that you get a few and use them instead of the PC serial port.  

+1

 

I really don't see any benefit in fighting to get RS232 working.

 

Unless this "old PC" is so very, very old that it has no USB ?!  surprise

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...