STM32 serial port realizes the principle of 485 dual-computer communication

RS485 communication must be known to everyone, when learning RS232, will take 485 (RS485 instead of 485 instead) and compare it. The advantages and disadvantages of 485 are not mentioned, there are online.

I am using the 485 communication of STM32 library function, so let's talk about the principle of STM32 serial port to realize 485 dual-machine communication:

Both 485 and 232 are based on the serial port communication interface, which is consistent in the data transmission and reception operations. But his two communication modes are very different ~! 232 is full duplex (example: A-> B simultaneous B-> A, instantaneous synchronization) working mode, and 485 is half-duplex (can not receive when receiving, close Can not send) work mode. In 232 communication, the host can receive the data sent by the slave while transmitting the data; however, in the 485 communication, the transceiver should perform the mode bit switching, for example, when sending data, the mode is set to '1'. , which is indicated as the transmission mode, cannot be received at this time; when receiving data, the mode position '0' is indicated as the reception mode, and cannot be transmitted at this time.

Before talking about the principle of STM32 serial port to realize 485 dual-machine communication, let's review the interrupt knowledge points in the serial port:

There are many types of interrupts for serial ports. There are two main types here: receiving data interrupts and sending data completion interrupts. These two interrupts are closely related to two flag bits: RXNE (read data register is not empty) and TC (send complete). For example, when receiving data (RXNE, the read data register is not empty), we need to generate an interrupt. An interrupt is generated at the end of the transmission of the data (TC, transmission completed). Both interrupt generation methods are configured in the open serial port interrupt function (USART_ITConfig();). And in the acquisition interrupt status function (USART_ITStatus ();) to determine whether to send an interrupt or accept an interrupt.

note

01

Someone asked when the interrupt was generated and did not see the interrupt flag cleared in the program. Has it been interrupted? There are two ways to clear the interrupt flag (also in the book): 1. Read USART_DR as soon as possible. Data register), this bit can be cleared by reading USART_DR; 2. You can directly write '0' to this bit and clear it directly.

02

The serial port baud rate of the two boards must be the same, otherwise the desired data will not be obtained.

STM32 serial port realizes the principle of 485 two-machine communication (library function):

❈ 1. In the main function, scan the button. Once key0 is pressed, the first 5 bytes of data are stored in the rs485buf[] array, then RS485_Send_Data (rs485buf, 5) is called; the function sends 5 bytes of data to the serial port. ❈

❈ 2, enter RS485_Send_Data (); function, first set the 485 to the transmission mode (RS485_TX_EN = 1) through the flag, then cycle 5 times, send the 5 bytes of data, through the library function: USART_Send_Data (); The USART_DR register (automatically transmitted), and finally sets 485 to the receive mode (RS485_TX_EN=0) by the flag bit. ❈

❈ 3. The first two are sent. It is now received. The main function is passed through RS485_Receive_Data(); it is received continuously. ❈❈4, enter RS485_Receive_Data (); function, if you have not pressed the button, it will not send data, it will not generate a receive interrupt, it will not go to our defined receive buffer (RS485_RX_BUF[64]) Write data. The value of the RS485_RX_CNT counter is also '0', corresponding to the if statement in the RS485_Receive_Data(); function (the red box in the figure below)❈

If the button is pressed, the data will be sent, and a receive interrupt will be generated. The data will be written to our defined receive buffer (RS485_RX_BUF[64]). The value of the RS485_RX_CNT counter will start to increase, corresponding to RS485_Receive_Data( ); the function will enter the if statement inside, take the data from the previously defined receive buffer (RS485_RX_BUF[64]).

XPON 1GE ONU

The following analyzes the causes of ONU energy waste:
1. The interface is idle.
ONU generally includes multiple interfaces. Such as FE interface, GE interface, POTS interface, WIFI and IPlV interface, etc. In many cases, only part of the interface is used, and energy is consumed when the interface is idle.
2. Increased energy consumption caused by chip module design.
In the ONU design, the modules are usually divided by function and integrated on the same chip, controlled by an enable terminal. When power is supplied, the entire module needs to be powered, and the unnecessary functional blocks are also consuming energy.
3. Processing of OLT data.
Due to the broadcast transmission characteristics of the OLT, when the OLT sends broadcast information or sends information to a certain ONU, other ONUs that do not receive the information must also process it, resulting in a waste of resources.
4. Idle monitoring.
For TDM-PON, each ONU can only send upstream data in burst mode in a time slot authorized by the OLT, and the OLT forwards downstream data in the form of broadcast frames, which makes all ONUs always in operation. The ONU does not know when the user or the OLT will send data to itself. The receiving and sending modules always keep monitoring. When a certain ONU has no upstream or downstream data for a long time, the normal operating state will make it consume more energy.
5. Waiting time.
The structure of the PON system determines that the channel capacity should be shared between ONUs in the upstream direction. The PON system needs to adopt a certain arbitration mechanism to avoid conflicts. Each ONU is allocated a time slot, and frames received from users are buffered first. It can only be sent when it arrives.

Dual Mode Onu,Xpon Onu Router,Xpon Ont 1GE ONU,Dual Mode Xpon Onu

Shenzhen GL-COM Technology CO.,LTD. , https://www.szglcom.com