Jema8513
Dear,

I'm running a very simple openplc V4 program on a ESP32-S3-Supermini board. I send the program with a CH340 USB-TTL adapter from my Pc. Tx Rx pins are 43 and 44, and the program is writed and running well, One output follow the state of one input as expected.

I tested Modbus TCP and it is ok, but If I try Modbus RTU I'm always getting a Time out error, doesn't matter the Modbus program I use to test.
 
I've checked UART params many times.
 
I'm sure that serial is working because I'm programing the board with this interface.
 
Could be that by default Modbus RTU serial uses other GPIO pins rather than 43/44 ?

I tested Serial1, 2, and 3.
 
Thanks
Reply 0 0
Jema8513
I've found that by default OpenPLC Modbus RTU uses pins 19/20 on ESP32-S3 that are tied to USB connector (without any uart chip). ESP32-S3 has a native USB interface.

Programing it with USB cable then now I can send and receive Modbus commands from my Pc.
 
As those boards have the U0Rx and U0Tx on pins 43/44, how can I use those pins for Modbus RTU. I want to develop a board based on this ESP32-S3-Supermini and there isn't any access to pins 19/20 rather the native USB connector.
 
Thanks
Reply 0 0
thiagoralves
OpenPLC uses whatever default is set for Arduino API Serial.begin(). To change the pins you would need to edit the runtime code to call something else in place of Serial.begin().
Reply 1 0
Jema8513
How to do that, please ?

Are there any place to select the pins associated ti Serial1, 2, etc ?
Reply 0 0
Programador s7
It would be interesting if it had the HSerial option for serial hardware and allowed to manually define Rx and Tx.
Reply 0 0
thiagoralves
The runtime code is strictly Arduino code, so one could simply modify it to initialize the port with the specific pins the same way as you would do on Arduino IDE.
Reply 1 0
Jema8513
You mean that I can modify the source code of my OpenPLC project (runtime code) before compiling defining serial begin pins and then compile and download it to ESP32, isn't it ?
 
Where can I find the source code of my project ?

How to compile it with my mods ? Arduino IDE ?
 
Thanks Thiago
Reply 0 0
thiagoralves
Ideally you need to modify the source code of the editor (the runtime source code lives inside of it) and build a new version of the editor (source here: https://github.com/Autonomy-Logic/openplc-editor). For temporary quick testing you can modify it locally on your openplc editor installation. The runtime source code lives inside sources/arduino on your local installation.
Reply 1 0
Jema8513
Well, finally I've figured out what was happening.
 
For some reason Serial (Serial 0) is using pins 19/20 (USB) even in the Arduino IDE config says that 43/44 must be used.

I've found the folder where GPIO's are defined here:


User\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.8\cores\esp32\

and the file is:

HardwareSerial.h


The config for Serial0 is like this:

#ifndef SOC_RX0
#if CONFIG_IDF_TARGET_ESP32
#define SOC_RX0 (gpio_num_t)3
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define SOC_RX0 (gpio_num_t)44
#elif CONFIG_IDF_TARGET_ESP32C2
#define SOC_RX0 (gpio_num_t)19

#ifndef SOC_TX0
#if CONFIG_IDF_TARGET_ESP32
#define SOC_TX0 (gpio_num_t)1
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define SOC_TX0 (gpio_num_t)43
#elif CONFIG_IDF_TARGET_ESP32C2
#define SOC_TX0 (gpio_num_t)20

And for Serial1: The pins are 15 / 16

And for Serial2: The pins are 19 / 20

So,I've just replaced pins 15 / 16 for Serial1 with 43 / 44 and now compiling selecting Serial1 Modbus is running fine.

Still don't know why Serial is not using the right ones !!!

But at least now is working :-) !!!
Reply 1 0
Reply