当前位置:网站首页>Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200
Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200
2022-06-29 07:42:00 【Industrial control old horse】
One 、 Hardware and communication principle analysis
Siemens S7-200 series PLC Have RS-485 Serial port , So we should make MCS51 SCM and S7-PLC To communicate , Several communication modes can be adopted . One of them is that you can use MCS-51 Serial port and MAX485 Chip connection , Then with S7-200 PLC Of RS-485 Communication through port , The hardware connection is shown in the figure 1 Shown .
S7-200 PLC It is the most abundant small serial communication mode PLC, Support multiple communication protocols , Such as point-to-point interface protocol (PPI agreement )、 Multipoint interface protocol (MPI agreement ) and PROFIBUS Protocol and free communication protocol . Free communication protocol is also called user defined protocol , Use free port mode , User defined communication protocols can be implemented , Connect multiple intelligent devices , It is very convenient to use , It has achieved great success in the third-party project access .
In free port mode ,PLC The serial communication interface of is controlled by the user , Through ladder diagram program and assembly language with the single chip microcomputer , To use the completion interrupt 、 Character reception interrupt 、 Transmission completion interrupt, etc , The communication protocol is completely controlled by the user . At this time, the MCU is in the host state , The MCU sends handshake signal actively ,PLC After receiving the signal, you can passively feed back the information .
chart 1 MCS-51 SCM and S7-200 Hardware wiring diagram of
Two 、 Communication system design
2.1 Communication protocol design
The definition is based on experience and relevant references , Define the protocol structure and parameters .
(1) The baud rate of communication is 9.6kbps, No verification ,8 Data bits ,1 Programmable bits ,1 Bit start bit ,1 Bit stop bit .
(2) The format of defining the data flow structure of the communication protocol is the starting code 、 Command code 、 Element first address 、 Number of bytes 、 Data blocks 、BCC Check code and end code .
● Start code : It means single chip microcomputer and PLC Start sending data , Is the first character of the data stream , tell PLC Communication started , It can be used 00H Express
● Command code : Indicates that the single-chip microcomputer is right PLC Various operations of :
40H: Read the target component I、Q、V、M、SM、L、T、C The data or state of ;
41H: Modify the target component I、Q、V、M、SM、L、T、C The data or state of ;
42H: Force the target unit to be ON;
43H: Force the target unit to be OFF;
● Element first address : Express PLC Internal component type and register address ( But it cannot represent a bit address ). The first two bytes indicate the register type , The last two bytes represent the register number .00 00(H):I Register area 01 00(H):Q Register area .02 00(H):M Register area 08 00(H):V Register area ;
● Number of bytes : Starting from the first address of the component , Read or write PLC Number of data blocks of components : Ready to read or write PLC The data or state of ;
● BCC Check code : During transmission , The instruction may be subject to any interference to distort the original data signal , The instruction at this time is of course wrong , To detect errors in the transmission of instructions , The receiving party must further confirm the instruction , To prevent erroneous instructions from being executed , The simplest way is to use the check code .BCC The method of the check code is the string to be transmitted ASCII Codes are XOR and in bytes , And transmit the XOR and as part of the instruction ; similarly , After receiving the instruction, the receiving party , XOR and... The received string in the same way , And compare with the value sent by the sender , If the values are equal , It means that the received instruction is correct , The opposite is wrong
● End code : The end character marks the end of the instruction , In this case, it is defined as FFH, Different PLC The slave station can define different end characters to receive the data for the PLC Instructions .
2.2 Implementation of communication program
(1) The realization of single chip computer program . MCU initializes in the main program , Adopt serial port working mode 3[2], The baud rate is 9.6kbps, Single chip microcomputer is used as the host , towards PLC Make a call , Read data or write data regularly , See figure for the procedure flow chart 2.
chart 2 Single chip computer communication program flow chart
(2)PLC Implementation of end program flow chart .PLC The end acts as a slave , Use ladder diagram or STL Programming , It is mainly to set the communication protocol first , Then process the collected data according to the protocol , And then send it to the host microcontroller , The specific program flow chart is shown in Figure 3 Shown .
chart 3 PLC End communication program flow chart
3、 ... and 、 Conclusion
In this paper, the single-chip microcomputer and PLC Serial communication method of , Successfully applied to multiple projects , The practice shows that this method is simple and reliable , The cost is low , And it is easy to expand other economical and practical functions , Such as A/D、D/A And so on , Good social and economic benefits have been achieved .
边栏推荐
- 感知健康生活 赋能无界连接 ——为OpenHarmony 3.1生态构建贡献芯海力量
- [translation] how Bink drives the digital loyalty transactions of some of the largest banks in the UK
- Markdown skill tree (8): code blocks
- cv::Mat与Base64转换(含图片压缩解压等流程)
- 施努卡:视觉定位系统厂家 什么是视觉定位系统
- [translation] E-Cloud. Large scale CDN using kubeedge
- Simulation analysis of sailing dynamics
- Imx6dl4.1.15 supports EIM bus (upper) - actual operation and modification.
- tf.count_nonzero
- Imx6dl4.1.15 supports EIM bus (Part 2) - configuration principle analysis.
猜你喜欢
随机推荐
Use of LSTM neural network and general neural network
软件测试面试如何正确谈论薪资?
How to permanently set Mysql to utf8 encoding?
cv2.cvtColor
Imx6dl4.1.15 supports EIM bus (upper) - actual operation and modification.
关于开发web场景下如何解决手机访问web跨域问题
反射修改final
Schnuka: 3D visual recognition system 3D visual inspection principle
Appium automation test foundation ADB common commands (III)
ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector
MIPS instruction set and brief analysis
蓝桥杯——13届第二批试题解析
路由详解(九阳真经)
Vibration signal generation and processing based on MATLAB Doppler effect
How to view software testing training? Do you need training?
关于KingbaseES临时文件过大问题
1031 Hello World for U
IMX6DL4.1.15支持EIM总线(上)——实际操作,修改内容。
postman预处理/前置条件Pre-request
Suggestions on working methods and efficient work









