Pages: [1]   Go Down
Author Topic: MAX485 communications  (Read 553 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
ÿÿ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:
#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);
  }
}
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

AltSoftSerial - yes, faking the UART in software, so it can't send & receive at the same time most likely.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: