Post by blankrobot on Aug 19, 2022 18:52:36 GMT
Hi,
I've been attempting to use one of the cores for RTU modbus via rs485 on Serial1, however I've run into a number of different problems.
rs485 chip I'm using is MAX485 (where DE & RE are jumped and connected to digital 12 on arduino, DI & RO are connected to TX1 & RX1, respectively.)
Modbus library I'm using:
github.com/emelianov/modbus-esp8266
Code I used in order to read a single Holding register value from slave ID 3 (should get 0x0, but get 0xE4 (timeout)):
Also tried this library to be sure, but still no data:
github.com/syvic/ModbusMaster
I've been attempting to use one of the cores for RTU modbus via rs485 on Serial1, however I've run into a number of different problems.
- When first attempting modbus, Stream.flush() wasn't being recognized, needed to add it into the core files for Stream.h, despite regular arduino files having it in there as an empty function for "backwards compatability"
- Attempted to run modbus library after changing core files, no longer got errors, but was still not getting data, kept getting read timeout errors
- Tested Serial1 with a simple print hello world while using a TTL->Serial converter, but got no response, however i did get a response from Serial0, however modbus on Serial0 still gave same no-data results
- I suspect the issue to be with the Stream.h library or the Serial.h core files, because the exact same wiring and code on an ordinary arduino mega gives me the expected data
rs485 chip I'm using is MAX485 (where DE & RE are jumped and connected to digital 12 on arduino, DI & RO are connected to TX1 & RX1, respectively.)
Modbus library I'm using:
github.com/emelianov/modbus-esp8266
Code I used in order to read a single Holding register value from slave ID 3 (should get 0x0, but get 0xE4 (timeout)):
#include <ModbusRTU_SB.h>
ModbusRTU mbRTU;
uint16_t x = 1;
void setup() {
SerialASC.begin(9600);
Serial0.begin(9600, SERIAL_8N1);
mbRTU.begin(&Serial0,12);
mbRTU.setBaudrate(9600);
mbRTU.master();
}
void loop() {
mbRTU.readHreg(3, 0, &x,1,cbWrite);
while(mbRTU.slave()) { // Needed for library to actually read/write
mbRTU.task();
yield();
}
delay(50);
SerialASC.println(x);
}
bool cbWrite(Modbus::ResultCode event, uint16_t transactionId, void* data){ //callback function to observe transmission status
SerialASC.print("Request result: 0x");
SerialASC.println(event, HEX);
return true;
}
Also tried this library to be sure, but still no data:
github.com/syvic/ModbusMaster