You take the red pill, you stay in Wonderland, and I show you how deep the rabbit hole goes.
The Matrix – 1999
Morpheus’ speech was a turning point for both Neo and the movie Matrix and that is the case in regard to RS-232, the red pill. It will give you the understanding and ability to control many thousands of devices which implement this serial interface.
RS-232 is a standard communication protocol for linking computer and its peripheral devices to allow serial data exchange. The standard defined voltage levels that made it immune to noise disturbances and reduced the errors in data exchange.
The standard definition by EIA to define RS-232 as “an interface b/w Data terminal equipment (DTE) and Data communication equipment (DCE).
A typical RS-232 system:
What is RS-232?
- Serial data transmission from point-to-point.
- Generally called COM ports in PC terms.
- Data may be in raw (binary) form or converted to ASCII.
- Normally only 2 devices are present – 1 transmitter and 1 receiver.
- Messages may contain multiple bytes.
- Message formatting and error correction is application specific.
- Data rates are defined in bits per seconds (baud).
Common Aapplications
- Connecting a device with an RS-232 control options.
- Connecting to a scanner, copier, fax modem or other serial devices.
Accessories
- You will need a USB-to-Serial adapter (plug USB side to laptop)
- Serial Cable (e.g. Db-9, null modem cable)
Serial
Term serial means the data is sent 1-bit at a time. Sending more than 1-bit at a time is called parallel. RS-232 is a specific serial protocol that defines the wiring and flow control used to send these data bits.
Wiring
We start with two pieces of equipment that needs to communicate with each other. To keep this simple, lets say one only send and the other only receive, in reality both sides send and receive but if you understand how the communication work in one-direction, you can apply it to both.
- Data is generated by the sender, which puts it in a send buffer, which temporarily holds the data.
- To get the data from sender buffer to the buffer on receiver we need a wire. On the sender side this is the transmit data or Tx wire. On the receiver end this is the receive data or Rx wire.
- Once these are connected together the data can flow from sender to receiver, this is the simplest case.
DTR & DSR – How the sender knows receiver is there?
RS-232 designers added a control wire which tells the sender that receiver is there. On sender side this called Data Terminal Ready (DTR), on the receiver end this is called Data Set Ready (DSR). When these are connected and proper voltage is set by receiver, the sender knows the receiver is there and data can safely flow.
RTS & CTS – What if sender send data too fast?
How fast the data is sent is called the baud rate. if the baud-rate is so high that the receiver can not get the data out of its buffer fast enough, the buffer overflow and data is lost.
To counter this, designers added another control wire, so the sender and receiver can coordinate when to send the data.
On the sender side this is Request to send (RTS). On the receiver side this is called Clear to send (CTS). With this additional wire the receiver can tell the sender when its need to pause and buffer over-run can be avoided. Using the send/stop signal is called hardware flow control. This RTS, CTS wire is hardware that controls when data flows between devices.
NULL Modem
When we loop the control wires from the sender side to the receiver side on the same device, device will tell itself that things are ready to go even when there is no modem. With the null modem we are back at the basic case and we only need to connect the transmit (Tx) and receieve (Rx) between two devices to transfer data. To be technically accurate, we also need a ground wire (Sg) to establish where the signal voltages are references from.
This arragement is called three-wire null modem. This means the functions that the control wires handle, making sure there is a device on both ends and the receiver is ready to receive the data sent are no longer being done. So another enterprising person figured out that you could perform the same flow control function by sending special packets of data over the transmit and receive lines. Using special packets (XON, XOFF) to control when the data is sent is called software flow control and the packets themselves are XON and XOFF.
When the receiver is ready for data, it sends an XON when it needs the sender to stop it sends an XOFF. this is less reliable than hardware flow control but its often work well enough to be worthwhile.
So, this was an introduction of RS-232, its a simple but very popular communication protocol. In upcoming post, I will try to build on top of this knowledge. I will also suggest to check the links in references for more details. Till next time, Happy Coding.
References
- https://www.engineersgarage.com/article_page/rs232-basics-implementation-specification/
- https://learn.sparkfun.com/tutorials/serial-communication/all
- https://www.youtube.com/watch?v=XVEnxipCIJ0
Discover more from Hex Quote
Subscribe to get the latest posts sent to your email.