Skip to content

Conversation

@TienHuyIoT
Copy link

Details:
- _slaveId must be difference 0 value to cleanup function run and return true.
- Not using vTaskSuspendAll() and xTaskResumeAll() by redefine ESP32
to ESP32_REMOVE.
- Update example ESP32-Concurent.ino and using Tool Modbus Slave on
PC for test.

Refs:
- Tool Modbus Slave link: https://www.modbustools.com/download.html
- ESP32 Arduino Release 1.0.6 based on ESP-IDF v3.3.5
https://github.com/espressif/arduino-esp32/releases/tag/1.0.6

@emelianov
Copy link
Owner

Hello @TienHuyIoT ,

  • _slaveId must be difference 0 value to cleanup function run and return true.

It's a bug for sure. But indeed callback for slaveId = 0 doesn't make sense. It will be no response anyway. So I suggest

if (waitResponse && slaveId) {

to fix.

  • Not using vTaskSuspendAll() and xTaskResumeAll() by redefine ESP32 to ESP32_REMOVE.

Another point to discuss. vTaskSuspendAll() and taskENTER_CRITICAL(&mux) are user to prevent task from switching while sending and reading data over UART and switching RX/TX mode (it's required to have control on delays in data flow). For sure it's not the best solution but I'm not ready to go to low level esp32 UART functions (you may refer ESP-IDF Modbus implementation). From other hand it would be great if you can suggest better solution.

  • Update example ESP32-Concurent.ino and using Tool Modbus Slave on PC for test.

That's okey. Thanks.

@emelianov emelianov added this to the 4.0.0 milestone Jun 27, 2021
@TienHuyIoT
Copy link
Author

TienHuyIoT commented Jun 27, 2021

Hi @emelianov ,
I am doing with a device using broadcast ID to get and set itself ID. So, i think with broadcast ID, Modbus Master also need to handle response data from slave to do something.

But indeed callback for slaveId = 0 doesn't make sense. It will be no response anyway

I have reviewed code function ModbusRTUTemplate::task(). To processing response data from slave, _slaveId variable must be not zero. So, it need to have a value than zero or do something another to read all feedback data from slave.

UART and switching RX/TX mode

Arduino flatform don't have implement uart serial class with half-duplex by auto control GPIO DE/RE max485 for modbusRTU.
everyone usually use the uart2Rs485 module or MAX13487E with direction in/out data control automation. So that device don't care about conflict or missing data out. if we want to control data flow, we should be update for serial class to handle or make a event callback for user control it after send out data in Modbus library (just my mindset :D).

@emelianov
Copy link
Owner

I am doing with a device using broadcast ID to get and set itself ID. So, i think with broadcast ID, Modbus Master also need to handle response data from slave to do something.

According to Modbus specification slave must not send any response on broadcast request. (It's absolutely reasonable as it'll be collision on the bus otherwise). That's why I'm insist on dropping callback for broadcasts. (For sure your point is right: existing code lead to memory leek and needs to be fixed)

I have reviewed code function ModbusRTUTemplate::task(). To processing response data from slave, _slaveId variable must be not zero. So, it need to have a value than zero or do something another to read all feedback data from slave.

That's correct behaviour.

Arduino flatform don't have implement uart serial class with half-duplex by auto control GPIO DE/RE max485 for modbusRTU.
everyone usually use the uart2Rs485 module or MAX13487E with direction in/out data control automation. So that device don't care about conflict or missing data out. if we want to control data flow, we should be update for serial class to handle or make a event callback for user control it after send out data in Modbus library (just my mindset :D).

There is MAX-485 and other that required manual data flow control.
Moreover the problem is not about flow control. ESP32 has preemptive multitasking and task can be suspended by RTOS so above mentioned functions are required to prevent task from to be switched/suspended.
I'm not ready for low level ESP32 UART operations so have to left the code as it is.

Details:
    - _slaveId must be difference 0 value to cleanup function run and return true.
    - Not using vTaskSuspendAll() and xTaskResumeAll() by redefine ESP32
    to ESP32_REMOVE.
    - Update example ESP32-Concurent.ino and using Tool Modbus Slave on
    PC for test.

Refs:
    - Tool Modbus Slave link: https://www.modbustools.com/download.html
    - ESP32 Arduino Release 1.0.6 based on ESP-IDF v3.3.5
      https://github.com/espressif/arduino-esp32/releases/tag/1.0.6
@emelianov emelianov force-pushed the Fix_Esp32_Crash_And_Master_Broadcast_ID branch from ecd3167 to 5f81c77 Compare August 1, 2021 12:49
@emelianov emelianov merged commit 4558b58 into emelianov:master Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants