mrbbp:
ok for the bit shift, it make sens but it works only one time, with an array and a modulo it repeats.
try it... it add a 1 to the bit on the left (8th)... the controler don't read it, the value "0x0" become "0x80", it is a printable ASCII value 
and for the advice about delay to disable TX_ENABLE_PIN...
the controler answer with only one command (asking current display adress)
in the Nick's example, there is these line added to avoid this problem...
while (!(UCSR0A & (1 << UDRE0))) // Wait for empty transmit buffer
UCSR0A |= 1 << TXC0; // mark transmission not complete
while (!(UCSR0A & (1 << TXC0))); // Wait for the transmission to complete
This code only works if the last byte has been moved to the hardware USART.
The code previously posted uses SoftwareSerial RS485();
To control the TX_ENABLE_PIN at the correct time:
digitalWrite(TX_ENABLE_PIN,LOW); // into transmit mode
RS485.write("yada");
RS485.flush(); // flush() will wait until the last byte in the txbuffer has been sent to the
// hardware, and the shift register has send out all of the bits. (Hardware Serial);
// I assume (ASS U ME) that SoftwareSerial has the same coding, I have never used
// SoftwareSerial, so I could be wrong. Hardware Serial, works as I have explained.
digitalWrite(TX_ENABLE_PIN,HIGH); // receive mode
Chuck.
Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.
thanks mrbbp can i use this code if i communicate two arduinos through their rx tx pins
and on one i wirte sending code and on other i write receiving code.
if there will be some changes please do tell me what will be they??
samreen_kiran, there is little use to use the Modbus protocol if you only want two Arduinos to communicate with each other.
If you only wish two Arduinos to communicate at short distance, then just use their TTL signals.
If on the other hand you need long distance, say greater than a few metres, then read and learn about Nick Gammon's article on using RS-485 to connect two Arduinos, mentioned in the very first post of this thread.
Also, look in the playground for other examples of methods that might suit your needs better.
Paul
thanks rockwallaby, i read that article if have any confusion after i will ask again for help 
Hello, a company just gave me a project to control their industrial controller
it talk through RS485 too.
So i used the same rs485 to TTL converter and change the code to send the correct address according to their datasheet controller.
the industrial controller was thermostat DIXELL XR77CH
i added buttons to send different address
Your Help is very important
send_serial_using_push_button_v2.ino (2.28 KB)
PV500-67 dixell XR10 cx register.pdf (239 KB)
Hello,
here I meet dificulter to control a multi-way valve, I arduino mega2560, a shield rs485 and the valve, I realized a twisted cable and put a resistant of 100 ohm on each side, the cable is 50 cm.
Example:
Transmit Message: 0B 0F 02 10 00 01 01 01 AF 09
this launches an aumatic cycle.
a light on the valve must flash during communication exchanges, nothing happens.
the serial monitor displays the message ...
could you help me
#include <SoftwareSerial.h>
// assemble message
byte msg [] = {
0x0B,
0x0F,
0x02,
0x11,
0x00,
0x01,
0x01,
0x01,
0x92,
0xC9,
};
#define TX_ENABLE_PIN 2 // define the EIA-485 transmit driver pin ( RE + DE pin's modules)
SoftwareSerial rs485(0, 1); // SoftwareSerial rs485(RO, DI); pins name on the module
void setup(){
pinMode(TX_ENABLE_PIN, OUTPUT); // driver output enable
rs485.begin (9600); // vitesse com
Serial.begin(9600);
}
void loop(){
digitalWrite (TX_ENABLE_PIN, HIGH); // enable transmit driver
// msg[3] = random(0,128); // generate a random display
for (int i = 0; i < 10; i++) {
Serial.print(msg[i], HEX); // console print the data
rs485.write(msg[i]); // flip display print
if (i < 9){
Serial.print(", "); // print a comma between data for console only :art:
}
}
Serial.println();
digitalWrite(TX_ENABLE_PIN, LOW); // disable transmit driver
delay(500);
}
AMPV_Modbus_Manual_en_2.1.pdf (580 KB)