0 Introduction
At present, multi-machine serial communication is the mainstream communication method in the field of communication control. Serial communication is often used to achieve the purpose of information exchange in data communication, computer network, distributed industrial control system and its measurement and control field. The multi-machine serial communication control network is a multi-machine serial communication industrial control equipment network composed of RS 485 communication interface at the physical layer. RS 485 is both the protocol standard of the physical layer and the electrical standard of the serial communication interface. This communication interface can easily form a control network with many devices. The RS 485 communication method has many advantages. First of all, its communication distance is relatively long, usually hundreds of meters or even more than kilometers, and it can also realize multi-point communication, so that a local area network within a small range can be established, which is more practical. RS 485 adopts differential signal transmission, which has little to do with the ground level, so it has better anti-interference ability, and can obtain stable transmission even when the signal voltage is relatively small.
1 Overall plan and hardware design
The design of the electronic switch system requires that the host can confirm the address with the slave and communicate with each other, the slave can accurately detect the measured signal, the host can receive the data signal from the slave and display it through the LCD and light-emitting diode, and the RS 485 bus master and slave can achieve long-distance communication. The main core chips used by the master and slave are all single-chip microcomputers. Considering the performance of the single-chip microcomputer and the needs of the actual operating environment, the AT89S51 single-chip microcomputer is selected, and the serial communication network structure is shown in Figure 1.
(1) Main components used by the host: AT89S51 MAX4851602LCD LED RESISTORS CAP CRYSTAL;
(2) Main components used by the slave: AT89S51 MAX485 RESISTORS CAP CRYSTAL
Main functions of the host:
(1) Address confirmation with the slave device.
(2) Query whether the slave has a signal (the corresponding data signal generated when the slave detects the measured value) to send to the master.
(3) The slave address of the sending signal is displayed through the LCD, and the signal level can be displayed through the light-emitting diode (the two light-emitting diodes here represent the on and off of the two travel switches respectively).
Main functions of slave:
(1) Address confirmation with the host.
(2) Detect the measured quantity and send the measured signal data to the host.
The host has two main functional modules: the LCD display module is used to display the slave address number, the device used is 1602LCD, and the RS 485 serial communication module is used to realize long-distance serial communication with the slave, which is realized using the MAX485 chip.
The main functional module of the slave is the RS 485 serial communication module, which is used to send and receive data with the host.
2 Design Implementation Principles
The master and slave devices both use the AT89S51 microcontroller, which is a low-power, high-performance CMOS 8-bit microcontroller with 4 KB of FLASH read-only program memory that can be repeatedly erased and written 1,000 times. XTAL1 of the microcontroller: input of the reverse oscillator amplifier and input of the internal clock working circuit. XTAL2: output from the reverse oscillator. This electronic switch is designed to be connected to an external 12MHz crystal oscillator.
The master and slave use two full-duplex serial communication ports of the microcontroller to connect to the MAX485 chip to complete the serial communication with the slave. The serial port control register SCON sets the serial port working mode, monitors the serial port working status, and controls the sending and receiving status. P3.0/RXD is the serial communication receiving end, and P3.1/TXD is the serial communication sending end.
The host port P0.0~P0.7 is used as the data line of the LCD display. The 10 kΩ pull-up resistor of the P0 port is connected to the D0~D7 data terminal of the 1602 LCD, P3.7 is connected to the enable terminal E, P3.6 is connected to the read/write signal line RW, and P3.5 is connected to the register selection terminal RS. The P1.0 and P1.1 pins are connected to two light-emitting diodes to display the level of the signal sent by the slave.
The slave's P1.0 and P1.1 pins are connected to the primary and secondary travel switches respectively to detect the status of the two switches. Finally, the slave's P1.0 and P1.1 pins send the status of the travel switches to the host, and the host reads the status value and displays it.
The host uses polling. When the host queries slave No. n, it confirms the address with slave No. n and determines whether slave No. n generates a signal. If not, the host will query slave No. n-1. If a signal is generated, the host receives the signal and stores the host number of the slave, which is displayed through the LED and LCD respectively. If slave No. n-1 continues to generate a signal, the host continues to receive until the reception is completed. The host will query slave No. n-2, and so on. The number of slaves can be set in the host program.
2.1 Multi-machine serial communication and communication protocol
The design core of the electronic switch is mainly realized through multi-machine serial communication of the microcontroller.
2.1.1 Transmitter and Receiver
The AT89S51 serial port is mainly composed of a transmitter, a receiver and a serial control register. The transmitter is mainly composed of a transmit buffer register SBUF and a transmit controller. The receiver is mainly composed of a receive buffer register SBUF, a receive shift register and a receive controller.
2.1.2 Serial Port Control Registers
The serial port control register SCON is used to set the serial port working mode, monitor the serial port working status, and control the sending and receiving status. It is a special function register that can be addressed by both byte and bit. The format of the control register SCON is as follows:
The settings of the microcontroller serial port control register SCON in the electronic switch are as follows:
Host SCON setting: 1 0 0 1 1 0 0 0 =#98H
Slave SCON setting: 1 0 1 1 0 0 0 0 = #0B0H
2.1.3 Choice of working mode
The serial communication working mode of this electronic switch microcontroller is selected as working mode 2. In mode 2, the serial port works in 11-bit asynchronous communication mode. One frame of information contains a start bit "0", eight data bits, a programmable ninth data bit and a stop bit "1". The programmable bit is the TB8 bit in SCON. After the eight data bits, it can be used as a parity bit or a flag bit of the address/data frame, which is determined by the user.
Baud rate selection: The baud rate of mode 2 is fixed.
If SMOD=0 in PCON, rate=fosc/32
If SMOD=1 in PCON, rate=fosc/64
In this design: the baud rate is 9 600 b/s.
2.1.4 Implementation Principle and Process
Multi-machine communication mainly relies on the correct setting and judgment of the multi-machine communication control bit SM2 and the 9th data bit (D8) sent or received between the master and slave machines.
The implementation process of multi-machine serial communication of electronic switches:
(1) Both the master and slave are initialized to working mode 2. The master sets SM2 = 0 to enable interrupts, and the slave sets SM2 = 1 and REN = 1.
(2) The host sets REN=1, TB8=1, sends the address information to the slave, and waits to see if the sending is complete. The slave waits for the host to send the address.
(3) The slave receives the address and compares it with the local address. If the comparison is correct, it sets SM2 = 0, sends a response address to the host and waits for the sending to be completed. After receiving the address, the host confirms the address and sets TB8 = 0.
(4) After the slave address is sent, it sends the signal data and waits for the sending to be completed.
(5) After receiving the data, the host sends the slave number to the LCD display and the signal data to the LED to display the signal level. [page]
2.1.5 Address confirmation between master and slave
Before the master and slave communicate, they first confirm the address, the purpose of which is to let the host know which slave is sending data to the host. The host first sends the address number #0FFH of slave n. After receiving the address sent by the host, all slaves check it with their own addresses. Slaves whose addresses are not #OFFH will continue to wait for the host's call. The correct slave sends its own response address to the host. After receiving the slave's response address, the host makes further judgments to confirm whether it is the address of slave n. After the address is confirmed to be correct, the host communicates data with slave n until the data communication is completed, and the host will call the next slave.
2.1.6 Avoiding data conflicts between multiple slaves and the master
When a host communicates serially with multiple slaves, if a slave sends data to the host when it has data, two, three or more slaves may generate data at the same time and need to send it to the host at the same time, which will cause data communication conflicts. The design of this electronic switch adopts the method of host polling slaves, which effectively avoids the problem of master-slave data communication conflicts. The host first calls slave No. n. After the address is confirmed, slave No. n responds and communicates with the host, and the other slaves are in a waiting state. The host receives the data of slave No. n and determines whether the slave continues to send data. At this time, if other slaves have data, they can only be in queue and will not interfere with the host. After the host receives the data, it will reduce the address of slave No. n by 1 and call slave No. n-1. It will repeatedly poll each slave. The host polling process is very fast, and the slave can be processed in time when it detects the measured signal. As shown in Figure 2.
2.2 Multiple RS 485 serial communication modules
RS 485 uses balanced transmission and differential reception to achieve communication: at the transmitting end TXD, the TTL level signal of the serial port is converted into two differential signal outputs A and B, and after transmission, the differential signal is restored to a TTL level signal at the receiving end. The two transmission lines usually use twisted pair cables, which are differential transmissions, so they have strong resistance to common mode interference and high receiving sensitivity. If the data is transmitted at a rate of 10 Kb/s, the transmission distance can reach 12 m, and when the data is transmitted at a rate of 100 Kb/s, the transmission distance can reach 1.2 km. If the baud rate is reduced, the transmission distance can be further increased.
To realize RS 485 serial communication, you only need to connect a MAX485 chip to the host and each slave. The output terminal RO of the receiver and the input terminal DI of the driver only need to be connected to the RXD and TXD of the microcontroller respectively; the and DE terminals are the enable terminals for receiving and transmitting respectively. When it is logic 0, the device is in the receiving state; when DE is logic 1, the device is in the transmitting state. Because MAX485 works in half-duplex state, only one pin of the microcontroller needs to be used to control these two pins; the P3.4 pin of the microcontroller is used in the host electronic switch to control the and DE terminals of MAX485, as shown in Figure 3.
The A and B terminals are the differential signal terminals for receiving and sending respectively. When the level of the A pin is higher than that of the B pin, it means that the data sent is 1; when the level of the A pin is lower than that of the B terminal, it means that the data sent is 0. The wiring is very simple when connected to the microcontroller. Only one signal is needed to control the reception and transmission of the MAX485.
The reliability measures are as follows:
When reset, both the master and slave should be in the receiving state.
On the control side, the effective pulse width of the DE signal should be greater than the width of a frame of signal sent or received.
At the same time, add a matching resistor between the A and B terminals. Generally, a 120 Ω resistor can be selected to absorb the reflected signal on the bus and ensure that the normal transmission signal is clean and burr-free. The value of the matching resistor should be equivalent to the characteristic impedance of the bus.
The receive and send enable and DE pin control are implemented in the program. The host part program is as follows:
2.3 LCD display module
The LCD display module uses 1602 LCD. 1602 LCD has many advantages, such as low power consumption, small size, rich display content, ultra-thin and light weight, and is increasingly widely used in pocket instruments and low-power application systems. The 1602 LCD display is used on electronic switches to display the slave number that sends the signal data. When a slave detects a signal, it will display: [page]
Fault Machine is: *** (No. 001, No. 002, No. 003...)
The main pin definitions of 1602 are as follows:
RS is the register selection. When it is high, the data register is selected. When it is low, the instruction register is selected. RW is the read/write signal line. When it is high, the read operation is performed. When it is low, the write operation is performed. When RS and RW are both low, the instruction or display address can be written. When RS is low and RW is high, the busy signal can be read. When RS is high and RW is low, data can be written. The E terminal is the enable terminal. When the E terminal jumps from high to low, the LCD module executes the command. D0~D7 are 8-bit bidirectional data lines.
When the host receives a primary or secondary signal from a slave, it sends the slave number to the LCD to display the slave number. The host first separates the address number value into hundreds of bits, and then displays it bit by bit on the LCD.
The procedure for separating hundreds of bits is as follows:
The schematic diagram of the host RS 485 communication and LCD display circuit is shown in Figure 3.
3 Functions and applications of electronic switches
The electronic switch is functionally divided into two parts: a master electronic switch and a slave electronic switch.
The host is mainly responsible for receiving and processing data, and displaying the final result status. The slave electronic switch is mainly responsible for detecting signals and sending data to the host. The entire system is composed of a host and one or more slave electronic switches. The number of slave electronic switches can be determined according to actual needs.
Because the electronic switch is used to detect the deviation of the conveyor belt position, the slave electronic switch is installed in a lever mechanism (as shown in Figure 4 and Figure 5). Each lever mechanism has two travel switches inside. According to the required signal level, they are set as a primary travel switch and a secondary travel switch respectively. The lever is connected to the travel switch through a cam mechanism, and the two data input lines of the slave electronic switch are connected to the two travel switches.
This electronic switch is mainly designed for the detection of position deviation during the transmission process of large and medium-sized conveyor belts. It can also be applied to the detection of displacement and deviation of other related equipment and occasions. Slave electronic switches are placed at determined positions on both sides of the conveyor belt. When a certain amount of position deviation occurs at a certain point during the transmission process of the conveyor belt, the first-level travel switch will be triggered through the gear lever to generate a first-level trigger signal, and the signal will be transmitted to the slave electronic switch. The slave electronic switch detects it and sends it to the host for processing. The host is responsible for displaying the slave number and fault level of the fault, so that the staff can understand where the conveyor belt has a first-level deviation and make corresponding adjustments to the conveyor belt. Similarly, when a second-level deviation occurs at a certain point on the conveyor belt, the slave electronic switch will send the second-level signal to the host for display.
The schematic diagram of the installation structure on the conveyor belt is shown in Figure 5.
4 Operation status and results
When the level 1 travel switch in the travel switch lever mechanism connected to slave No. 1 is pressed, slave No. 1 detects a level 1 fault signal, confirms the address with the host, and sends data to the host. At this time, the LCD display on the host displays: Fault Machine is: 001 (the faulty slave number is 001), and one of the LEDs is off (under normal conditions, both LEDs are in a light state). Similarly, if slave No. 2 detects a fault signal, the operating result is shown in Figure 6.
5 Conclusion
This electronic switch is designed based on the principle of single-chip multi-machine serial communication. It is a small electronic switch system composed of RS 485 module and 1602 LCD display module. In industrial control, the application of multi-machine serial communication is becoming more and more extensive. On the basis of this electronic switch design, more powerful electronic switch related products based on RS 485 bus multi-machine serial communication can be developed for application in industrial control, detection and other fields.
Previous article:Anti-interference design of C8051f064 in power monitoring instrument
Next article:Design and implementation of automobile anti-theft alarm system based on single chip microcomputer
Recommended ReadingLatest update time:2024-11-17 02:28
- Popular Resources
- Popular amplifiers
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Practical training guidance for new electrician technology (Wu Qihong, Jiang Jian, Xu Kungang, Zhang Hong)
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- (Bonus 10) GD32L233 Review - SPI Driver DS1302
- O-RAN Testing Tool - Terminal Emulator UEE, Do You Know It?
- [Evaluation of domestic FPGA Gaoyun GW1N-4 series development board]——5. Internal Flash and external Flash program curing test
- The difference between msp430fr5994 and msp430fr59941
- Please help me with ad5933
- Without exaggeration or criticism, SS5 is the smoothest and most user-friendly Eclipse-based IDE I have ever used.
- [2022 Digi-Key Innovation Design Competition] 4. ESP32-S2-Kaluga-1 running LVGL
- Share a domestic 32-bit M3 microcontroller CH32F103
- Those who work on weekends, please come and gather
- Dear electronic design experts, please come and have a look