STM32 RS485 communication method

In the long-distance communication, it is difficult to avoid interference, therefore, great cattle people have created a differential transmission method - RS485 communication (hereinafter referred to as RS485). RS485 transmits data by two differential lines. Compared with RS232, the transmission distance is farther and interference is stronger. Of course, in order to save money, only one set of differential lines is reserved, and only half-duplex communication that only receives or sends data at the same time can be completed.

In the design, we often use a chip named Max485 to complete the conversion from TTL level to differential level. This chip has a DE (transmission enable) pin to control the data transmission direction of the RS485 line. When the foot is high and when it is low, the quality of our data exchange also plays a major role.

Let's first look at the effect of the DE pin. When the master device completes the transmission, it needs to release the RS485 bus within 1 byte. Otherwise, after the slave device receives the data and then sends back the data, it will conflict with the master device's occupation of the bus. This is on the RS485 bus. Not allowed - The RS485 bus has no arbitration mechanism. Therefore, the DE pin needs to pull the DE pin from the high level to the low level within one second of the master sending the last bit of the last byte.

STM32 RS485 communication method

The STM32 microprocessor provides an application example to achieve precise and efficient control of the DE pin. Here we use DMA to send and receive data through the UART, then we will use the DMA transmit complete interrupt and the USART transmit complete interrupt. The DMA controller monitors the entire transmission process. The pending data will be continuously stored in the USART data register until the DMA count is reduced to zero. When the DMA transmission is complete, it will trigger the DMA transmit complete interrupt, and we will pull the DE pin low during this interrupt.

STM32 RS485 communication method

Trasmission Pole

Trasmission Pole,Painted Steel Pole,Transmission Lines Steel Pole,Power Distribution Steel Pole

Jiangsu Baojuhe Science and Technology Co.,Ltd. , https://www.galvanizedsteelpole.com