Problem in modbus RTU with PLC

hi,
I m using arduino UNO to read delta plc register through RS485. M using Simple modbus master v10 code

#include <SimpleModbusMaster.h>

//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10

#define TxEnablePin 2 
enum
{
  PACKET1,
//  PACKET2,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
unsigned int readRegs[1];

void setup()
{//address for D2 register is 4098(decimal) its hex is 1002
  modbus_construct(packet1, 2, READ_HOLDING_REGISTERS, 4098, 1, readRegs);
  
  modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);

}

void loop()
{
  char i;
 
  modbus_update();
  if(Serial.available() >0);
  {
    Serial.print("requests: ");    
    Serial.println(packet1->requests);
    Serial.print("successful_requests: ");  
    Serial.println(packet1->successful_requests);
    Serial.print("failed_requests: ");  
    Serial.println(packet1->failed_requests);  
    Serial.print("exception_errors: ");  
    Serial.println(packet1->exception_errors); 
    Serial.print(readRegs[0]);
    Serial.println("");
    delay(2000);
  }
}

the output is 0 insted i should get 29H
kindly help for this problem

Thank you
ratna

You might like to try setting your register setting to just 98 as the function code of reading holding registers is based at 4000 already. You are trying to read actual register 8098, which most probably does not exist.

Also, remove any delay(...) for any code you have with Modbus, as it is likely to cause you problems.
Create proper timing loops if you need to have delays.


Paul

hi rockwallaby,

Thanks for ur reply

I tried ur suggestion but the result is same, find the attached image of response. I entered hex value for 4098 address (1002H) with no success in output. My connection is from arduino rx(pin0) tx(pin1) to rx tx of max485 and A,B and gnd to rs485 connection of PLC. Schematic for RS232 to RS485 conversion and vice versa is almost similar to the 2nd image attached. The voltage between A B is 167mv which i guess should be more than 200mv. right????
Also whenever i start communication, transmit led never blinks but receive Led is blinking.
Kindly guide me where i m going wrong.

Thank u
Ratna

hi guys,

Somebody please guide for the problem i m facing. My work has totally stuck due to this. :slightly_frowning_face:

thanks
ratna