Elliot
Is it possible to use a STM32 board as a slave device with the Win webserver?
What should I do with the .st program and hardware layer?
it seems that I managed to connect my board with the PC webserver with modbus RTU but I don't know how to use it, for example, write some output to the pins on the board.
And I'm confused about the address mapping of modbus. What does the "modbus address" acturally mean? a persistant storage or what? and is it possible to map some output to pins?
thiagoralves
Watch this video:
https://youtu.be/dQ8GcfpGDuA

The procedure would be the same, but instead of writing the blank project to an Arduino Uno, you would write it to your STM32. Then when adding the slave device, you will have to pay attention to the number of IOs on the STM32 versus the template for the Uno.
Reply 0 0
Elliot
@thiagoralves Thank you so much for your help and I will try to get my board work with the tutorial
But I still have some questions.
1: It said that I should upload a blank program to the slave device, is that mean that the OpenPLC runtime is responsible for handling Modbus requests?
2: how can I connect my STM32 board to the modbus master?
Since in the arduino Uno example I saw you just use one cable. I guess I'm supposed to use serial port to connect and I'm using a USB-TTL serial converter to connect my board to PC, so how can my board receive Modbus requests?
Reply 0 0
thiagoralves
1. Yes. Uploading a blank program means you will have OpenPLC Runtime running on your STM32 with no specific logic tied to it (blank), making it a dumb slave.
2. Just as you saw on the video, you simply add your board to the slave devices tab. I'm assuming you want to connect your board to another OpenPLC Runtime running as master. If you want to connect it to any other modbus master, than instructions will vary according to the modbus master you're using
3. OpenPLC Runtime running on the STM32 can handle modbus requests over serial only. Boards that have native Wi-Fi or Ethernet support (like esp8266) can handle modbus requests over serial, Wi-Fi or Ethernet.
Reply 0 0
Tarik2511
That is, stm32f103 does not support ethernet in openplc? Modbus tcp slave
Reply 0 0
thiagoralves
stm32f103 by itself does not support Ethernet. If you add Ethernet through a W5500 chip it might work.
Reply 0 0
Tarik2511
And how is the slave id configured in modbus tcp
Reply 0 0
thiagoralves
Modbus TCP does not have slave id. Devices are addressed via IP 
Reply 0 0
Tarik2511
Thanks for the answer. I connected w5100 and w5500 modules to stm32f103c8t6 ethernet, it did not start. I understood that in this file C:\Users\Admin\OpenPLC_Editor\editor\arduino\examples\Baremetal you need to change ethernet.h or ethernet2.h depending on the use of ethernet module w5100/5500. Tested w5100 and w5500 on arduino mega and uno, works. It doesn't work on stm32f103 for some reason, although there is ping. Thank you for such a good openplc program, later I will try modbus tcp on raspberry pi zero w2
Reply 0 0
Tarik2511

int PWDC = 0;
void setup()
{
TCCR2A = 0x00;
TCCR2B = 0x07;
TIMSK2=0x01;
TCNT2=100;
}
void loop()
{
PWDC = 0;
}
ISR(TIMER2_OVF_vect)
{
TCNT2=100;
if(PWDC >= 100)
{
asm volatile ("jmp 0x0000");
}
else
{
PWDC = PWDC+1;
}
;
}
[CODE][/CODE]


Reply 0 0
Tarik2511
This is part of the program for watchdog arduino mega I understood that the easiest method is to insert the code into C:\Users\Admin\OpenPLC_Editor\editor\arduino\examples\Baremetal 
Reply 0 0
Tarik2511
Thanks for the answer. I connected w5100 and w5500 modules to stm32f103c8t6 ethernet, it did not start. I understood that in this file C:\Users\Admin\OpenPLC_Editor\editor\arduino\examples\Baremetal you need to change ethernet.h or ethernet2.h depending on the use of ethernet module w5100/5500. Tested w5100 and w5500 on arduino mega and uno, works. It doesn't work on stm32f103 for some reason, although there is ping. Thank you for such a good openplc program, later I will try modbus tcp on raspberry pi zero w2
Hello. I managed to run modbus tcp on stm32f103c8t6 on the w5500 module. The problem was that PA4, PA5, PA6, PA7 were used as "Analog In". To use ethernet, you need to go to "Transfer Program to PLC", then in the "I/O Config" menu, in the "Analog inputs" item, delete the PA4, PA5, PA6, PA7 ports.
Reply 1 0
Tarik2511
STM32F1-ethernet-w5500.jpg
Reply 1 0
Reply