Hi,
i am trying to make MODBUS TCP SLAVE code based ESP32 platform.
For modbus_TCP, I use this library: https://github.com/emelianov/modbus-esp8266
Plan is to have one dedicated task only for MODBUS_TCP. Please refer below extraction from compete code :
During testing code is working fine only when mb.task(); is in viod loop(); part. When is in located in Task area (as shown) unfortunately is not running.
Any kind of guidelines/advice how to solve this issue that code will be functional will be appreciated.
Thanks a lot.
Dragan Lukovic
i am trying to make MODBUS TCP SLAVE code based ESP32 platform.
For modbus_TCP, I use this library: https://github.com/emelianov/modbus-esp8266
Plan is to have one dedicated task only for MODBUS_TCP. Please refer below extraction from compete code :
modbus TCP slave Task:
void setup() {
Serial.begin(9600); // Open serial communications and wait for port to open
delay(500);
Ethernet.init(5); // SS pin
Ethernet.begin(mac, ip, SubnetMask ); // start the Ethernet connection
//Ethernet.begin(mac, ip ); // start the Ethernet connection
delay(500); // give the Ethernet shield a second to initialize
modbus_TCP_init_val();
mb.server(502); // Listen TCP server
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// MODBUS TCP TASK ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
xTaskCreatePinnedToCore(
Task_MODBUS_TCP_Service
, "Task_MODBUS_TCP_Service"
, 8192 // Stack size
, NULL // When no parameter is used, simply pass NULL
, 0 // Priority
, &Task_mb_tcp_hdlr // With task handle we will be able to manipulate with this task.
, RUNNING_CORE_1 // Core 1 on which the task will run // pin task to core X
);
delay(500);
}
void loop() {
// [B]mb.task(); // working when unmark comment ![/B]
}
void Task_MODBUS_TCP_Service(void *pvParameters){ // This is a task.
(void) pvParameters;
while(1){ // A Task shall never return or exit.
[B]mb.task(); // when is located here - not working ! [/B]
vTaskDelay(pdMS_TO_TICKS(1));
}
}
Any kind of guidelines/advice how to solve this issue that code will be functional will be appreciated.
Thanks a lot.
Dragan Lukovic