I am developing an application to get data using Modbus protocol and upload it to IoT platform using MQTT.
I am using PlatformIO with Arduino framework.
The modbus library used is the one from the user https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino.
I use the ESP32-POE Module and the Serial1 port of the UEXT to communicate with the MOD-RS485 module as well as the SD card to store information from Jsons using the SD_MMC.h library.
I have desoldered the SCL/SCK jumper.
To create Modbus, I use the class constructor, "Modbus master(0, Serial1, 5)" as a global variable, where 5 is the pin for SS of the UEXT.
Inside a function, but it is not setup(), I call Serial1.begin(9600) and master.start().
The workflow is:
- Create Thread Queue.
- Create Event
- Register event callback function.
- Create timer (freeRTOS) to add a thread to a thread queue.
- When timer is triggered make a post to the event to call the callback.
- The callback function reads Modbus and sends via MQTT.
The problem is that Modbus only reads correctly the first time, the rest of the calls always return an error.
The moment there is an error it is unable to read a value correctly again.
I have tried to use higher timeouts but nothing.
The value of T35 is 5 ms, although I have tried 4 and higher values up to 35ms.
Doing some debugging on Serial1, there seems to be a lot of noise.
did you get any further here?
I would also read and write Modbus RTU devices via Olimex products.