smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

RS-485 half duplex operation with MAX485 and compatible transceivers #30

Closed GITChr closed 4 years ago

GITChr commented 6 years ago

Hi! Great that someone wrote this library. A question:

In the examples, RS-485 is sometimes mentioned in the code (advanced master), while at the top of the file, it is mentioned this works only with RS232 and USB.

For operation with RS-485, the transceiver needs to be switched back and forth between receive and transmit modes. Is this implemented in the library and how do I use this feature?

Thanks Christoph

adkolimp commented 6 years ago

I am not too sure if you have already found a solution. If I am right you may use the following

Modbus(uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin); If you initialise with this method then the toggling is taken care. u8txenpin is probably what you are looking for. On the RS-485 you should short RE, DE pins. Let me know if you have solved it in any other way.

jjassar commented 6 years ago

@GITChr have you solved the issue with solution recommended by @adkolimp . Please update

smarmengol commented 6 years ago

Sorry for the delay in my answer. The original library handled the RS-485 transceiver through a digital output:

xzsfd2457 commented 4 years ago

I am getting response from devices by using below code.......

define DE PB9

void setup() { disableDebugPorts(); Serial.begin(9600); Serial1.begin(9600); pinMode(DE,OUTPUT); //digitalWrite(DE,HIGH);

} byte test_data[] ={0x01,0x04,0x00,0x10,0x00,0x01,0x30,0x0F} ;

void loop() { Serial1.begin(9600); digitalWrite(DE,HIGH); delay(2000); Serial1.write(test_data,8); delay(10); digitalWrite(DE,LOW); Serial1.end();

Serial1.begin(9600); while(1){ if (Serial1.available()) { Serial.println(Serial1.read(),HEX); } } Serial.flush(); Serial1.flush(); delay(1000); // put your main code here, to run repeatedly:

}

smarmengol commented 4 years ago

I am getting response from devices by using below code.......

define DE PB9

void setup() { disableDebugPorts(); Serial.begin(9600); Serial1.begin(9600); pinMode(DE,OUTPUT); //digitalWrite(DE,HIGH);

} byte test_data[] ={0x01,0x04,0x00,0x10,0x00,0x01,0x30,0x0F} ;

void loop() { Serial1.begin(9600); digitalWrite(DE,HIGH); delay(2000); Serial1.write(test_data,8); delay(10); digitalWrite(DE,LOW); Serial1.end();

Serial1.begin(9600); while(1){ if (Serial1.available()) { Serial.println(Serial1.read(),HEX); } } Serial.flush(); Serial1.flush(); delay(1000); // put your main code here, to run repeatedly:

}

Hi, There is something that I'm missing. Maybe I'm getting too old. What is the relation between this and Modbus? Your code is for a serial transmission. Nothing else! Regards,

xzsfd2457 commented 4 years ago

I am getting response from devices by using below code.......

define DE PB9

void setup() { disableDebugPorts(); Serial.begin(9600); Serial1.begin(9600); pinMode(DE,OUTPUT); //digitalWrite(DE,HIGH); } byte test_data[] ={0x01,0x04,0x00,0x10,0x00,0x01,0x30,0x0F} ; void loop() { Serial1.begin(9600); digitalWrite(DE,HIGH); delay(2000); //Keep delay is important Serial1.write(test_data,8); delay(10); digitalWrite(DE,LOW); Serial1.end(); Serial1.begin(9600); while(1){ if (Serial1.available()) { Serial.println(Serial1.read(),HEX); } } Serial.flush(); Serial1.flush(); delay(1000); // put your main code here, to run repeatedly: }

Hi, There is something that I'm missing. Maybe I'm getting too old. What is the relation between this and Modbus? Your code is for a serial transmission. Nothing else! Regards,

I am sending serial data using MAX485 converter...