The serial interface is a device that can convert parallel data characters from the CPU into a continuous serial data stream and convert the received serial data stream into parallel data characters for the CPU. The circuit that generally accomplishes this function is called a serial interface circuit.
Serial communication block diagram Serial port communication refers to a communication method between a peripheral device and a computer to transmit data in a bit by data signal line, ground line, control line, and the like. This communication method uses less data lines and can save communication costs in long-distance communication, but its transmission speed is lower than parallel transmission.
The serial port is a very common device communication protocol on a computer. Most computers (excluding laptops) contain two RS-232 based serial ports. The serial port is also a common communication protocol for instrumentation equipment; many GPIB-compatible devices also have an RS-232 port. At the same time, the serial communication protocol can also be used to obtain data of the remote acquisition device.
RS-232 (ANSI/EIA-232 standard) is a serial connection standard on IBM-PC and its compatible machines. Can be used for many purposes, such as connecting a mouse, printer or Modem, but also to industrial instrumentation. For the improvement of driving and wiring, the transmission length or speed of RS-232 in practical applications often exceeds the standard value. RS-232 is limited to point-to-point communication between the PC serial port and the device. The maximum distance for RS-232 serial communication is 50 feet.
1. Baud rate settingSerial communication parameters refer to baud rate, data bits, parity bits, and stop bits. The termio structure is also used when implementing control over the serial port. The following describes how to set these parameters in conjunction with specific code.
2. Data bitThe data bits refer to the number of bits occupied by the actual data in each byte. To modify the data bits can be done by modifying the c_cflag member in the termios structure. CS5, CS6, CS7, and CS8 represent data bits of 5, 6, 7, and 8, respectively. It is worth noting that when setting the data bits, you must first use CSIZE for bit masking. The specific setup code is as follows:
#include //Header file definition
#include
#include "termios.h 》
......
Struct termios opt; /* defines a pointer to the termios structure type opt*/
. .. ..
/ / Get the serial port pointer to the termios structure
Tcgetattr(fd, &Opt);
...
/ / Block other signs
Opt.c_cflag&=~CSIZE;
/ / Modify the data bit to 8bit
Opt.c_cflag |=CS8;
...
/ / Set the modified termios data to the serial port
Tcsetattr(fd,TCANOW,&Opt);
......
3. Parity bitParity can be selected by even parity, odd parity, space, or not. If you want to set to even parity, first set the PA_cflag in the termios structure to set the PARENB flag, and clear the PARODD flag. If you want to set the odd parity, you must set the c_cflag in the termios structure to set the PARENB flag and the PARODD flag. If you do not want to use any checksums, clear the PARENB bit of c_cflag in the termios structure. Table 6.12 shows the specific method for setting the parity.
Table 6.12 Setting the parity bit
Set specific code
No check opt.c_cflag &= ~PARENB;
Odd parity opt.c_cflag |= (PARODD | PARENB);
Even parity opt.c_cflag &= ~ PARENB;
Opt.c_cflag &= ~PARODD;
Space opt.c_cflag &= ~PARENB;
Opt.c_cflag &= ~CSTOPB;
The following gives an example of setting the parity of serial communication to even parity. The specific code is as follows:
#include //Header file definition
#include
#include "termios.h 》
......
Struct termios opt; /* defines a pointer to the termios structure type opt*/
......
/ / Get the serial port pointer to the termios structure
Tcgetattr(fd, &Opt);
...
Opt.c_cflag &= ~ PARENB;
Opt.c_cflag &= ~PARODD;
...
/ / Set the modified termios data to the serial port
Tcsetattr(fd,TCANOW,&Opt);
......
4. Data flow controlData flow control refers to the method used to mark the beginning and end of data transmission. You can choose not to use data flow control, use hardware for flow control, and use software for flow control. The data flow control settings are shown in Table 6.13.
Table 6.13 Data Flow Control Settings
Set specific code
Do not use data flow control opt.c_cflag &= ~CRTSCTS
Hardware opt.c_cflag |= CRTSCTS
Software opt.c_cflag | = IXON|IXOFF|IXANY
Since the hardware flow control requires a correspondingly connected cable, the commonly used flow control method uses software for flow control. The relevant code for setting up control without data flow is given below:
#include //Header file definition
#include
#include "termios.h 》
......
Struct termios opt; /* defines a pointer to the termios structure type opt*/
......
/ / Get the serial port pointer to the termios structure
Tcgetattr(fd, &opt);
...
Opt.c_cflag &= ~CRTSCTS...
/ / Set the modified termios data to the serial port
Tcsetattr(fd,TCANOW,&Opt);
......
HD Mini Projector-1080P high-resolution display, magnify the details and present a clear picture, without any distortion in direct projection. The LED light source system integrates color control to improve the brightness, quality and stability of the picture, and present the real world in front of your eyes.
led home projector 1080p,1080p home cinema projector,wifi 1080p home theater projector
Shenzhen Happybate Trading Co.,LTD , https://www.happybateprojectors.com