[go: up one dir, main page]

CN108628536A - A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction - Google Patents

A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction Download PDF

Info

Publication number
CN108628536A
CN108628536A CN201810523138.8A CN201810523138A CN108628536A CN 108628536 A CN108628536 A CN 108628536A CN 201810523138 A CN201810523138 A CN 201810523138A CN 108628536 A CN108628536 A CN 108628536A
Authority
CN
China
Prior art keywords
data
module
human
stm32
touch screen
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810523138.8A
Other languages
Chinese (zh)
Inventor
游达章
徐笑涵
余磊涛
王�琦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hubei University of Technology
Original Assignee
Hubei University of Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hubei University of Technology filed Critical Hubei University of Technology
Priority to CN201810523138.8A priority Critical patent/CN108628536A/en
Publication of CN108628536A publication Critical patent/CN108628536A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/01Input arrangements or combined input and output arrangements for interaction between user and computer
    • G06F3/048Interaction techniques based on graphical user interfaces [GUI]
    • G06F3/0487Interaction techniques based on graphical user interfaces [GUI] using specific features provided by the input device, e.g. functions controlled by the rotation of a mouse with dual sensing arrangements, or of the nature of the input device, e.g. tap gestures based on pressure sensed by a digitiser
    • G06F3/0488Interaction techniques based on graphical user interfaces [GUI] using specific features provided by the input device, e.g. functions controlled by the rotation of a mouse with dual sensing arrangements, or of the nature of the input device, e.g. tap gestures based on pressure sensed by a digitiser using a touch-screen or digitiser, e.g. input of commands through traced gestures
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Input From Keyboards Or The Like (AREA)

Abstract

Include turning 232 adapters, RS232 data lines, power module by the minimum system circuit board of main control chip, human-computer interaction touch apparatus, TTL of STM32F103RCT6 the invention discloses a kind of STM32 of man-machine interface interaction and serial ports touch screen communication module;Using STM32F103RCT6 as the minimum system circuit board of main control chip the control to motor is communicated and is realized with human-computer interaction touch apparatus by serial ports and data line;Power module with include being connect by the minimum system circuit board of main control chip, human-computer interaction touch apparatus of STM32F103RCT6.The present invention has a set of communication program for simplifying efficient in touch screen communication level;In embedded system platform level, hardware configuration is simple but the embedded device of rich interface, master control type are enriched, and communication program modularization facilitates transplanting;In Human Machine Interface level, the brief generous control in interface is in good order, allows controller and touch screen real-time communication, humanized design to avoid the generation of some maloperations by Modbus communications protocol.

Description

一种人机界面交互的STM32与串口触摸屏通讯模板A STM32 and serial port touch screen communication template for man-machine interface interaction

技术领域technical field

本专利属于威纶通触摸屏显示控制程序通用模板领域,具体涉及一种可提供良好交互环境的STM32与串口触摸屏通讯模板的设计。This patent belongs to the general template field of Weiluntong touch screen display control program, and specifically relates to the design of a STM32 and serial touch screen communication template that can provide a good interactive environment.

背景技术Background technique

近年来,随着工业自动化的迅猛发展,工业控制系统的生产效率、环境友好和可靠性等技术性能指标有了明显的提高,工业控制系统的操作难度却大幅度下降,各类工业控制系统日益智能化。新一代的工业控制系统的客户,在设备的可操作性以及设备操作的安全性与舒适性等方面对工业控制系统提出了更高的要求。这表明,给工业控制系统配套相应的人机交互平台,并保证平台人机界面的质量已成为一个大问题。可靠的人机交互平台与友好的人机界面设计已经成为新一代工业控制系统开发的一个重要组成部分。触摸屏作为一种新的人机界面产品已广泛应用在各大自动化工厂。使用触摸屏能很好的提高设备生产效率,明确告知设备操作员自动化设备的运行状况及生产状态。使用触摸屏可以使电气接线简单化,同时减少主控板的I/O点数,降低生产成本,相对提高整套自动化设备的附加值。In recent years, with the rapid development of industrial automation, the technical performance indicators such as production efficiency, environmental friendliness and reliability of industrial control systems have been significantly improved, but the operation difficulty of industrial control systems has been greatly reduced. Intelligent. Customers of the new generation of industrial control systems have put forward higher requirements for industrial control systems in terms of equipment operability, safety and comfort of equipment operation. This shows that it has become a big problem to support the corresponding human-computer interaction platform for the industrial control system and ensure the quality of the platform human-computer interface. A reliable human-computer interaction platform and a friendly human-computer interface design have become an important part of the development of a new generation of industrial control systems. As a new human-machine interface product, touch screen has been widely used in major automation factories. Using the touch screen can improve the production efficiency of the equipment, and clearly inform the equipment operator of the operation status and production status of the automation equipment. Using the touch screen can simplify the electrical wiring, reduce the number of I/O points of the main control board, reduce production costs, and relatively increase the added value of the entire set of automation equipment.

然而在进行工业触摸屏的人机交互界面的开发中,开发者花需要费很多精力在调试最底层的代码中,需要理解modelbus通信协议,rs232串口以及丰富的32位单片机知识。在调试的过程中,往往就在通信协议与工控屏的通信上大费周章,消耗许多时间,影响项目进度。However, in the development of the human-computer interaction interface of the industrial touch screen, developers need to spend a lot of energy in debugging the lowest-level code, and need to understand the modelbus communication protocol, rs232 serial port and rich knowledge of 32-bit single-chip microcomputer. In the process of debugging, it is often a lot of work on the communication between the communication protocol and the industrial control screen, which consumes a lot of time and affects the progress of the project.

专利内容patent content

本专利的目的是提供一种人机界面交互的STM32与串口触摸屏通讯模板,在进行工业控制人机界面开发的过程中,可以将精力全部放在开发和调试需要的功能上,减少开发成本,缩短开发周期,增加程序的可靠性和稳定性。在教育领域,此方法可以作为入门工控屏与32位单片机及modelbus协议开发的优秀例程。The purpose of this patent is to provide a STM32 and serial touch screen communication template for man-machine interface interaction. During the development of industrial control man-machine interface, you can focus all your energy on the functions required for development and debugging, and reduce development costs. Shorten the development cycle and increase the reliability and stability of the program. In the field of education, this method can be used as an excellent routine for the development of entry-level industrial control screens, 32-bit single-chip microcomputers and modelbus protocols.

本发明所采用的技术方案是:一种人机界面交互的STM32与串口触摸屏通讯模板,其特征在于:包括以STM32F103RCT6为主控芯片的最小系统电路板、人机交互触摸设备、TTL转232转接头、RS232数据线、电源模块;The technical scheme adopted in the present invention is: a communication template of STM32 and serial port touch screen for man-machine interface interaction, characterized in that it includes the minimum system circuit board with STM32F103RCT6 as the main control chip, man-machine interaction touch equipment, TTL to 232 turns Connector, RS232 data cable, power module;

所述以STM32F103RCT6为主控芯片的最小系统电路板通过TTL转232转接头、串口及RS232数据线与人机交互触摸设备进行通讯和实现对电机的控制;The minimum system circuit board with STM32F103RCT6 as the main control chip communicates with the human-computer interaction touch device and realizes the control of the motor through the TTL to 232 adapter, serial port and RS232 data line;

所述电源模块与所述包括以STM32F103RCT6为主控芯片的最小系统电路板、人机交互触摸设备连接。The power supply module is connected with the minimum system circuit board including the STM32F103RCT6 as the main control chip, and the human-computer interaction touch device.

本专利人机界面交互的stm32与串口触摸屏通讯模板的设计的优点是:在触摸屏通讯层面上,有一套精简完整高效的通讯程序(包含数据帧的识别、数据帧的发送和通讯内容提取等);在嵌入式系统平台层面上,选用了硬件结构简单但是接口丰富的嵌入式设备,主控种类丰富,通讯程序模块化,方便移植;在人机界面设计层面上,界面简约大方控件井然有序,通过Modbus通讯协议让控制器与触摸屏实时通讯,显示数据,人性化的设计能避免一些误操作的发生。The advantage of the design of the communication template between stm32 and serial port touch screen of the patent man-machine interface interaction is: on the level of touch screen communication, there is a set of simplified, complete and efficient communication program (including identification of data frame, transmission of data frame and extraction of communication content, etc.) ; On the level of the embedded system platform, an embedded device with a simple hardware structure but rich interfaces is selected, with rich types of main control, modular communication program, and easy transplantation; on the level of man-machine interface design, the interface is simple and elegant, and the controls are well-organized , Through the Modbus communication protocol, the controller can communicate with the touch screen in real time to display data, and the humanized design can avoid some misoperations.

附图说明Description of drawings

图1为本发明实施例的框架结构图;Fig. 1 is a frame structure diagram of an embodiment of the present invention;

图2为本发明实施例的STM32数据帧识别流程图;Fig. 2 is the STM32 data frame identification flowchart of the embodiment of the present invention;

图3为本发明实施例的数据帧发送流程图;FIG. 3 is a flow chart of sending data frames according to an embodiment of the present invention;

图4为本发明实施例的CRC-16校验在STM32中的实现流程图。FIG. 4 is a flow chart of the implementation of the CRC-16 check in the STM32 according to the embodiment of the present invention.

具体实施方式Detailed ways

为了便于本领域普通技术人员理解和实施本发明,下面结合附图及实施例对本发明作进一步的详细描述,应当理解,此处所描述的实施示例仅用于说明和解释本发明,并不用于限定本发明。In order to facilitate those of ordinary skill in the art to understand and implement the present invention, the present invention will be described in further detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the implementation examples described here are only used to illustrate and explain the present invention, and are not intended to limit this invention.

请见图1,本发明提供的一种人机界面交互的STM32与串口触摸屏通讯模板,其特征在于:包括以STM32F103RCT6为主控芯片的最小系统电路板、人机交互触摸设备、TTL转232转接头、RS232数据线、电源模块;以STM32F103RCT6为主控芯片的最小系统电路板通过TTL转232转接头、串口及RS232数据线与人机交互触摸设备进行通讯和实现对电机的控制;电源模块与包括以STM32F103RCT6为主控芯片的最小系统电路板、人机交互触摸设备连接。Please see Fig. 1, a communication template of STM32 and serial port touch screen provided by the present invention is characterized in that it includes the minimum system circuit board with STM32F103RCT6 as the main control chip, human-computer interaction touch equipment, TTL to 232 turns Connector, RS232 data line, power module; the minimum system circuit board with STM32F103RCT6 as the main control chip communicates with the human-computer interaction touch device and realizes the control of the motor through the TTL to 232 adapter, serial port and RS232 data line; the power module and Including the minimum system circuit board with STM32F103RCT6 as the main control chip, human-computer interaction touch device connection.

本实施例的人机交互触摸设备为威纶通TK6070IQ触摸屏,转接头为MAX3232芯片的TTL转232转接头。The human-computer interaction touch device in this embodiment is a Weiluntong TK6070IQ touch screen, and the adapter is a TTL-to-232 adapter of the MAX3232 chip.

本实施例的人机交互触摸设备包括下载模式选择模块、运行速度设置模块、加工头部磨损补偿模块、参数初始化模块、调试模式速度设置模块、坐标显示模块、归零状态灯、归零设置模块、手动坐标位置移动模块、运行停止控制模块;下载模式包括SD卡下载模式和串口下载模式;下载模式选择模块,用于选择G代码的传输模式;运行速度设置模块,用于调节程序运行时的速度;加工头部磨损补偿模块,用于通过设定相关数值进行刀具补偿;参数初始化模块,用于模板开机时用户输入的数据存入下位机缓冲区供使用;调试模式速度设置模块,用于在debug模式下的运行速度设置;坐标显示模块,用于显示模板运作时坐标数值的变化;归零状态灯,为模板归零状态指示灯;归零设置模块,用于设置模板回原点;手动坐标位置移动模块,用于非执行G代码阶段通过X\Y\Z的方向按钮控制坐标的位置变化;运行停止控制模块,用于暂停及急停控制。The human-computer interaction touch device in this embodiment includes a download mode selection module, an operating speed setting module, a processing head wear compensation module, a parameter initialization module, a debugging mode speed setting module, a coordinate display module, a zeroing status light, and a zeroing setting module , manual coordinate position movement module, running stop control module; download mode includes SD card download mode and serial port download mode; download mode selection module, used to select the transmission mode of G code; running speed setting module, used to adjust the speed when the program is running Speed; the machining head wear compensation module is used to perform tool compensation by setting relevant values; the parameter initialization module is used to store the data input by the user into the lower computer buffer for use when the template is turned on; the speed setting module in debugging mode is used to Running speed setting in debug mode; coordinate display module, used to display the change of coordinate value when the template is running; zero status light, which is the template zero status indicator; zero setting module, used to set the template to return to the origin; manual The coordinate position movement module is used to control the position change of the coordinates through the X\Y\Z direction buttons in the non-executing G code stage; the running stop control module is used for pause and emergency stop control.

提取必要参数并匹配对应的界面控件,每个控件均有一个相对独立的地址。人机交互触摸设备上主要有设置了Modbus-RTU通讯协中线圈状态(0x_n)状态和int型寄存器状态来定义界面上的变量,将STM32与界面连接起来完成人机界面的开发,使用界面开发程序就可以验证并在线仿真使用效果。对应参数表格,将参数名与编号添加到通讯协议中。因为编号是起到数组下标的作用,因此使用#define语句将参数名通过下标与通讯协议关联起来,注意要在最后添加表示总数的参数,这两个为下位机所单独使用且不可无。Extract the necessary parameters and match the corresponding interface controls, each control has a relatively independent address. The human-computer interaction touch device mainly sets the coil state (0x_n) state and int register state in the Modbus-RTU communication association to define the variables on the interface, and connects the STM32 to the interface to complete the development of the human-machine interface. Use the interface development The program can verify and simulate the use effect online. Corresponding to the parameter table, add the parameter name and number to the communication protocol. Because the serial number acts as an array subscript, use the #define statement to associate the parameter name with the communication protocol through the subscript, and pay attention to adding the parameter indicating the total number at the end. These two are used separately by the lower computer and are indispensable.

界面软件也要进行仿真的准备。在选择了对应屏幕后还要对连接属性进行修改,如波特率大小要与下位机发送一致,COM口要与插在电脑上的USB转TTL板一致等。配置完后,将STM32通过USB转TTL连接电脑,点击在线仿真即可实验人机界面是否成功;若仿真无异常且各控件灵活使用,则通讯成功。接下来就是使用人机界面进行下位机的实际使用。The interface software should also be prepared for simulation. After selecting the corresponding screen, you need to modify the connection properties, such as the baud rate should be the same as the lower computer, the COM port should be the same as the USB to TTL board plugged into the computer, etc. After the configuration is complete, connect the STM32 to the computer via USB to TTL, click on the online simulation to test whether the man-machine interface is successful; if the simulation is normal and the controls are used flexibly, the communication is successful. The next step is to use the man-machine interface for the actual use of the lower computer.

本实施例的以STM32F103RCT6为主控芯片的最小系统电路板与人机交互触摸设备通信,包括以下步骤:In this embodiment, the minimum system circuit board with STM32F103RCT6 as the main control chip communicates with the human-computer interaction touch device, including the following steps:

步骤1:STM32数据帧识别;Step 1: STM32 data frame identification;

STM32与人机交互触摸设备通讯的实现由STM32数据帧识别及数据帧发送两步骤组成。人机交互触摸设备主要传输RS232信号,通过一个RS232转TTL模块输出TTL信号和单片机连接,通过串口进行交互。两者之间遵循Modbus-RTU通讯协议。The realization of communication between STM32 and human-computer interaction touch devices consists of two steps: STM32 data frame identification and data frame transmission. The human-computer interaction touch device mainly transmits RS232 signals, and outputs TTL signals through an RS232-to-TTL module to connect with the microcontroller, and interact through the serial port. The two follow the Modbus-RTU communication protocol.

STM32需要识别的数据帧类型为四个:线圈状态读取、线圈状态修改、寄存器状态读取和寄存器状态修改。数据帧通过STM32串口通讯,接收寄存器大小为一个字节,即数据帧有多少个字节串口就相应接收多少次。作为主机的触摸屏发送给从机的数据帧固定为八个字节一帧,其内容与分布如下表1所示:There are four types of data frames that STM32 needs to recognize: coil status reading, coil status modification, register status reading, and register status modification. The data frame communicates through the STM32 serial port, and the size of the receiving register is one byte, that is, as many bytes as there are in the data frame, the serial port receives as many times as necessary. The data frame sent by the touch screen as the host to the slave is fixed at eight bytes per frame, and its content and distribution are shown in Table 1 below:

表1Table 1

设备号Device No 功能码function code 地址高低位address high and low 地址信息Address information 校验位(尾部)check digit (tail) 1字节1 byte 1字节1 byte 2字节2 bytes 2字节2 bytes 2字节2 bytes

利用接收到的数据帧固定格式与长度这一特征,请见图2,STM32数据帧识别如下:Taking advantage of the fixed format and length of the received data frame, see Figure 2, the STM32 data frame is identified as follows:

①定义一个大小为8的char型数组用来收集串口接收到的数据;① Define a char array with a size of 8 to collect the data received by the serial port;

②每收到一个数据就将数组除最高位整体向前移一个单位,最新收到的数据放在最后一位;②Every time a piece of data is received, the array is moved forward by one unit except for the highest bit, and the latest received data is placed in the last bit;

③触摸屏设备号为01,初步判断最高位的数据是否为01,是则进行下一步,不是则回转执行步骤②;③The device number of the touch screen is 01. Preliminarily judge whether the highest bit data is 01. If yes, go to the next step. If not, go back to step ②;

④此时数组里极有可能已经是一个完整数据帧,进行数据校验。根据数组最后两位的CRC校验位判断这一组八个字节的数据是否为正确数据帧,若是则进行下一步,若不是则进行步骤②;④ At this time, the array is very likely to be a complete data frame, and data verification is performed. Judging whether the data of this group of eight bytes is a correct data frame according to the CRC check digit of the last two digits of the array, if so, proceed to the next step, if not, proceed to step ②;

⑤此时需要区分此数据帧的类型,判断数组第二位为01、03、05或06中的哪一种。01为读取线圈状态,即布尔寄存器状态;03为读取数值寄存器状态,即int型寄存器状态;05为修改布尔寄存器状态;06为修改int型寄存器状态。识别完成后调用对应的函数进一步处理;其中,功能码的代号及作用请见表2;⑤ At this time, it is necessary to distinguish the type of the data frame, and determine which of the second digit of the array is 01, 03, 05 or 06. 01 is to read the state of the coil, that is, the state of the Boolean register; 03 is to read the state of the value register, that is, the state of the int type register; 05 is to modify the state of the Boolean register; 06 is to modify the state of the int type register. After the recognition is completed, call the corresponding function for further processing; among them, the code and function of the function code are shown in Table 2;

表2Table 2

代码the code 名称name 作用effect 0101 读取线圈状态read coil status 取得一组逻辑线圈的当前状态(ON/OFF)Get the current status (ON/OFF) of a group of logic coils 0303 读取保持寄存器read holding register 在一个或多个保持寄存器中取得当前的二进制值Get the current binary value in one or more holding registers 0505 强置单线圈Forced Single Coil 强置一个逻辑线圈的通断状态Forces the on-off state of a logic coil 0606 预置单寄存器preset single register 放置一个特定的二进制值到一个单寄存器中place a specific binary value into a single register

⑥读取状态的函数将接收数据的数组第3、4位提取作为读取开始的地址,第5、6位作为读取需要的个数;修改状态的函数将接收数据的数组第3、4位提取作为修改寄存器的地址,第5、6位作为修改内容;⑥The function of reading the state extracts the 3rd and 4th bits of the received data array as the address of the start of reading, and the 5th and 6th bits as the number required for reading; the function of modifying the state takes the 3rd and 4th bits of the received data array Bit extraction is used as the address of the modified register, and the 5th and 6th bits are used as the modified content;

⑦向人机交互触摸设备返回从机数据帧,回到第二步等待数据接收。⑦ Return the slave data frame to the human-computer interaction touch device, and return to the second step to wait for data reception.

步骤2:数据帧发送;Step 2: send data frame;

针对不同的触摸屏主机数据帧,从机需要返回发送相应的数据帧作为应答,若不能及时应答,触摸屏会显示警告下位机系统无响应。修改的数据帧返回为主机原数据帧本身,无需任何改动;读取状态数据帧需要返回从机指定寄存器的信息,因此在内容上与长度上均有些许不同,如下表3所示从机返回读取数据帧格式;For different data frames of the touch screen master, the slave needs to return and send the corresponding data frame as a response. If it cannot respond in time, the touch screen will display a warning that the lower computer system has no response. The modified data frame is returned as the original data frame of the host without any modification; reading the status data frame needs to return the information of the specified register of the slave, so the content and length are slightly different, as shown in Table 3 below. Read data frame format;

表3table 3

设备号Device No 功能码function code 返回字节数NReturn the number of bytes N 返回内容return content 校验位(尾部)check digit (tail) 1字节1 byte 1字节1 byte 2字节2 bytes N字节N bytes 2字节2 bytes

请见图3,数据帧发送过程为:Please see Figure 3, the data frame sending process is:

①定义一个int型数组用来发送数据,大小应大于等于所有与触摸屏通讯内容有关变量的总和;① Define an int type array to send data, the size should be greater than or equal to the sum of all variables related to the communication content of the touch screen;

②若此时进入了读取函数,根据当前接收到的主机数据帧,填入设备号与功能码;②If the read function is entered at this time, fill in the device number and function code according to the currently received host data frame;

③将发送内容字节数填入。字节数对于布尔型读取(01功能码)而言为布尔型个数,C语言没有布尔型变量,因此将每个布尔型状态存放在不同char型变量的最后一位(byte);对于数值型读取(06功能码)而言为数值型个数的二倍,因为数值使用int型变量;③ Fill in the number of bytes to send. The number of bytes is a Boolean number for Boolean reading (01 function code), and C language has no Boolean variables, so each Boolean state is stored in the last bit (byte) of a different char variable; for Numeric reading (06 function code) is twice the number of numeric values, because the numeric values use int variables;

④按顺序填入指定寄存器变量的值。④ Fill in the value of the specified register variable in order.

⑤将已填入的所有字节进行CRC校验,得到大小为两字节的校验码,放入到以上数据的尾部;⑤ Perform CRC check on all the filled bytes to get a two-byte check code and put it at the end of the above data;

⑥将此发送数组进行发送,结束函数回到第二步进行等待再次进入。⑥Send this sending array, end the function and go back to the second step to wait for re-entry.

请见图4,本实施例的CRC-16校验在STM32中的实现,常用查表法和计算法。Please refer to Fig. 4, the implementation of the CRC-16 check in this embodiment in STM32, commonly used look-up table method and calculation method.

计算方法一般都是:The calculation method is generally:

①预置1个16位的寄存器为十六进制FFFF(即全为1),称此寄存器为CRC寄存器;① A 16-bit register is preset as hexadecimal FFFF (that is, all 1), and this register is called a CRC register;

②把第一个8位二进制数据(既通讯信息帧的第一个字节)与16位的CRC寄存器的低8位相异或,把结果放于CRC寄存器,高八位数据不变;② XOR the first 8-bit binary data (the first byte of the communication information frame) with the lower 8 bits of the 16-bit CRC register, put the result in the CRC register, and keep the upper 8-bit data unchanged;

③把CRC寄存器的内容右移一位(朝低位)用0填补最高位,并检查右移后的移出位;③ Shift the content of the CRC register to the right by one bit (towards the lower bit), fill the highest bit with 0, and check the shifted out bit after the right shift;

④如果移出位为0:重复第3步(再次右移一位);如果移出位为1,CRC寄存器与多项式A001(1010 0000 0000 0001)进行异或;④ If the shifted out bit is 0: Repeat step 3 (shift right again by one bit); if the shifted out bit is 1, the CRC register is XORed with the polynomial A001 (1010 0000 0000 0001);

⑤重复步骤3和4,直到右移8次,这样整个8位数据全部进行了处理;⑤ Repeat steps 3 and 4 until the right shift is 8 times, so that the entire 8-bit data has been processed;

⑥重复步骤2到步骤5,进行通讯数据帧下一个字节的处理;⑥ Repeat steps 2 to 5 to process the next byte of the communication data frame;

⑦将该通讯信息帧所有字节按上述步骤计算完成后,得到的16位CRC寄存器的高、低字节进行交换;⑧最后得到的CRC寄存器内容即为:CRC码。⑦ After all the bytes of the communication information frame are calculated according to the above steps, the high and low bytes of the obtained 16-bit CRC register are exchanged; ⑧The content of the finally obtained CRC register is: CRC code.

以上计算步骤中的多项式A001是8005按位颠倒后的结果。The polynomial A001 in the above calculation steps is the result of bitwise inversion of 8005.

查表法是将移位异或的计算结果做成了一个表,就是将0~256放入一个长度为16位的寄存器中的低八位,高八位填充0,然后将该寄存器与多项式0XA001按照上述3、4步骤,直到八位全部移出,最后寄存器中的值就是表格中的数据,高八位、低八位分别单独一个表。The look-up table method is to make the calculation result of the shift XOR into a table, that is, put 0~256 into the lower eight bits of a 16-bit register, fill the upper eight bits with 0, and then combine the register with the polynomial 0XA001 follow the above steps 3 and 4 until all eight bits are shifted out, and the value in the final register is the data in the table, with a separate table for the upper eight bits and lower eight bits.

应当理解的是,本说明书未详细阐述的部分均属于现有技术。It should be understood that the parts not described in detail in this specification belong to the prior art.

应当理解的是,上述针对较佳实施例的描述较为详细,并不能因此而认为是对本发明专利保护范围的限制,本领域的普通技术人员在本发明的启示下,在不脱离本发明权利要求所保护的范围情况下,还可以做出替换或变形,均落入本发明的保护范围之内,本发明的请求保护范围应以所附权利要求为准。It should be understood that the above-mentioned descriptions for the preferred embodiments are relatively detailed, and should not therefore be considered as limiting the scope of the patent protection of the present invention. Within the scope of protection, replacements or modifications can also be made, all of which fall within the protection scope of the present invention, and the scope of protection of the present invention should be based on the appended claims.

Claims (5)

1. a kind of STM32 and serial ports touch screen communication module of man-machine interface interaction, it is characterised in that:Including with STM32F103RCT6 is that the minimum system circuit board, human-computer interaction touch apparatus, TTL of main control chip turn 232 adapters, RS232 Data line, power module;
It is described using STM32F103RCT6 as the minimum system circuit board of main control chip by TTL turn 232 adapters, serial ports and RS232 data lines are communicated and are realized the control to motor with human-computer interaction touch apparatus;
The power module with it is described include using STM32F103RCT6 as the minimum system circuit board of main control chip, human-computer interaction Touch apparatus connects.
2. the STM32 and serial ports touch screen communication module of man-machine interface interaction according to claim 1, it is characterised in that: The human-computer interaction touch apparatus is that prestige synthetic fibre leads to TK6070IQ touch screens, and adapter is that the TTL of MAX3232 chips turns 232 switchings Head.
3. the STM32 and serial ports touch screen communication module of man-machine interface interaction according to claim 1, it is characterised in that: The human-computer interaction touch apparatus includes downloading mode selecting module, speed of service setup module, processing head wear-compensating mould Block, parameter initialization module, debugging mode speed setup module, coordinate display module, clean state lamp, zero setup module, Manual co-ordinate position mobile module, operation stop control module;
The downloading mode includes SD card downloading mode and serial ports downloading mode;The downloading mode selecting module, for selecting G The transmission mode of code;The speed of service setup module, for adjusting speed when program operation;The processing head abrasion Compensating module, for carrying out cutter compensation by setting correlation values;The parameter initialization module is switched on for the template When data input by user be stored in slave computer buffering area for using;The debugging mode speed setup module, in debug moulds Speed of service setting under formula;The coordinate display module, the variation of coordinate values when for showing the template running;It is described Clean state lamp is the template clean state indicator light;The zero setup module, for the template Aligning control to be arranged; Manual co-ordinate position mobile module, for the non-executing G code stage by X Y Z arrow button control coordinate position Variation;The operation stops control module, for pause and emergency stop control.
4. the STM32 and serial ports touch screen communication module of man-machine interface interaction according to claim 1, it is characterised in that: It is described to be communicated with human-computer interaction touch apparatus by the minimum system circuit board of main control chip of STM32F103RCT6 including following Step:
Step 1:STM32 data frames identify;
Step 1.1:The char type arrays that a size is 8 are defined to be used for collecting the data that serial ports receives;
Step 1.2:A data are often received just by array except highest order is whole to one unit of Forward, the newest data received are put In last position;
Step 1.3:Touch panel device number is 01, tentatively judges whether the data of highest order are 01, is to carry out next step, is not It then turns round and executes step 1.2;
Step 1.4:Carry out data check;The data of this eight byte of group are judged according to last two CRC check positions of array Whether it is correct data frame, if then carrying out in next step, step 1.2 is executed if not then turning round;
Step 1.5:The type for distinguishing this data frame judges array second to be any in 01,03,05 or 06;01 is reading Take coil state, i.e. Boolean register state;03 is reading numerical values buffer status, i.e. int types buffer status;05 is modification Boolean register state;06 is modification int type buffer status;Corresponding function is called to be further processed after the completion of identification;
Step 1.6:The address that the function of reading state starts the 3rd, 4 extraction of array for receiving data as reading, the 5th, 6 Position is as the number for reading needs;The function of modification state will receive the 3rd, 4 extraction of array of data as modification register Address, the 5th, 6 as modification content;
Step 1.7:Slave data frame is returned to human-computer interaction touch apparatus, step 2 is executed and waits for data receiver;
Step 2:Data frame is sent;
Step 2.1:It defines an int type array and is used for transmission data, size should be greater than setting with human-computer interaction touch equal to all The summation of standby Content of communciation relevant variable;
Step 2.2:If entering function reading at this time, according to the host data frame being currently received, device number and function are inserted Code;
Step 2.3:Content byte number filling will be sent;Byte number is Boolean type number for Boolean type reading, will be each Boolean type state is stored in last position of different char types variables;It is the two of numeric type number for numeric type reading Times, because numerical value uses int type variables;Boolean type reads corresponding 01 function code, and numeric type reads corresponding 06 function code;
Step 2.4:The value for specifying register variable is inserted in order;
Step 2.5:All bytes inserted are subjected to CRC check, the check code that size is two bytes is obtained, is put into above The tail portion of data;
Step 2.6:By this transmission array send, terminate function return to step 2.2 carry out wait for be again introduced into.
5. the STM32 and serial ports touch screen communication module of man-machine interface interaction according to any one of claims 1-4, It is characterized in that:CRC-16 verifies the realization in STM32, including look-up table and calculating method;
The calculating method, specific implementation include the following steps:
1. preset 1 16 registers are hexadecimal FFFF, this register is referred to as CRC registers;
2. first 8 bit binary data are different with 16 least-significant bytes of CRC registers or, result is put in CRC deposits Device, high eight-bit data are constant;
3. the content of CRC registers, which is moved to right a use 0, fills up highest order, and checks the shift-out bit after moving to right;
4. if shift-out bit is 0:The 3rd step is repeated, moves to right one again;If shift-out bit is 1, CRC registers and multinomial A001 carries out exclusive or;
5. repeating step 3 and 4, until moving to right 8 times, 8 data entire so are all handled;
6. repeating step 2 arrives step 5, the processing of the next byte of communication data frame is carried out;
7. after the completion of all bytes of communication information frame are calculated by above-mentioned steps, the high and low word of 16 obtained CRC registers Section swaps;
8. the CRC content of registers finally obtained is:CRC code;
The look-up table is that the result of calculation for shifting exclusive or has been made a table, and it is 16 to be put into a length by 0~256 Register in low eight, high eight-bit filling 0, then by the register and multinomial 0XA001 according to 3,4 step in calculating method Suddenly, it is all removed until eight, the value in last register is exactly the data in table, high eight-bit, eight individually one low A table.
CN201810523138.8A 2018-05-28 2018-05-28 A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction Pending CN108628536A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810523138.8A CN108628536A (en) 2018-05-28 2018-05-28 A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810523138.8A CN108628536A (en) 2018-05-28 2018-05-28 A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction

Publications (1)

Publication Number Publication Date
CN108628536A true CN108628536A (en) 2018-10-09

Family

ID=63690334

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810523138.8A Pending CN108628536A (en) 2018-05-28 2018-05-28 A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction

Country Status (1)

Country Link
CN (1) CN108628536A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110303209A (en) * 2019-07-02 2019-10-08 东莞市迪蒙数控机械有限公司 Automatic control method for control process of electric spark forming machine

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN203433511U (en) * 2013-08-12 2014-02-12 昆明理工大学 Parameter setting system under intelligent control of singlechip microcomputer
CN105278437A (en) * 2014-06-16 2016-01-27 上海宝信软件股份有限公司 Modbus RTU/ASCII protocol realization method based on S7-300/400 PLC
CN206077426U (en) * 2016-10-13 2017-04-05 余大庆 Single-chip microcomputer LAN control system based on MODBUS RTU communications protocol
CN106569440A (en) * 2016-10-25 2017-04-19 宁波中车新能源科技有限公司 Method for achieving communication between microprocessor and touch screen based on MODBUS-RTU protocol
US20170109132A1 (en) * 1999-06-10 2017-04-20 West View Research, Llc Computerized information and display apparatus with automatic context determination

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170109132A1 (en) * 1999-06-10 2017-04-20 West View Research, Llc Computerized information and display apparatus with automatic context determination
CN203433511U (en) * 2013-08-12 2014-02-12 昆明理工大学 Parameter setting system under intelligent control of singlechip microcomputer
CN105278437A (en) * 2014-06-16 2016-01-27 上海宝信软件股份有限公司 Modbus RTU/ASCII protocol realization method based on S7-300/400 PLC
CN206077426U (en) * 2016-10-13 2017-04-05 余大庆 Single-chip microcomputer LAN control system based on MODBUS RTU communications protocol
CN106569440A (en) * 2016-10-25 2017-04-19 宁波中车新能源科技有限公司 Method for achieving communication between microprocessor and touch screen based on MODBUS-RTU protocol

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
林填达等: "基于Modbus协议的STM32与触摸屏通讯的实现", 《自动化与仪表》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110303209A (en) * 2019-07-02 2019-10-08 东莞市迪蒙数控机械有限公司 Automatic control method for control process of electric spark forming machine

Similar Documents

Publication Publication Date Title
CN100524122C (en) Bus controller for numerical control system of full digital ring bus
CN102662835B (en) A program debugging method for an embedded system and the embedded system
CN101771700B (en) Modbus protocol communication node based on FPGA
CN105353715A (en) Realization method of logic control of VB/VC (Microsoft Visual Basic 6.0/Microsoft Visual C++) and PLC (Programmable Logic Controller) on the basis of serial communication
CN100504688C (en) A dedicated chip to realize the function of the bus controller in the ring bus numerical control system
CN104504974A (en) Experiment instrument for designing and developing single-chip microcomputer
CN110262425A (en) A kind of induction heating dcs
CN101706762A (en) Intelligent type signal transfer system
CN115033444B (en) 8051 core-based online debugging circuit control device
CN106444657A (en) Modbus main station command processing method and master station controller
CN108847869A (en) Portable multifunctional electric power analog channel test device and its test method
CN115328710A (en) Qt-based radio frequency automatic test method
CN103699051A (en) Wireless telecontrol system
CN111008102A (en) FPGA accelerator card high-speed interface SI test control device, system and method
CN108628536A (en) A kind of STM32 and serial ports touch screen communication module of man-machine interface interaction
CN202421854U (en) Triplex level redundancy switching value output module for DCS (data communication system)
CN102193860B (en) Microcontroller online debugging circuit and method as well as microcontroller
CN100487615C (en) Single-line two-way communication method of reorganizable controller
CN112114899A (en) Chip debugging system and debugger
CN202677376U (en) Device for downloading chip programs
CN205091732U (en) Automatic switching device for USB interface
CN118260230A (en) HDLC communication controller with cross RS485 bus fast data forwarding function
CN102622937A (en) Robot demonstrator
CN206431814U (en) Infrared chip test platform based on FPGA
CN214278732U (en) Programmable heat supply network concentrator

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20181009

RJ01 Rejection of invention patent application after publication