RS485 2 CLICK Test in Arduino

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
mkraljsvn
Posts: 1
Joined: 19 Jan 2020 14:22

RS485 2 CLICK Test in Arduino

#1 Post by mkraljsvn » 19 Jan 2020 14:54

Hey everybody,

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

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: RS485 2 CLICK Test in Arduino

#2 Post by stefan.filipovic » 20 Jan 2020 16:31

Hi Marko,

Could you try with a 1 ms delay added after the Serial2_write code line?

Code: Select all

Serial2.write(char(character));
delay(1);
Kind regards,
Stefan Filipović

Post Reply

Return to “User Projects”