Making RS232 work: On this page are several rules that make using RS232 a simple task. These simple rules will ensure your RS232 system works easily.
I have been using RS232 for years and it always flies along and is always reliable but there are some simple rules to follow otherwise you can get in big mess.
Jump to Rule 1 : Keep it
Jump to Rule 2 : Use a straight through cable.
Jump to Rule 3 : Make cross over at dev. board.
Jump to Rule 4 : Set RS232 Identical at each end.
Jump to Rule 5 : Re-check connections at both ends.
Extra: Other reasons RS232 may not work.
Jump to Setting up Tera Term. (Serial program running on the PC that uses a serial port)
RS232 can actually work well but a lot of software
the handshake signals to be in place and this is why it can be so
miss one out or connect a single wire wrongly or setup the software
incorrectly and it will just sit there doing
absolutely nothing.It is best to start from a simple setup and progress
to a more complex one gradually checking as you go that each part is
RS232 is only difficult if you try to use all the facilities that the standard provides. You really don't need to consider all the signals when using RS232 on the bench (for simple communication between your hardware and a PC) i.e. to make RS232 work over a few metres.
If you want to make RS232 work over long distances then you must use all the signals including handshake signals as these ensure correct operation. For 1-3 metres I only ever use the following:
These work for speeds of 9600 baud and beyond. You can test how far beyond by experimenting with the settings in the PIC program and PC software.
This is a cable where pin 1 connects to pin 1 at the other end, pin 2 connects to pin 2 at the other end etc.
There are two cable types:
Note: Signals that are crossed over for a null modem cable are (TX,RX) and handshaking signals (RTS,CTS) and (DSR,DTR).
If you don't know what cable type you have then use a multimeter to test on its buzz setting. To make sure you don't drop everything on the floor stick a piece of wire in the female connector and wrap the other end of the wire around the multimeter probe - then you can concentrate on probing the pin in the male connector. To keep things simple use a straight through cable.
Note: Serial cables are never marked as null modem or modem - they all look the same!
The key to getting an RS232 system to work is knowing exactly what cable you have and its pin connections. Using a straight through cable you don't need to worry about Modem / Null modem cables and this eliminates a source of confusion.
You can not make the crossover at the PC end as you just plug the serial cable into the PC - and that's fine. At this point you have direct connections from the Serial connector at the back of the PC all the way to your development board.
So you know exactly where you are - all connections to the development board are straight through from the PC. The final step is to make the cross over on the board.
The schematic below shows a development board with a serial connection to/from the PC that lets RS232 work between a microcontroller and the PC.
I have labeled the serial connector with the connections located at the PC - this makes it easier to visualize the whole system.
You can think of the PC and cable as one unit connecting directly to the development board and you do not need to worry about null modem cables, crossover cables, gender changers, cross over boxes etc. You only need to concentrate on the schematic with the PC serial port as an extension of the schematic.
All you do next is to connect the serial connector labeled TX (which is the serial input to the development board from the PC) to the receiver on your development board (labeled R1IN). Similarly connect T1OUT (which is the serial output from the development board) to the PC Serial port labeled RX. This makes the cross-over on your board. Next connect the grounds together (GND and 0 volts).
In each program there will be a setting that defines the usage of the bits transmitted between the PC and the microcontroller. To make RS232 work these settings must be identical. As a starting point use the following settings at each end.
|Bits per second (BAUD)||9600|
|Number of bits||8|
If you want to change anything just change one thing at a time but again keep the same value(s) in both bits of software.
These settings are standard settings.
A big source of confusion in making RS232 work is the connector gender (male or female). Usually a pcb designer is given a diagram that does not specify the gender of the part - and uses the one that was used last time. When it comes to building the board the connections are mirrored (male and female connectors are mirrors of each other) and you have to hand wire the connection.
To ensure that this does not happen always lay out all the parts before finishing the schematic so that you ensure the correct gender of connections from one end of the system to the other.
After your PCB designer has laid out the board print out the PCB design (or for multi-layer boards sit down and use the PCB tool with the designer) view the design only from the top of the chip (it could be on the reverse side) and trace each signal wire to the connector to ensure that the connector is wired correctly. Physically use a "real" connector and examine where the signal comes out of the connector. This way you can ensure that the signals are in the right place.
Getting the gender of the connections is essential so double
and even triple check the parts so that you know in your head which way to
connect up the system.
For older versions of Windows such as XP, Windows came pre-loaded with a serial communications program called Hyperterminal. Since modern computers don't have serial ports anymore you'll have to download a Serial Terminal program yourself!
Tera Term is an open source terminal emulation program that works on Windows and is actively supported.
To run it type Tera Term at the start prompt and click "Tera Term"
You will be presented with a black screen so all you need to do next is setup the comms parameters as described above.
To do this select Menu: Setup-->Serial Port and choose the following parameters adjusting for the COM port in use:
Note: the delay settings that you can use if your receiving system is slow.
If you are writing code on the PC the serial ports are really fussy about what connections are made to the serial port and require looped back signals unless care is taken to program the chips in the PC so that they do not require loop backed signals. It is best just to use known working programs such as Tera Term.
Note: Loop back means faking the signals at one end - DTS is connected to RTS and DTR is connected to DSR (at the same end) - sometimes you need to control CD as well.
Another reason for RS232 not to work is if you use equipment that is powered by the serial port. Laptops are optimized for power saving so they give out the minimum power (lower volts and current).
Another possibility for RS232 not to work is voltage level sensing. Levels detected by the serial chip in the PC may not allow detection of the signal.
Newer serial port chip in the PC detect voltages below 3V (and above -3V) as a 'one' but older chips will not report it since the RS232 standard defines this voltage range as undetermined. For these older chips the voltage for a 'one' (mark) must be lower than -3V and for a 'zero' (space) must be higher than 3V. The ±3V indeterminate area gives the RS232 system immunity to noise and this allows the system to work in an electrically noisy environment but sacrificing the noise immunity means that it is easier to interface using standard CMOS logic levels (0,5V).
The only way to find out if your system works with (0,5V) logic levels is to test it - which is a pain (and what if you change it later). So it is just much easier to use a level translator chip such as a MAX232.
So does RS232 work ? - If you follow these guidelines then RS232 will work.
How to use the BMP280 for weather pressure measurement or altitude change detection.
How to use the TCS230 (/TCS3200) Color detector chip and easily add it to any of your projects.
How to use MC78M05BDTRKG for maximum current without using too large a heatsink pad and how to select the optimum input voltage.
How to use fixed point maths to save microcontroller memory by avoiding use of the floating point library.
Essential Guide to the DHT22/11 humidity sensor with library code guide and Full Arduino Tutorial. Learn how to Easily determine Humidity, Dew point and Heat Index.
I2C tutorial: Learn all about the 2 wire I2C serial protocol. Learn how easy it is to use, how it works and when to use it...