Main Content

Modbus Read

Read data from server device register(s) over RS485 network

Since R2025a

  • MODBUS Read

Libraries:
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F7xx Based Boards

Description

In the Modbus Read block,

  • Client: Read data from a Modbus® server connected on the RS485 network.

  • Server: Reads data from its own registers.

The Modbus Read block outputs the values read as an [Nx1] array of uint16 or logical values based on the register category.

Embedded Coder® Support Package for STMicroelectronics® STM32 Processors supports the Modbus communication protocol over the RS485 network. The client and the server must be connected on the same RS485 network for successful Modbus communication. Each device on the RS485 network is referenced by a unique 8-bit address or identifier.

This table categories the server device registers referenced by the Modbus client device.

Register TypeRegister SizeAllowed Client Operation on Register
Coil1-bitRead and Write
Discrete Input1-bitRead
Holding Register16-bitRead and Write
Input Register16-bitRead

The client can perform either a read or a write operation (depending on the register type) on register(s) of a server device.

Note

Ensure that the number of client write registers does not exceed the server read register count.

To enable the Modbus communication on a particular UART, navigate to the Configuration Parameters > Hardware Implementation > Target hardware resources > USART/UART properties of the model and perform the following:

  1. Enable the Modbus on required USART/UART peripheral.

  2. Select the MODBUS Mode parameter as Server or Client. If you set the MODBUS Mode to Server, configure the registers accordingly.

  3. Select the register type to configure and enter the register address in the Start address field. For more information, see UART/USART.

UART/USART Configuration

Examples

Ports

Output

expand all

The block outputs the data read by the client from the server device register(s) as a N-by-1 vector, where N represents the number of registers on the server device.

  • If you select the Coil or Discrete Input read operations, the client reads the server registers as a 1-bit read operation. The block outputs the read data as Boolean data.

  • If you select the Holding Register or Input Register read operations, the client reads the server registers as a 16-bit read operation. The block outputs the read data as uint16 data.

Data Types: Boolean | uint16

Parameters

expand all

Select the Modbus read block type.

Enter the unique 8-bit Modbus server address or identifier to identify the server from which the client reads the data.

Select the server register on which you want to perform read operation. Specify any one of the following:

  • Coil: Read data from the coil register starting at the address specified in the Coil Address parameter.

  • Discrete input: Read data from the discrete input register starting at the address specified in the Discrete Input Address parameter.

  • Holding register: Read data from the holding register starting at the address specified in the Holding Register Address parameter.

  • Input register: Read data from the input register starting at the address specified in the Input Register Address parameter.

Specify the start address to execute the read operation. Use zero-based indexing; for example, to read from the 10th location, specify the value as 9.

Specify the number of registers the client reads data from. For example, for the client to read data from the coil registers with location ranging from 10 to 14, enter 5.

Configure the USART or UART module for MODBUS communication.

To enable read of a particular register, navigate to the Configuration Parameters > Hardware Implementation > Target hardware resources > USART/UART properties.

Amount of time in seconds that the model waits for data during each simulation time step.

Enter the time interval (in seconds) at which the client reads data from the server device register(s).

Version History

Introduced in R2025a