EnviroDIY / SensorModbusMaster

An Arduino library to act as Modbus Master to control a sensor/slave
https://envirodiy.github.io/SensorModbusMaster/
BSD 3-Clause "New" or "Revised" License
48 stars 23 forks source link

Arduino hangs on any read attempt #10

Open saspol opened 5 years ago

saspol commented 5 years ago

Hi, i trying to use this library on Mega:

HardwareSerial modbusSerial = Serial2; modbusMaster modbus;

modbusSerial.begin(2400); modbus.begin(101, modbusSerial); float val = modbus.uint16FromRegister(0x04, 1, bigEndian); TTL to RS485 adapter blink 8 times TX on boot, then Mega hangs on any type read register attempt. Any suggestion how to debug this?
SRGDamia1 commented 5 years ago

Definitely use the setDebugStream function.

If you have a second mega or any other board I would also try spying on the serial communication. That is, run your first mega with your desired program connected to your RS485 adapter and your modbus device. On your second mega connect the Rx of Serial1 to the Tx of the RS485 adapter, the Rx of Serial2 to the Rx of the adapter. Then run a very simple program that mirrors both back to the terminal: while (Serial1.available()) Serial.print(Serial1.read()); while (Serial2.available()) Serial.print(Serial2.read());