Soft square serial screen RK6043A trial --------modbus Rtu+485 development

illustrate

Recently, a vehicle monitoring project used this serial port screen, which is currently being explored, so write a record description.

The screen in hand is a 4.3-inch touch screen, and the interface behind it should support 232 and 485 communication. The current plan is to use the modbus RTU+485 mode.

You can go to the official website to download the software and manual of the serial screen. You need to install an HMI-TFT simulation software. Most of the work is to set the serial screen interface, drag and drop some controls, and set the protocol commands on this software. You can also download sample references.

Create a new project and download it to the serial screen to run

1. Prepare the background picture of the interface. The example is in png format, so here I use the drawing software that comes with Windows. The full-screen size of the 4.3-inch reference example picture is 480*272.


2. Open the HMI-TFT software, click New Project, and then create a new screen.



3. Set the splash screen and baud rate.

    Note : (This step was forgotten when compiling for the first time, resulting in an error in the compilation project)


4. Set the background of the screen, drag four text controls, and set some control parameters. It mainly includes the size, color, alignment of the text font, and whether the text box is in input mode. If it is in input mode, you also need to select the type of keyboard.

Drag the text control to the background image


The setting content of the text control property


5. Because the modbus protocol is to be used, it is necessary to set the protocol (tools in the menu bar --> protocol settings), add variable definitions and logical processing. Bind the control to the variable, after setting, save and compile.

It should be noted in the figure below that the script needs to be enabled , and it is disabled by default. The protocol type selects modbus master, which means the serial screen is the master device. In addition, the unit of the next three time parameters is ms. In order to facilitate the communication with the serial port debugging assistant to manually reply to the protocol, the reply timeout is increased here. When actually communicating with the MCU, it can be reduced.

The following figure shows the binding of variables and controls. In the variable settings, there are many options for the variable type. Here, the holding register (corresponding to modbus function code 0x03) is selected; the slave address is filled in decimal (22), and change to the protocol. The transmission is in hexadecimal (0x16), the variable address can be freely defined, and the slave device can reply according to this address.


The control binding in the figure below is to bind the control in a certain screen to the variable defined above. In this way, when the parameter of the slave device is received and the variable is changed, the display of the control will also change; when the display of the control changes, the variable will also change, and then the changed parameter will be transmitted to the slave device.


When the operation is complete, you need to save and compile


6. Compile the entire project (there is a compile option in the upper left menu bar of the software)

7. Generate the sd card resource package, copy all the generated files to the sd card, then insert the serial screen, power on again, and wait for the update

Select Tools--->Production Wizard, click Generate SD Card Resource Package



Reinsert the copied SD card into the serial screen and power on again.



   Note : There are two problems here. First, after directly copying the generated folder to the sd card, the interface of the serial port screen cannot be updated. Later, it was found that all files can be copied to the root directory of the sd card to be updated normally. The second is that when generating the sd card resource package, all four options are selected. As a result, after the serial port screen is powered on again, the screen is stuck in the check section and an error occurs. Just tick the two above - download image resources and download project settings.

Serial debugging assistant <----modbus----> serial screen

Goal: Use the modbus RTU protocol to change a parameter on the screen through the serial debugging assistant

Description: First of all, the serial port screen acts as a modbus master station, and the display parameters of the controls in the interface need to be updated. It will continuously send polling commands to the slave device, and the slave device will reply to the relevant parameters after receiving it. parameters will be displayed. Here, we must first analyze the command structure principle sent by the master station, so as to facilitate the communication between the serial port screen and other MCUs in the future.

1. modbus RTU format You can find the detailed protocol format on the Internet. Only the function code 0x03 is used here, and the following table is intercepted ( reference 1 )


2. Experimental communication

Connect the serial screen to the computer through a 485 to usb cable. Open the serial port debugging assistant, set the serial port parameters and connect. You will find that the serial port screen actively sends data. Because two variables were set before, two packets of different data are also sent here (not together, there is a certain delay in between). According to the above protocol format, it can be analyzed:

0x16 is the slave device address 22; 0x03 is the function code; 0x00 01 is the register address; 0x00 01 is the read quantity; 0xD6 ED is the CRC check code.


If the message is received immediately (response timeout setting) reply: 16 03 02 00 17 8c 49 (hexadecimal)

It means that 0x00 17 is the data in the serial screen query register 0x00 01, which is 23 (decimal)


The effect is as follows: the temperature changes from 0 to 23



The above are some simple instructions, other complex functions are still being explored.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325577125&siteId=291194637