RS485 data missing

Dear ALL,

I am using modbus rtu library.I have attached my code for reference below.The code tested with 9600 baudrate . I no data being lost while transmission while 9600 baudadrate. we connected slave in below passion . where device 1 and 3 communicating properly where other data found lost of data.

The device seems working fine individually.when connected in desi chain passion it gives loss of data.

I also try to change baud rate . but change in baud rate not even communicating in modscan32. Please suggest what i need to make it work.

How change baud rate in code. and make it work

#include <avr/wdt.h>
#include"glob.h"
Modbus *slave = 0;
int8_t state = 0;
uint16_t au16data[30];
float MINV_RANGE = 0.5;
//float MIDV_RANGE1=1.875;
float MAXV_RANGE = 4.5;


int SPD;
int DISCONNECTOR;


int array[8][3] = {
  {
    0, 0, 0
  }
  , {
    0, 0, 1
  }
  , {
    0, 1, 0
  }
  , {
    0, 1, 1
  }
  , {
    1, 0, 0
  }
  , {
    1, 0, 1
  }
  , {
    1, 1, 0
  }
  , {
    1, 1, 1
  }
};
void Take_Reading() {

  for (int row = 0; row < 8; row++)
  {
    //   // get rid of me:
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    delay(50




      );
    analog_1_pv[row] = ANALOG_SCALING * analogRead(A0);
    analog_2_pv[row] = ANALOG_SCALING * analogRead(A1);
    analog_3_pv[row] = ANALOG_SCALING * analogRead(A2);
    if ( (analog_1_pv[row] <= MINV_RANGE || (analog_1_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value1[row] =  0.0;
    }
    else
    {
      Current_Value1[row] =  (analog_1_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_2_pv[row] <= MINV_RANGE || (analog_2_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value2[row] =  0.0;
    }
    else
    {
      Current_Value2[row] =  (analog_2_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_3_pv[row] <= MINV_RANGE || (analog_3_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value3[row] =  0.0;
    }
    else
    {
      Current_Value3[row] =  (analog_3_pv[row] * 12.5) - 31.25;

    }


    Mod_current[row] = (uint16_t)(Mul_Factor * Current_Value1[row]);
    Mod_current[row + 8] = (uint16_t)(Mul_Factor * Current_Value2[row]);
    Mod_current[row + 16] = (uint16_t)(Mul_Factor * Current_Value3[row]);


  }



}


void modbus_call() {

  /*  for (int i = 0; i < 8; i++)
   {
   au16data[i] = Mod_current[i];
   au16data[i + 8] = Mod_current[i + 8];
   au16data[i + 16] = Mod_current[i + 16];
   }*/

  au16data[0]= Mod_current[0];
  au16data[1]= Mod_current[1];
  au16data[2]= Mod_current[2];
  au16data[3]= Mod_current[3];
  au16data[4]= Mod_current[4];
  au16data[5]= Mod_current[5];
  au16data[6]= Mod_current[6];
  au16data[7]= Mod_current[7];


  au16data[8]= Mod_current[8];
  au16data[9]= Mod_current[9];
  au16data[10]= Mod_current[10];
  au16data[11]= Mod_current[11];

  au16data[12]= Mod_current[23];
  au16data[13]= Mod_current[22];
  au16data[14]= Mod_current[21];
  au16data[15]= Mod_current[20];

  au16data[16]= Mod_current[19];
  au16data[17]= Mod_current[18];
  au16data[18]= Mod_current[17];
  au16data[19]= Mod_current[16];
  au16data[20]= Mod_current[15];
  au16data[21]= Mod_current[14];
  au16data[22]= Mod_current[13];
  au16data[23]=Mod_current[12];

  au16data[24] =(uint16_t)temp_int;
  au16data[25] = ID_Check();
  au16data[26] = SPD;
  au16data[27] = DISCONNECTOR;
  au16data[28] = HV_Reading;
  //  au16data[28] =(100*ID_Check())+( 10*SPD)+(1*DISCONNECTOR);
  // au16data[29]=slave->getInCnt();
  // au16data[30]=slave->getOutCnt();
  //  au16data[31]=slave.getErrCnt();
}



int ID_Check() {

  int ID_value;
  for (int row = 0; row < 8; row++)
  {
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    Status_Out[row] = digitalRead(Output_Read);

  }

  ID_value = 1 * Status_Out[7] + 2 * Status_Out[6] + 4 * Status_Out[5] + 8 * Status_Out[4] + 16 * Status_Out[3] + 32 * Status_Out[2]
    + 64 * Status_Out[1] + 128 * Status_Out[0];
  //  ID_value = 1 * Status_Out[0] + 2 * Status_Out[1] + 4 * Status_Out[2] + 8 * Status_Out[3] + 16 * Status_Out[4] + 32 * Status_Out[5
  + 64 * Status_Out[6] + 128 * Status_Out[7];

  return (ID_value);

}

void setup()
{
  wdt_enable(WDTO_8S);

  //analogReference(INTERNAL);

  pinMode(3, OUTPUT);
  pinMode(SO_enable, OUTPUT) ;// pin can enable/disable using digital IO 7 of arduino
  pinMode(S1_enable, OUTPUT) ;// pin can enable/disable using digital IO 6 of arduino
  pinMode(S2_enable, OUTPUT) ;// pin can enable/disable using digital IO 5 of arduino
  //  pinMode(Enablepin, OUTPUT) ;// pin can enable/disable using digital IO 4 of arduino
  pinMode(A0, INPUT) ;
  pinMode(A5, INPUT) ;
  //spd & DC STATUS
  pinMode(SPD_STATUS_PIN, INPUT);
  pinMode(DC_STATUS_PIN, INPUT);

  if (millis() < 5000)
  {
    Device_ID = ID_Check();
  }
  slave = new Modbus(Device_ID, 0, 0);
 [b] slave->begin(9600);// here i am changing slave baudrate[/b]
  // Serial.begin(9600);
}



void loop() {
  wdt_reset();

  //  int Get_ID=getID();
  Device_ID = ID_Check();
 Take_Reading();
  temp_int=Take_Temp_Reading();
  SPD= SPD_Check();
  DISCONNECTOR=  DC_Status();
  Take_HV_Reading();
  if (slave->getID()==Device_ID)
  {
   // wdt_reset();
    modbus_call();
   // slave->setTimeOut(500);
  }
  slave->poll( au16data, 30 );
  // Print_Result();

}

Code_2016.zip (8.87 KB)