RS232 is full-duplex communication, when the data is sent, you can also receive data, but you may feel unclear, such as in the application, you go to the operation of the serial port writing, you do not feel able to read the serial port data, because the CPU is a single core, CPU only one brain, Only one person is working, so you will feel you to operate the serial port write, you can not read the serial number of the data, because the instruction is a run, only one person at work. But RS232 is full duplex, When the data is sent, it can receive data, which can be reflected in the hardware, if you do not feel in the application, in the application you go to operate the serial port to send data, At the same time, the other side like you to send data, although you can not read this data in the application at the same time, but in the hardware, the data sent to the other side has been read into the hardware of the serial port reading buffer. When the application serial port after the end of the operation, to read the serial port data, will be from the hardware serial port of the buffer you sent at the same time the other side of the data sent, and the other side of the data sent over, read to. This is RS232. Full-duplex embodiment, embodied in the application and hardware.
RS485 is half-duplex communication, when the data is sent, is not read data, in the data to read data, is not send data, this is reflected in the software, is when you send data, before you send data to the RS485 can be sent to the data of the pin to pull high or low, To switch the state to the status of the outgoing data, because RS485 is half-duplex, so the read state and the state to distinguish, so there is a RS485 send and receive status of the pin, with a pull-up or pull-down representation. When you send the data, pull up or pull down the pin, and then you call the Write function to carry out the serial port of the data, after the use of this function, you have to remember to delay a period of time, in going to pull the pin high or pull down to switch to RS485 read state, because if your data is not all sent through the serial port, You are in the hardware of the write buffer, the data is still sent, but in the application, your write function has returned, but you will RS485 pin switch to read state, at the hardware level, found that 485 is read state, will be switched to 485 read mode, And your data in the hardware buffer, even if not sent to complete, because the hardware has been blocked this road. So when you call out the serial port write function, must delay after a period of time in going to pull the pin high or pull down to switch to 485 read state, this delay time, is based on how much data you want to send, that is, the length of the data and the baud rate of the serial port and the data in the media when the transmission of the check bit and Because if it contains a stop in the check bit, your data length will be on the two bits, because you send the data area is sent, length is the length of the data area you send, but in the transmission of the media, there may be other bits exist, you have to consider in. Then, according to the actual length of the transmission and the current serial port baud rate, to calculate the time delay. After each call to write the serial function after the time to delay, in the go to pull the pin high or pull down to switch to read state. Prevent the data is not sent, you will not let him send, and this delay time also can not be arbitrarily long, because you may be in the delay of so long interval, the other party has sent you the data, but you still for the status, and can't read the data he sent you at this time, which is why, This delay time to get the actual data sent includes whether to consider the stop bit check, and the baud rate to calculate the reason.