November 15, 2024, 05:36:18 AM

MOD-RS485 data receive

Started by cosmin91ro, July 13, 2016, 02:08:48 PM

Previous topic - Next topic

cosmin91ro

Hello,

I need help, please. I have Olimexino-328 board (Atmega328P chip) and the module MOD-RS485 connected via UEXT.

I am trying to transmit data between the board and a PC via RS485 interface. I was successful in sending data from the boar to PC after setting DE and /RE pins to HIGH but by no means am I able to receive data from the RS485. Of course I set up DE and /RE pins to LOW before start checking for incoming data, but with no success.

I also tried to transfer data via RS485 between two identical setups( Olimexino 328 + MOD-RS485 ) but with no success

This is the code on sender side:
#define RE 10
#define DE 13
#define LED2 9   // For debugging

void setup ()
{
  Serial.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  pinMode(LED2, OUTPUT);

  digitalWrite(RE, HIGH);
  digitalWrite(DE, HIGH);
}

void loop ()
{
    Serial.write(0x41);
    delay(2000);
}



And this is the code on receiver side:
#define RE 10
#define DE 13
#define LED2 9

byte recv;

void setup() {
  Serial.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  pinMode(LED2, OUTPUT);

  digitalWrite(RE, LOW);
  digitalWrite(DE, LOW);
}

void loop() {
  if (Serial.available())
  {
    digitalWrite(LED2, HIGH);
    delay(500);
    while ( Serial.available() )
    {
      recv = Serial.read();
    }
  }
  digitalWrite(LED2, LOW);
}



If I connect directly the UART interfaces between the two boards, I can see data coming ( led is blinking ).

Please provide me with some clues where I might be wrong. Thank you!

Stanimir5F

#1
Hello, cosmin91ro!

The thing I noticed in your code is that you define RE as D10 while it should be D7. Unless you have moved the jumper's position by default it is shorted to D7.

I managed to make a bridge between two boards.
I connected two Olimexino-328 boards with MOD-RS485 modules via 4 jumper cables and UEXT cables like this.
Programmed the boards with this code (one with Enable (TRANSMIT); and one with Enable (RECEIVE); ):
#define DE  13
#define _RE  7

#define TRANSMIT  1
#define RECEIVE   0

void Enable (int Mode)
{
  digitalWrite (DE, Mode);
  digitalWrite (_RE, Mode);
}

void setup()
{
  Serial.begin (9600);

  pinMode (DE, OUTPUT);
  pinMode (_RE, OUTPUT);

  Enable (TRANSMIT);
  //Enable (RECEIVE);
}

void loop ()
{
  while (Serial.available() > 0)
    Serial.print((char)Serial.read());
}


and on the terminal when I send characters on the one with enabled transmit I receive them on the other terminal. Here is the result.

So can you try again with changed value for RE to 7 (except you moved jumper's position) and tell me whether it works or not.

Stan, Olimex
May the Source be with You!

cosmin91ro

Quote from: Stanimir5F on July 19, 2016, 02:02:21 PM
Hello, cosmin91ro!

The thing I noticed in your code is that you define RE as D10 while it should be D7. Unless you have moved the jumper's position by default it is shorted to D7.

I managed to make a bridge between two boards.
I connected two Olimexino-328 boards with MOD-RS485 modules via 4 jumper cables and UEXT cables like this.
Programmed the boards with this code (one with Enable (TRANSMIT); and one with Enable (RECEIVE);):
#define DE  13
#define _RE  7

#define TRANSMIT  1
#define RECEIVE   0

void Enable (int Mode)
{
  digitalWrite (DE, Mode);
  digitalWrite (_RE, Mode);
}

void setup()
{
  Serial.begin (9600);

  pinMode (DE, OUTPUT);
  pinMode (_RE, OUTPUT);

  Enable (TRANSMIT);
  //Enable (RECEIVE);
}

void loop ()
{
  while (Serial.available() > 0)
    Serial.print((char)Serial.read());
}


and on the terminal when I send characters on the one with enabled transmit I receive them on the other terminal. Here is the result.

So can you try again with changed value for RE to 7 (except you moved jumper's position) and tell me whether it works or not.

Stan, Olimex

Thank you, your solution worked. Indeed, I was using the wrong pin.
Thank you for your time.