I bought two RS485 2 click boards (3.3V version) and want to do a simple test of connecting them together. I am new to 485 but not to programming.
I connected A&B with twisted pair and GND with additional wire.
CLICK1 CLICK2
A <--> A
B <--> B
GND <--> GND
My test is with two Arduino DUE boards do I have 4 UARTS available. I use "serial" for console and "Serial2" for 485.
I connected:
CLICKn Arduino DUE
3V3 <--> 3.3V
GND <--> GND
RX <--> RX2
TX <--> TX2
DE <--> PIN33
RE <--> PIN35
Both MASTER and SLAVE are connected the same and the test code for both is the same. For test is just reads user input from Serial and echoes it on Serial2 and if something received on Serial2 it echoes back to Serial.
The code does not seem to work and I don't know why. Tested with osciloscope the TX, RX, DE and RE and when a char is sent the state of the line DE&RE changes and there are some bits on TX line, however nothing changes on A or B wire ...
I must be missing something obvious here. I use the same source for master and slave.
Thank you for all your help, source code is attached here:
-----
Code: Select all
// Mikroelektronika RS485 2 click test
const byte RS485_DE_PIN = 33;
const byte RS485_RE_PIN = 35;
const byte RECEIVE_ENABLE = LOW;
const byte RECEIVE_DISABLE = HIGH;
const byte TRANSMIT_ENABLE = HIGH;
const byte TRANSMIT_DISABLE = LOW;
void setup() {
Serial.begin (115200);
Serial2.begin (28800);
pinMode(RS485_DE_PIN, OUTPUT);
pinMode(RS485_RE_PIN, OUTPUT);
digitalWrite (RS485_DE_PIN, TRANSMIT_DISABLE);
digitalWrite (RS485_RE_PIN, RECEIVE_ENABLE);
}
void loop() {
if (Serial.available()) {
byte character = Serial.read();
Serial.print("Sent[");
Serial.print(char(character));
Serial.println("].");
digitalWrite (RS485_RE_PIN, RECEIVE_DISABLE);
digitalWrite (RS485_DE_PIN, TRANSMIT_ENABLE);
Serial2.write(char(character));
digitalWrite (RS485_DE_PIN, TRANSMIT_DISABLE);
digitalWrite (RS485_RE_PIN, RECEIVE_ENABLE);
}
if (Serial2.available()) {
byte character = Serial2.read();
Serial.print("Received[");
Serial.print(char(character));
Serial.println("].");
}
} // end of loop
Best,
Marko