I want to interface MAX485 with arduino for communication with energy meter using RS485 protocol.
Energy meter datasheet can be found on this link-
http://www.powertechinternational.in/catalouges/SCHNEIDER-CONZERV-EM-6400.pdf
I am using RS485 to RS232 module by LC electronics.
I have tested my module and it works properly. I have tested it using loop back test as per instructions given on link-
https://arduino-info.wikispaces.com/SoftwareSerialRS485Example
I must send "01030F3C00048711" (HEX) sequence to read 4 holding registers.
Hardware connections:
A and B of module are connected to A and B of energy meter. DI is connected to TX and RO to RX of Serial1 port on arduino mega. Control pins DE and RE' are shorted and connected to pin 3 of arduino.
Code:
void setup() {
pinMode(13,OUTPUT);
pinMode(3,OUTPUT);
digitalWrite(3,LOW);
digitalWrite(13,LOW);
Serial.begin(9600);
Serial1.begin(9600);
}
uint8_t val[8]={01,03,15,60,00,04,135,17}; //sequence to be sent
int buf=5;
void loop() {
digitalWrite(3,HIGH); //transmit enable
for(int i=0;i<8;i++) //Send sequence
{
Serial.print(val[i],HEX);
}
delay(10);
digitalWrite(3,LOW); //receive enable
buf=Serial1.read();
Serial.println(buf,HEX);
if(buf!=5)
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}
// delay(1000);
}
output on serial monitor: 0 (multiple times with some delay in between and LED at pin 13 was blinking)
Ideally I should get data stored in 4 holding registers starting from address 3901