Both sides previous revisionPrevious revisionNext revision | Previous revision |
en:examples:communication:rs232 [2010/03/29 19:30] – Helen | en:examples:communication:rs232 [2020/07/20 09:00] (current) – external edit 127.0.0.1 |
---|
| <pagebreak> |
====== RS-232 ====== | ====== RS-232 ====== |
| |
//Vajalikud teadmised: [HW] [[en:hardware:homelab:controller]], [AVR] [[en:avr:usart]], [LIB] [[en:software:homelab:library:usart]], [LIB] [[en:software:homelab:library:module:lcd_alphanumeric]]// | //Necessary knowledge: [HW] [[en:hardware:homelab:controller]], [AVR] [[en:avr:usart]], [LIB] [[en:software:homelab:library:usart]], [LIB] [[en:software:homelab:library:module:lcd_alphanumeric]]// |
| |
===== Teooria ===== | ===== Theory ===== |
| |
[{{ :examples:communication:comm_rs232_cable.jpg?220|Cable RS-232. Left plug is „male” and the right one is „female” plug."}}] | [{{ :examples:communication:comm_rs232_cable.jpg?220|Cable RS-232. Left plug is „male” and the right one is „female” plug."}}] |
| |
UART means universal asynchronous receiver/transmitter. USART is almost the same, with the difference that the data is sent with clock signal. The UART may be called also a serial interface. The serial interface is a data transferring mechanism, where each bit is transmitted one by one. For example, to transmit 1 bait, 8 bits are transmitted with certain interval. This means that on the serial interface line, which is one pin of the microcontroller, the value of voltage is changed after certain time, once low and then high. Usually there are two devices connected to the serial interface. One is transmitting the information (by changing the value of the pin) and the other is receiving it (by registering the value of the pin). Transmitting pin is TX, and receiving pin is RX. The info is moving always to one direction on one line. For sending data to the other direction an other line is used. If data is moved on two lines at the same time, it is called full duplex bus. | UART means universal asynchronous receiver/transmitter. USART is almost the same, with the difference that the data is sent with clock signal. The UART may be called also a serial interface. The serial interface is a data transferring mechanism, where each bit is transmitted one by one. For example, to transmit 1 bait, 8 bits are transmitted with certain interval. This means that on the serial interface line, which is one pin of the microcontroller, the value of voltage is changed after certain time, once low and then high. Usually there are two devices connected to the serial interface. One is transmitting the information (by changing the value of the pin) and the other is receiving it (by registering the value of the pin). Transmitting pin is TX, and receiving pin is RX. The info is moving always to one direction on one line. For sending data to the other direction an other line is used. If data is moved on two lines at the same time, it is called full duplex bus. |
| |
| |
[{{ :examples:communication:comm_uart_frame.png?319|the frame of UART, where S is start-bit , 0-7 are data-bits, P is parity-bit (if existing) and T is stop-bit (or 2).}}] | [{{ :examples:communication:comm_uart_frame.png?319|the frame of UART, where S is start-bit , 0-7 are data-bits, P is parity-bit (if existing) and T is stop-bit (or 2).}}] |
| |
Furthermore, it is worth to know that the RS-232 standard includes in addition to the data-signals (RX, TX) also data flow control pins DTR, DCD, DSR, RI, RTS and CTS, which are used for controlling the communication between the devices. For example they can be used to notify whether it is ready to receive data or not. Since the RS-232 interface’s original goal is to connect the computers to a modem, some signals are (were) useful rather for showing the state of the telephone lines. | Furthermore, it is worth to know that the RS-232 standard includes in addition to the data-signals (RX, TX) also data flow control pins DTR, DCD, DSR, RI, RTS and CTS, which are used for controlling the communication between the devices. For example they can be used to notify whether it is ready to receive data or not. Since the RS-232 interface’s original goal is to connect the computers to a modem, some signals are (were) useful rather for showing the state of the telephone lines. |
| |
| |
===== Practice ===== | ===== Practice ===== |
| |
On the board of the controller module of the Home Lab is one RS-232 type male plug. Through that can controller be connected to computer or to an other controller. For connecting to a computer a usual not inverted cable must be used, which one end is male and other one is female. For connection to an other controller a cable must be used where RX and TX and current control signals are perpendicularly inverted and both plugs are female. The inverted cable is also called zero modem cable. The following is an example program of using UART serial interface. When the program is started, it transmits a welcome through a RS-232 interface and displays messages, which are received. LCD and USART libraries are used. | The Controller module board is equipped with one RS-232 type male plug. Through that can controller be connected to computer or to an other controller. For connecting to a computer a usual not inverted cable must be used, which one end is male and other one is female. For connection to an other controller a cable must be used where RX and TX and current control signals are perpendicularly inverted and both plugs are female. The inverted cable is also called zero modem cable. The following is an example program of using UART serial interface. When the program is started, it transmits a welcome through a RS-232 interface and displays messages, which are received. LCD and USART libraries are used. |
| |
<code c> | <code c> |
// | // |
// Connecting the controller module of the Home Lab to a computer through RS-232. | // Connecting the Controller module of the HomeLab to a computer through RS-232. |
// The example is using digital input-output module with LCD. | // The example is using digital input-output module with LCD. |
// The text inserted in the terminal of the computer is displayed on the LCD. | // The text inserted in the terminal of the computer is displayed on the LCD. |