Skip to content

HsienChing/RS-485_Modbus-RTU_Call_Response_and_HMI_Display_with_CRC_for_STM32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RS-485 Modbus-RTU Call Response and HMI Display with CRC for STM32

About the project

The STM32 NUCLEO-F446RE board is used to communicate with the external device through RS-485 Modbus-RTU. The device responses are resolved by the STM32 NUCLEO-F446RE with cyclic redundancy check (CRC) and outputted to the human-machine interface (HMI).

License: MIT Contributor Covenant

Brief description

There are two boards used in this project, i.e., the main and test boards. The main board is the major developing object in this project, providing all required functionalities. The test board is used to simulate the device for testing the functionalities of the main board.

Main board

Suggested board:

  1. STM32 NUCLEO-F446RE
  2. Blue Pill (STM32F103C8T6)

Suggested development environment:

  1. STM32CubeIDE

Purpose:

  1. Send Modbus-RTU command to the device through RS-485 via the UART1.
  2. Get responses from the device through RS-485.
  3. Send the device responses to the human-machine interface (HMI) via the UART3.
  4. Users can monitor the device responses from the STM32CubeIDE console monitor (or other serial monitor) via UART2.

Suggested hardware setup:

  1. UART1: A "RS-485 to TTL module" is used to convert the RS-485 signal because STM32 NUCLEO-F446RE (and Blue Pill) does not support RS-485 directly.
  2. UART3: A HMI with the UART interface is used to show the device responses through the UART3.

Suggested software (STM32CubeIDE) setup:

  1. Pinout & configuration/Connectivity
    1. Turn on USART1, Mode: Asynchronous, Basic parameters: 9600 8N1
    2. Turn on USART2, Mode: Asynchronous, Basic parameters: 115200 8N1
    3. Turn on USART3, Mode: Asynchronous, Basic parameters: 115200 8N1

Suggested library for calculating CRC:

  1. The CRC 16 calculation function is available from Lammert Bies, https://github.com/lammertb/libcrc .
  2. On-line CRC calculation and free library, https://www.lammertbies.nl/comm/info/crc-calculation .
  3. The key files of the library used in this project is put in the library.

Notice:

If the following problems happen during compiling by STM32CubeIDE, go to "Project > Properties > C/C++ Build > Settings > Tool Settings > MCU Settings" and then check the box "Use float with printf from newlib-nano (-u _printf_float)."

1. The float formatting support is not enabled, check your MCU Settings from "Project Properties > C/C++ Build > Settings > Tool Settings", or add manually "-u _printf_float" in linker flags.	main.c	/F103C8_UART_HMI/Core/Src	
2. Problem description: The float formatting support is not enabled, check your MCU Settings from "Project Properties > C/C++ Build > Settings > Tool Settings", or add manually "-u _printf_float" in linker flags.

Test board (device simulator)

Suggested board:

  1. STM32 NUCLEO-F446RE
  2. Blue Pill (STM32F103C8T6)

Suggested development environment:

  1. STM32CubeIDE

Purpose:

  1. Receive Modbus-RTU command from the main board through RS-485 via the UART1.
  2. Generate the Modbus data with CRC and counting value.
  3. Send the Modbus data back.

Suggested hardware setup:

  1. UART1: A "RS-485 to TTL module" is used to convert the RS-485 signal because STM32 NUCLEO-F446RE (and Blue Pill) does not support RS-485 directly.

Suggested software (STM32CubeIDE) setup:

  1. Pinout & configuration/Connectivity
    1. Turn on USART1, Mode: Asynchronous, Basic parameters: 9600 8N1

Suggested library for calculating CRC:

  1. The CRC 16 calculation function is available from Lammert Bies, https://github.com/lammertb/libcrc .
  2. On-line CRC calculation and free library, https://www.lammertbies.nl/comm/info/crc-calculation .
  3. The key files of the library used in this project is put in the library.

Usage

  1. Setup the "Pinout & configuration" of the boards by STM32CubeIDE.
  2. Copy and paste the source code into the file ProjectFolder/Core/Src/main.c .

The source codes are in the code directory. Example: "Main board - STM32 NUCLEO-F446RE" means that the STM32 NUCLEO-F446RE is used as the main board.

Main board - Blue Pill (STM32F103C8T6)

# Source file Date
2 Main_Modbus_HMI_BluePill_v02.c 2021-09-17
1 Main_Modbus_HMI_BluePill_v01.c 2021-09-15

Main board - STM32 NUCLEO-F446RE

# Source file Date
2 Main_Modbus_HMI_F446RE_v02.c 2021-09-17
1 Main_Modbus_HMI_F446RE_v01.c 2021-09-14

Test board - Blue Pill (STM32F103C8T6)

# Source file Date
1 Test_Modbus_HMI_BluePill_v01.c 2021-09-14

Test board - STM32 NUCLEO-F446RE

# Source file Date
1 Test_Modbus_HMI_F446RE_v01.c 2021-09-15

License

Distributed under the MIT License.

Contact

Author: Dr. Hsien-Ching Chung

ORCID: https://orcid.org/0000-0001-9364-8858

Project Link: https://github.com/HsienChing/RS-485_Modbus-RTU_Call_Response_and_HMI_Display_with_CRC_for_STM32

Acknowledgements

H.C. Chung thanks all the contributors to this project for their valuable discussions and recommendations, especially Jung-Feng Lin, Hsiao-Wen Yang, Yen-Kai Lo, An-De Andrew Chung.

This work was supported in part by Super Double Power Technology Co., Ltd., Taiwan under grant SDP-RD-PROJ-001-2020.