RS485 is an alternatve for RS232 for long distances. Maximum length of the cable for RS232 is only 15m. For RS485 it is about 1200m. In addition you can connect many devices to RS485 bus (unlike RS232 — only 2).
Send/receive mode is selected by RTS signal. The converter was designed to be as simple as possible, so it has no some features that can be found in commercial grade products (e.g. galvanic separation).
Popular chip MAX232 is used to convert RS232 signals from/to TTL level. MAX485 converts TTL level signals to RS485 standard. RTS line is used to change transmission mode of MAX485. RTS signal is first converted to TTL level by MAX232 then connected to DE and RE/ pins.
2 LEDs are used to indicate current state of the interface.
If your control system needs to receiving and sending data in the same time you must use full duplex transmission mode. It is possible (and in real world this is the most popular case) that control system first sends request message and than waits for the response. For this kind of systems half duplex communication is sufficient. This interface operates in half duplex mode at it only require 2 wires (full duplex 4 wires) and is simpler to build.
RS485 bus must be terminated on the ends for long lines. By default it is 120Ω resistor. If there are more then 2 devices on the bus, terminator is needed only on the first and last unit. Terminator can be omitted for short lines.
Single layered, size is 63×48mm. PCB artwork, the schematic and part list is available as PDF documents at the end of this article.
After soldering all the elements, power the device. Red LED (LED2) should be bright. Check voltage between pins 15 & 16 of MAX232 and between pins 5 & 8 of MAX485. It should be 5V.
This test is just to prove that some parts of the converter works. It needs only PC computer; another RS485 device is not required at this stage.
Connect your PC computer with converter using RS232 cable. Run Hyperterminal in Windows or any other terminal program, set 9600bps, 8N1 and handshaking None. When you click hook on and hook off icons you should notice change in green LED.
Click hook on icon and type anything in terminal window, the voltage between CON2-1 and CON2-2 should change quickly.
Note You can use any other serial terminal program.
To see if converter works well some data must be properly sent and received. For the real test you need another device with RS485 interface.
If you have two RS485 interfaces you can check interface using simpler method. Just connect two interfaces, run 2 terminal programs and see if one terminal program can receive what you type in the other window. You must remember to switch appropriate send/receive mode for both interfaces (set appropriate state of RTS signal).
When the converter is in TX mode and transmits data you can notice voltage change between A-B pins.
From programmers point of view data transmission through RS485 is the same as serial port transmission. The only difference is that you have to set appropriate state ofRTS line before sending/receiving any data. Because RTS line is very often used in half-duplex converters to switch TX/RX mode, many programs can be used without any modifications.
Transmission modes of converter:
RTS high – you can receive data
RTS low – you can send data
For Win32 API (MS Windows) when you setup serial port set manual control of RTS line in DCB structure.
dcb.fRtsControl = RTS_CONTROL_ENABLE; //manual RTS control & RTS initally high
dcb.fRtsControl = RTS_CONTROL_DISABLE; //manual RTS control & RTS initally low
Before transmission set appropriate RTS state:
To receive data set RTS high: EscapeCommFunction(hSerialPortHandle, SETRTS)
To send data set RTS low: EscapeCommFunction(hSerialPortHandle, CLRRTS);
Green LED indicates the current status of RTS line.