RS485 Timeout Error

hi guys ,
i have a question. i use modbus to read an analog input or blink a led simple projects. i use usb rs485 converter and connect with arduino as it's supposed to be. sketch is working no problem but while i try the connect modbus it say Timeout error . i changed baud rate, parity or stop bits and try many times but not working. please help.

#include <SimpleModbusSlave.h>
#define LED 9
enum
{
ADC_VAL,
PWM_VAL,
HOLDING_REGS_SIZE // leave this one
};
unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
void setup()
{
modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);
modbus_update_comms(9600, SERIAL_8N2, 1);
pinMode(LED, OUTPUT);
}
void loop()
{
modbus_update();
holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
analogWrite(LED, holdingRegs[PWM_VAL]>>2); // constrain adc value from the arduino master to 255
}

This is the sketch for the slave. What is the master device?

I don't see values defined for ADC_VAL, PWM_VAL, or HOLDING_REGS_SIZE. Where are those values set? What are they?

thank you dude for your answer.
i didnt realize its slave cause i saw examples with this code its not mention its slave or master. master is my pc.i communicate pc and arduino with max485 and usb rs485 converter. i look other examples to got it. are you know good example to be teaching.? thanks again.

I give advice on your next direction as you have not provided a complete description of your project.

What I can say is the MODBUS libraries I have reviewed verge on an advanced topic. There are many out there. None are complete. None are perfect. You will need to review each and decide which one you understand best.

ok i got it i work hard try examples and libraries.thank you for replying.

i communicate pc and arduino with max485 and usb rs485 converter.

If your USB-RS485 converter is a standard model from Ebay or Amazon you probably got one with a CH340/341 chip on it. The driver of these chips don't support any parity or stop bits setting other than 8N1. It's probably not a limitation of the chip but of the driver but as there is no documentation of these chips it's not very probable that the situation will get better.

thank you for reply .
how can i fix it ? i installed new drivers but not changed.its the other code i am trying this its simple but i have still timeout error. arduino is the slave pc master as i said before. is the code wrong or usb485 or another thing. i tried changed device manager adjustment then tried and its same. i dont know what can i do. thanks again. please help .

#include <SimpleModbusSlave.h>
enum
{
HOLDING_REGS_SIZE // leave this one
// total number of registers for function 3 and 16 share the same register array
// i.e. the same address space
};

unsigned int holdingRegs[HOLDING_REGS_SIZE];
void setup() {
// put your setup code here, to run once:
modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);
modbus_update_comms(9600, SERIAL_8N2, 0);
}
void loop() {
// put your main code here, to run repeatedly:
modbus_update();

holdingRegs[0] = analogRead(A0);
}

i try 8N1,8N2,8E1 but not working.

how can i fix it ?

Change every occurrence of "SERIAL_8N2" to "SERIAL_8N1" to set on the Arduino side the only serial configuration the sleazy chip with it's driver is able to set.

If that doesn't help, post links to the hardware you're using and also post a wiring diagram of your complete setup.

thank you for answer.
i tried you said but not worked.i tried 2 arduinos communicate together with simple modbus slave library it's worked but i tried same code with one arduino and pc its not worked i dont got it. is it id definition necessary or something else? . can you help me . thanks again.
#include <SimpleModbusSlave.h>
enum
{
// just add or remove registers and your good to go...
// The first register starts at address 0

//Analog Inputs
ADC_A0,///CHANEL 0
// ADC_A1,
HOLDING_REGS_SIZE // leave this one
// total number of registers for function 3 and 16 share the same register array
// i.e. the same address space
};
unsigned int holdingRegs[HOLDING_REGS_SIZE];
void setup() {
// put your setup code here, to run once:
modbus_configure(&Serial, 9600, SERIAL_8E1, 1, 3, HOLDING_REGS_SIZE, holdingRegs);
//modbus_configure(&Serial, 9600, SERIAL_8E1, 2, 3, HOLDING_REGS_SIZE, holdingRegs);
// modbus_update_comms(baud, byteFormat, id) is not needed but allows for easy update of the
// port variables and slave id dynamically in any function.

}

void loop() {
// put your main code here, to run repeatedly:
modbus_update();
holdingRegs[ADC_A0] = analogRead(A0);
//holdingRegs[ADC_A1] = analogRead(A1);
}

Please edit your answer and insert code tags!!

i tried you said but not worked

No, you didn't:

modbus_configure(&Serial, 9600, SERIAL_8E1, 1, 3, HOLDING_REGS_SIZE, holdingRegs);

SERIAL_8E1 is not the same as SERIAL_8N1.

i tried same code with one arduino and pc its not worked

What software do you use on the PC side? Links!

thank you for your help.
its work now. my connection is wrong. actually its true but there are some tricks . anyway thanks again. and you are right i used 8N1 . thanks dude.