I am sending and receiving data to a Modbus slave using main Serial port of Arduino uno through TTL RS 485 converters.
The data is successfully received by the Slave and returns a reply.
The reply reaches the RX pin (D0) but the Serial.available() is always Zero. Serial.Read() returns only Zeros.
Simultaneously connected the Rx pin to another TTL to USB converter and monitored the data and it shows correct data.
What can be the mistake.
Durgaidass
In a half-duplex communication a sender has to be selected and allowed to put its output on the bus. AFAIK a Modbus slave will turn on its output driver in response of a message to its Modbus address. For that time you have to disable your RS-485 line driver and enable the receiver.
Hi DrDiettric, Thanks for the response.
RS485 is working OK. Because the desired output goes to the Modbus simulator and the response is reaching the RX (D0) Pin of UNO.
But the Serial.available() is always ZERO.
result = node.readCoils(1, 16);
// delay(100);
ASerial.print(Serial.available());
ASerial.print(result);
/////////////////////////////////////////////////////
if (result == node.ku8MBSuccess)
{
for (j = 0; j <= 6; j++)
{
// Serial.flush();
if (Serial.available()) {
//delay(1);
rec_buf[j] = Serial.read();
ASerial.println( Serial.read());
}
}
// ASerial.write((char)rec_buf[6]);
ASerial.write('K');
}
Hi noiasca
In this ASerial.print(result); prints the correct response.
When I connect the Rx Pin(D0) of UNO to a serial monitor through TTL -RS485-USB in a PC, the desired data is shown. But in my code the Serial.read() buf is always ZERO as if Receiver is disabled.
Thanks
Hi
When in actual code code I will use only the rec_buf[j] only. Now for testing purpose I used direct print. with this it should give correct response at least for 3 itterartions.
Thanks
ok, think i see your issue..
be nice to see the whole sketch..
thinking you got the Serial object linked to a modbus object (node)..
not sure what modbus lib your using but you get the response from the node not the attached Serial object..
something like..
node.getResponseBuffer(0);
but again, this really depends on the lib used..
but yeah, the Serial object should always be emptied by the modbus object..
Hi Qubits-us Thanks for the information.
Actually that was the mistake I was doing.
Since the expected reply was reaching the Rx PIN, I was trying to read the Serial object.
Now I am getting the correct information from node object.