Showing results for 
Search instead for 
Did you mean: 

How to implement MODBUS protocol communication using UART in STM32L151RCT6 MCU

Associate III


I am using the STM32L151RCT6 in STM32cube IDE, i need to create MODBUS protocol communication between MCU and other board as slave..

Please suggest me any related link for implement this..

it will be helpful for me...

Associate III

A pretty good implementation of the modbas protocol can be found here:

Here's the documentation for it:


I need to configure the RTU MODBUS Slave with RS485 communication in my application.

I referred the below link for implementation :

I got example codes and tried to implement one example .

But in this examples he is passing the 16 bit unsigned integer from slave, i need to pass 32 bit integer and float also.

How it is possible to pass the 32 bit integer and float values from the MODBUS slave??

please help me to resolve this....

Associate III

In my opinion, the only possible solution is to divide the 32 bit integer value into two 16 bit ones and store them in separate registers of slave device, keeping in mind where the low and high word is. When reading by the master, both 16 bit words should be combined into one 32 bit value.

The same approach should be applied to float values.

OK thanks for reply.

I will try and tell you about that.

One more thing i have requirement of upgrading firmware through MODBUS..

It is like Slave device firmware i need to upgrade through MODBUS.

Is there any related link ??

please suggest me any links or examples on this..

Associate III

Unfortunately, I don't know of any solution to this problem.

Modbus has no device update capability.

This requirement is uneasonable.

Ok fine .

Can you suggest me how to achieve?

function code 06(Write single) and function code 16(Write Multiple) .

From this i may achieve my requirement..

These features are available in the implementation I indicated earlier.


I tried to split the 32 bit integer value in to two - 16 bit values like this.

32 bit A = 0x12345678

16 bit MSB = A & 0xFFFF0000 (i.e 12340000)

MSB = MSB>> 16(i.e 00001234)

register 1 = MSB

16 bit LSB = A & 0x0000FFFF(i.e 00005878)

register 2 = LSB

like this if i followed for float means how to handle the mantissa and exponential part ??

float and 32 bit integer are different types of data how both follows same method??

please help me to clarify this