STM32F103, FreeModbus slave station design (5)-How to add FreeModbus code to keil work

Keywords: Modbus FreeModbus STM32F103C8T6 CubeMX transplantation

Summary: STM32F103, FreeModbus slave station design (5)-How to add FreeModbus code to keil. Explain in detail how to obtain the freemodbus code, the general structure of the code, and how to add freemodbus to the keil project. Explained the precautions, a full actual demonstration, and it is actually available.

1. premise

(1) Pin configuration

figure 1

(2) Peripheral resources

figure 2

2. FreeModbus protocol code added

(1) Get the code

The latest FreeModbus protocol code can be downloaded on its official website. Kong Binghuo (WeChat public account: Kong Binghuo) reminds that it is the free version that only supports the slave station. The version that supports the master station is charged.

image 3

(2) Add code to the project

In the Freemodbus code, you need to copy the two folders modbus and demo. Copy the entire modbus folder to the project directory, copy the port folder in demo-bare to the project directory, and copy the demo in demo-bare. c copied to the Src folder of the project directory, Kong Binghuo (WeChat public number: Kong Binghuo) renamed it: modbus_app.c, as shown in Figure 4.

Figure 4

Create a new Group in the keil project, name it: modbus, add all files in the modbus folder to it, then create a new Group named prot, add all files in the port folder to it, and add modbus_app.c to it In the existing Group named Application/User, as shown in Figure 5.

Figure 5

(3) The header file contains path modification

In the magic wand option of the project, add all the subfolders added to the project to the include path, as shown in Figure 6.

(4) Compile

Note out the main function in modbus_app.c, because there can only be one main function in a project, and then compile it, there is no error, there are 4 warnings, this will be eliminated after the subsequent code modification.

Figure 6

The design experience sharing of single-chip microcomputer, ARM, fieldbus, PLC, embedded software and hardware, adhering to the concept of "every bit is wisdom", expounding knowledge points based on actual projects, sharing and communicating together



Guess you like

Origin blog.51cto.com/2773203/2573830