MODBUS implementation in STM32F103C8T6 with STM32 official core in Arduino IDE

Post here first, or if you can't find a relevant section!
Post Reply
mustaq_ahm
Posts: 31
Joined: Tue Sep 14, 2021 11:08 am
Answers: 2

MODBUS implementation in STM32F103C8T6 with STM32 official core in Arduino IDE

Post by mustaq_ahm »

Hello all,
Good Day!

I have came here several times, and and asked some question here is overview of what I have in my mind and my questions.

I am working on my Master Thesis. I would like to implement Modbus RTU protocol using RS485 UART serial communication between four STM32F103C8T6 with STM32 official core in Arduino IDE.

I have some questions!

1. Is there a full-fleged libary for Modbus RTU protocol using RS485 UART serial communication as mentioned in Modicon Modbus Protocol Reference Guide official document (https://www.modbus.org/docs/PI_MBUS_300.pdf)? Literally the whole implementation of Modbus RTU protocol using RS485 UART serial communication for both Master and Slave (Start->Address->Function Code->Data->CRC->Stop) .

*. From my understanding about MODBUS, it is possible to communicate between one Master microcontroller with several other slave microcontrollers. Also it is possible to Broadcast the message or request from master to to all slave microcontrllers


2. If so how can I broadcast the message from Master microcontroller to all the slave microcontrollers? I want to implement this in STM32f103C8T6 to send message to all my slave STM32F103C8T6 microcontrollers. And I want to get back the response from only one slave with the 10 sensor data values. Is this fesible through MODBUS? If yes, let me know how? If no, let me know why?

3. If it is fesible, will there be any collision? If yes, let me know why? If no, let me know how?

My hardware is fixed I can not change anything from my hardware part. I have started my Thesis in company in the software part in programming the STM32F103C8T6 with stm32 official core in Arduino IDE. So, I have four similar PCB board with STM32F103C8T6 have some temperature sensor's, LED's, motors's, PWM generator's. My goal is to make one microcontroller as Master and other three as Slave. And Master should be having HMI (Human Machine Interface.). All the slave microcontrollers will have the same funtionalities as Master except HMI.

My processes should look similar to this:
i. I should be able to give Inputs or set some limits or something like that from HMI to Master microcontroller.
ii. The limits or inputs or whatever must be set in the Master microcontroller and from Master microntroller all those inputs or limits must be set for Slave microcontrollers as well.
iii. Then the Master microntroller should be able to send the broadcast request or message to all the slave microcontrollers to get all the data's.
iv. Then the Master microcontroller must get all the sensor values or states of the LED's or Motor's or whatever from Master microcontroller itself.
v. Then, all this data's to be stored sepeartely in Master microntroller.
vi. (from iii.) When the Master microntroller has sent the broadcast request or message to all the slave microcontrollers. (same as iv. for slaves) Then all the slave microcontrollers must get all their sensor values or states of the LED's or Motor's or whatever from themself. (same as v. for slaves) And stored sepeartely in them itself.
vii. Then Master microcontroller should send request or message to each slave microcontroller, one after one to get the stored values or states of the LED's or Motor's or whatever from the Slave microcontroller to the Master microcontroller.
viii. Then there must be over all check in the Master microcontroller to check all data is available for HMI.
ix. If something is missing then the Master must get the missing data from itself or from slaves.
x. Then the Master to should send all the data to HMI from Master Microcontroller.

So, basically I will be controlling the whole thing with HMI having my Master microntroller connected to it and all other Slave microcontrollers connected to Master microcontroller.

4. Is it possible to do my whole above process in 500 milliseconds? If yes, let me know how? If no, let me know why?

5. How much time will take for the whole process in your opinion?

6. Is there any examples of implementing all these?

7. What are difficulties I might face?

8. For what I must be prepared?

Fow each how and why question please try to give atleast minimum description please.

Your answers will be really helpfull for my thesis. Let me know your suggestions, oppinions, and guidence. I would like to here from all of you. Thanks in Advance.

Greeting,
Mustaq.
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: MODBUS implementation in STM32F103C8T6 with STM32 official core in Arduino IDE

Post by ag123 »

My guess is there are probably commercial implementations and that they may not sell you the codes, depending on the commercial terms of those selling that. PLC and SCADA isn't a 'new' thing really, even simple production lines say a conveyor belt sorter probably use something like this.

Have you tried out the sources as suggested by fpistm?
viewtopic.php?p=8578#p8578

Note that some of them may not be offered for commercial implementations, e.g. GPL etc. e.g. you may need to open source your codes if you implement them. And for others it is strictly non-commercial. So you would need to contact the authors.

On another note, since you have the specs, you can probably write your own implementation and I think it isn't after all that difficult.
I looked at MAX485 and RS-485. It is actually a bus architecture. What it takes is that only 1 device on the RS-485 bus can 'speak' at any one time. All that means is that you need to enable the Driver Output on MAX485 each time before transmit and disable it again after sending. This applies to all devices on the bus.

The rest are protocol matters which you can implement based on the specs.
mustaq_ahm
Posts: 31
Joined: Tue Sep 14, 2021 11:08 am
Answers: 2

Re: MODBUS implementation in STM32F103C8T6 with STM32 official core in Arduino IDE

Post by mustaq_ahm »

Have you tried out the sources as suggested by fpistm?
viewtopic.php?p=8578#p8578
I am on it. But, I am still trying to understand the whole working process and coding. But you people really gave me great insights for future approach to my thesis.
This looks good. But, I have to check it out.

Anyways thanks all for replying my queries by spending your time and energy for me. And sorry for my delay to reply you back.
Post Reply

Return to “General discussion”