Go Down

Topic: MAX485 communications (Read 763 times) previous topic - next topic

cptdondo

I have two Arduino Pro Minis that each have a MAX485 chip. Right now I have them set up on a single breadboard with about 3" between the MAX485 chips, so I am not using terminators.

I am seeing a lot of dropped characters, similar to what happens if my baud rate is wrong.

Code: [Select]

ÿÿHÿHÿHÿ
HÿHÿ
HÿHÿ


I am using AltSoftSerial, which could also be the problem.  Pin 13 is wired to the RE+DE pins.  If I take out the delay(1) I get nothing, so it looks like there's some bouncing or something going on.  It's also possible that I am not handling half-duplex correctly.  If I take out the MAX485 chips and just cross over pins 8 and 9 between the arduinos the setup works perfectely, so it's something in how I handle the MAX485 chips.

My breadboard is wired similar to this:

http://aquaticus.info/rs485

Here's my quick and dirty code (the output on the serial console is above).  The code is running on each arduino. 

Code: [Select]

#include <AltSoftSerial.h>

// AltSoftSerial always uses these pins:
//
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Teensy 2.0         9        10       (none)
// Teensy++ 2.0      25         4       26, 27
// Arduino Uno        9         8         10
// Arduino Mega      46        48       44, 45
// Wiring-S           5         6          4
// Sanguino          13        14         12

AltSoftSerial altSerial;

void setup() {
  Serial.begin(9600);
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
  digitalWrite(13,HIGH);
  delay(1);
  altSerial.println("Hello World");
  delay(1);
  digitalWrite(13,LOW);
}

void loop() {
  char c;
  c=0;
  while (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
    c=0xff;
  }
  if(c>0) {
    digitalWrite(13,HIGH);
    delay(1);
    altSerial.println("a");
    delay(1);
    digitalWrite(13,LOW);
  }
}

cptdondo

I think I just figured it out....   Half-duplex - I need a master and a slave, not two peers sending asynchronously.  I'll re-code it tomorrow.

CrossRoads

AltSoftSerial - yes, faking the UART in software, so it can't send & receive at the same time most likely.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy