The RS485 master-slave communication library on Nick Gammon's page http://www.gammon.com.au/Arduino/RS485_protocol.zip is working for me OK, but on the same hardware wiring is not working for the non-blocking library http://www.gammon.com.au/Arduino/RS485_non_blocking.zip.
I can not find information about the connection of MAX485 on Arduino for non-block version. Is MAX485/RS485 from HW serial (ie Rx=0 and Tx=1)?
If so, how can a slave on the same line at the same time receive from master the message "hello world" and print it to the serial monitor? Thank you for the explanation.
When I added the SoftwareSerial library into Nick's example for non-blocking, so it works, but is it still a non-blocking?
//Master:
#include <RS485_non_blocking.h>
#include <SoftwareSerial.h>
const byte ENABLE_PIN = 4;
SoftwareSerial mySerial(2,3); //RX = 2 TX = 3
size_t fWrite (const byte what) {
return mySerial.write (what);
}
RS485 myChannel (NULL, NULL, fWrite, 0);
void setup () {
Serial.begin (9600);
mySerial.begin (28800);
myChannel.begin ();
pinMode (ENABLE_PIN, OUTPUT); // driver output enable
} // end of setup
const byte msg [] = "Hello world";
void loop () {
digitalWrite (ENABLE_PIN, HIGH); // enable sending
myChannel.sendMsg (msg, sizeof (msg));
digitalWrite (ENABLE_PIN, LOW); // disable sending
delay (1000);
} // end of loop
//Slave:
#include <RS485_non_blocking.h>
#include <SoftwareSerial.h>
const byte ENABLE_PIN = 4;
SoftwareSerial mySerial(2,3); //RX = 2 TX = 3
int fAvailable () {
return mySerial.available ();
}
int fRead() {
return mySerial.read ();
}
RS485 myChannel (fRead, fAvailable, NULL, 20);
void setup() {
Serial.begin(9600);
mySerial.begin(28800);
myChannel.begin();
pinMode (ENABLE_PIN, OUTPUT); // driver output enable
} // end of setup
void loop() {
if (myChannel.update()) {
Serial.write (myChannel.getData(), myChannel.getLength());
Serial.println();
}
} // end of loop
Regards, Vava (Sorry for my English... :-)